pitchamdf
Prev | Orchestra Opcodes and Operators | Next

## pitchamdf

pitchamdf — Follows the pitch of a signal based on the AMDF method.

## Description

Follows the pitch of a signal based on the AMDF method (Average Magnitude Difference Function). Outputs pitch and amplitude tracking signals. The method is quite fast and should run in realtime. This technique usually works best for monophonic signals.

## Syntax

    kcps, krms pitchamdf asig, imincps, imaxcps [, icps] [, imedi] \
          [, idowns] [, iexcps] [, irmsmedi]

## Initialization

imincps -- estimated minimum frequency (expressed in Hz) present in the signal

imaxcps -- estimated maximum frequency present in the signal

icps (optional, default=0) -- estimated initial frequency of the signal. If 0, icps = (imincps+imaxcps) / 2. The default is 0.

imedi (optional, default=1) -- size of median filter applied to the output kcps. The size of the filter will be imedi*2+1. If 0, no median filtering will be applied. The default is 1.

idowns (optional, default=1) -- downsampling factor for asig. Must be an integer. A factor of idowns > 1 results in faster performance, but may result in worse pitch detection. Useful range is 1 - 4. The default is 1.

iexcps (optional, default=0) -- how frequently pitch analysis is executed, expressed in Hz. If 0, iexcps is set to imincps. This is usually reasonable, but experimentation with other values may lead to better results. Default is 0.

irmsmedi (optional, default=0) -- size of median filter applied to the output krms. The size of the filter will be irmsmedi*2+1. If 0, no median filtering will be applied. The default is 0.

## Performance

kcps -- pitch tracking output

krms -- amplitude tracking output

pitchamdf usually works best for monophonic signals, and is quite reliable if appropriate initial values are chosen. Setting imincps and imaxcps as narrow as possible to the range of the signal's pitch, results in better detection and performance.

Because this process can only detect pitch after an initial delay, setting icps close to the signal's real initial pitch prevents spurious data at the beginning.

The median filter prevents kcps from jumping. Experiment to determine the optimum value for imedi for a given signal.

Other initial values can usually be left at the default settings. Lowpass filtering of asig before passing it to pitchamdf, can improve performance, especially with complex waveforms.

## Examples

Here is an example of the pitchamdf opcode. It uses the file pitchamdf.csd.

Example 569. Example of the pitchamdf 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 pitchamdf.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

    asig soundin p4
    asig tone asig, 1000		;lowpass-filter
    kcps, krms pitchamdf asig, 100, 500, 200
    asig poscil krms, 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>

## Credits

Author: Peter Neubäcker
Munich, Germany
August 1999

New in Csound version 3.59

Prev | Up | Next
pitch | Home | planet