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. Play pitch.csd
Example 763. 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 ; by Menno Knevel 2022 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 Sfile = p4 asig soundin Sfile koct, kamp pitch asig, iupdte, ilo, ihi, idbthresh, ifrqs, iconf, istrt kamp = kamp*.00004 ;lower volume kcps = cpsoct(koct) asig poscil kamp, kcps, 1 ;re-synthesize with sawtooth printf "now %s is used...\n\n", 1, Sfile 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 4 "singFemale.aif" i 2 10 4 "singFemale.aif" i 1 15 2 "drumsMlp.wav" i 2 17 2 "drumsMlp.wav" e </CsScore> </CsoundSynthesizer>