pitch — Tracks the pitch of a signal.
Using the same techniques as spectrum and specptrk, pitch tracks the pitch of the signal in octave point decimal form, and amplitude in dB.
koct, kamp pitch asig, iupdte, ilo, ihi, idbthresh [, ifrqs] [, iconf] \
[, istrt] [, iocts] [, iq] [, inptls] [, irolloff] [, iskip]
iupdte -- length of period, in seconds, that outputs are updated
ilo, ihi -- range in which pitch is detected, expressed in octave point decimal
idbthresh -- amplitude, expressed in decibels, necessary for the pitch to be detected. Once started it continues until it is 6 dB down.
ifrqs (optional) -- number of divisons of an octave. Default is 12 and is limited to 120.
iconf (optional) -- the number of conformations needed for an octave jump. Default is 10.
istrt (optional) -- starting pitch for tracker. Default value is (ilo + ihi)/2.
iocts (optional) -- number of octave decimations in spectrum. Default is 6.
iq (optional) -- Q of analysis filters. Default is 10.
inptls (optional) -- number of harmonics, used in matching. Computation time increases with the number of harmonics. Default is 4.
irolloff (optional) -- amplitude rolloff for the set of filters expressed as fraction per octave. Values must be positive. Default is 0.6.
iskip (optional) -- if non-zero, skips initialization. Default is 0.
koct -- The pitch output, given in the octave point decimal format.
kamp -- The amplitude output.
pitch analyzes the input signal, asig, to give a pitch/amplitude pair of outputs, for the strongest frequency in the signal. The value is updated every iupdte seconds.
The number of partials and rolloff fraction can effect the pitch tracking, so some experimentation may be necessary. Suggested values are 4 or 5 harmonics, with rolloff 0.6, up to 10 or 12 harmonics with rolloff 0.75 for complex timbres, with a weak fundamental.
Here is an example of the pitch opcode. It uses the file pitch.csd.
Example 631. Example of the pitch opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac ;;;realtime audio out ;-iadc ;;;uncomment -iadc if real audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o pitch.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 instr 1 ;clean audio asig soundin p4 outs asig, asig endin instr 2 ;use pitch iupdte = 0.001 ;high definition ilo = 6 ihi = 10 idbthresh = 10 ifrqs = 12 iconf = 10 istrt = 8 asig soundin p4 koct, kamp pitch asig, iupdte, ilo, ihi, idbthresh, ifrqs, iconf, istrt kamp = kamp*.00005 ;lower volume kcps = cpsoct(koct) asig poscil kamp, kcps, 1 ;re-synthesize with sawtooth outs asig, asig endin </CsInstruments> <CsScore> f1 0 16384 10 1 0.5 0.3 0.25 0.2 0.167 0.14 0.125 .111 ;sawtooth i 1 0 3 "fox.wav" i 2 3 3 "fox.wav" i 1 6 3 "mary.wav" i 2 9 3 "mary.wav" i 1 12 3 "beats.wav" i 2 15 3 "beats.wav" e </CsScore> </CsoundSynthesizer>