Skip to content

pitchac

Estimate pitch by correlating successive windows of an audio signal.

Syntax

kpitch = pitchac(asig, kfmin, kfmax, iflow)
kpitch pitchac asig, kfmin, kfmax, iflow

Initialization

iflow -- lowest frequency in Hz used to size the sample and correlation buffers. It must be positive and no greater than the sample rate, and the resulting buffer length must fit in memory. Set it at or below the smallest kfmin you will use.

Performance

kpitch -- estimated frequency in Hz. It starts at zero and holds the last accepted estimate until another estimate is accepted.

asig -- audio signal to analyze.

kfmin -- frequency in Hz used to choose the analysis window length, approximately sr / kfmin samples. It must be positive and no greater than the sample rate. The requested length is limited to the capacity set by iflow. A change takes effect when the current window finishes. This parameter controls the window length; it is not a separate lower-bound check on the reported pitch.

kfmax -- highest accepted pitch estimate in Hz. An estimate above this value leaves the previous output unchanged.

The opcode correlates the previous sample window with a circularly shifted current window. A nonzero lag gives an estimate of sr / lag. It updates the stored estimate after each completed window, so analysis introduces a delay. Silence or a window without an accepted nonzero lag leaves the previous estimate unchanged.

Examples

Here is an example of the pitchac opcode. It uses the file pitchac.csd. It prints the estimate for a sine wave:

<CsoundSynthesizer>
<CsOptions>
-n -d -m0
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 1
0dbfs = 1

instr 1
  aInput oscili 0.2, 200
  kPitch pitchac aInput, 100, 500, 50
  printks "Estimated pitch: %7.2f Hz\n", 0.1, kPitch
endin
</CsInstruments>
<CsScore>
i 1 0 1
e
</CsScore>
</CsoundSynthesizer>

See also

pitchamdf, ptrack, Sensing and Control