ptrack

ptrack — Tracks the pitch of a signal.

Description

ptrack takes an input signal, splits it into ihopsize blocks and using a STFT method, extracts an estimated pitch for its fundamental frequency as well as estimating the total amplitude of the signal in dB, relative to full-scale (0dB). The method implies an analysis window size of 2*ihopsize samples (overlaping by 1/2 window), which has to be a power-of-two, between 128 and 8192 (hopsizes between 64 and 4096). Smaller windows will give better time precision, but worse frequency accuracy (esp. in low fundamentals).This opcode is based on an original algorithm by M. Puckette.

Syntax

kcps, kamp ptrack asig, ihopsize[,ipeaks]

Initialization

ihopsize -- size of the analysis 'hop', in samples, required to be power-of-two (min 64, max 4096). This is the period between measurements.

ipeaks, ihi -- number of spectral peaks to use in the analysis, defaults to 20 (optional)

Performance

kcps -- estimated pitch in Hz.

kamp -- estimated amplitude in dB relative to full-scale (0dB) (ie. always <= 0).

ptrack analyzes the input signal, asig, to give a pitch/amplitude pair of outputs, for the fundamental of a monophonic signal. The output is updated every sr/ihopsize seconds.

Examples

Here is an example of the ptrack opcode. This example uses the files ptrack.csd.

Example 663. Example of the ptrack 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 realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o ptrack.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100 
ksmps = 32 
0dbfs  = 1 
nchnls = 2

instr 1

ihop  = p4
aout  diskin2 "fox.wav",1, 0, 1
kf,ka ptrack aout, ihop	; pitch track with different hopsizes
kcps  port kf, 0.01	; smooth freq
kamp  port ka, 0.01	; smooth amp
; drive an oscillator
asig  poscil ampdb(kamp)*0dbfs, kcps, 1
      outs  asig, asig

endin
</CsInstruments>
<CsScore>
; simple sine wave
f 1 0 4096 10 1

i 1 0  5 128
i 1 6  5 512
i 1 12 5 1024
e
</CsScore>
</CsoundSynthesizer>


Credits

Author: Victor Lazzarini
NUI, Maynooth.
Maynooth, Ireland
March, 2007

New in Csound version 5.05