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 345. 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
; Audio out   Audio in    No display
-odac           -iadc     -d     ;;;RT audio I/O
</CsOptions>
<CsInstruments>
sr= 44100
ksmps = 16
nchnls= 1

;Example by Victor Lazzarini 2007

instr 1
  a1 inch 1              ; take an input signal
  kf,ka ptrack a1, 512   ; pitch track with winsize=1024
  kcps port kf, 0.01     ; smooth freq
  kamp port ka, 0.01     ; smooth amp

  ; drive an oscillator
  aout oscili ampdb(kamp)*0dbfs, kcps, 1

  out  aout
endin

</CsInstruments>
<CsScore>
i1 0 3600
e
</CsScore>
</CsoundSynthesizer>


Credits

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

New in Csound version 5.05