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 and mary.wav.

Example 365. 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
    ; Audio out   Audio in    No messages
    -odac           -iadc     -d     ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o pitchamdf.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; synth waveform
    giwave ftgen 2, 0, 1024, 10, 1, 1, 1, 1

    ; Instrument #1 - play an audio file with no effects.
    instr 1
      ; get input signal with original freq.
      asig soundin "mary.wav"

      out asig
    endin

    ; Instrument #2 - play the synth waveform using the
    ; same pitch and amplitude as the audio file.
    instr 2
      ; get input signal with original freq.
      asig soundin "mary.wav"

      ; lowpass-filter
      asig tone asig, 1000
      ; extract pitch and envelope
      kcps, krms pitchamdf asig, 150, 500, 200
      ; "re-synthesize" with the synth waveform, giwave.
      asig1 oscil krms, kcps, giwave

      out asig1
    endin

    </CsInstruments>
    <CsScore>

    ; Play Instrument #1, the audio file, for three seconds.
    i 1 0 3
    ; Play Instrument #2, the "re-synthesized" waveform, for three seconds.
    i 2 3 3
    e

    </CsScore>
    </CsoundSynthesizer>

## Credits

Author: Peter Neubäcker
Munich, Germany
August 1999

New in Csound version 3.59

Prev | Up | Next
pitch | Home | planet