pvspitch
Prev | Orchestra Opcodes and Operators | Next

## pvspitch

pvspitch — Track the pitch and amplitude of a PVS signal.

## Description

Track the pitch and amplitude of a PVS signal as k-rate variables.

## Syntax

    kfr, kamp pvspitch fsig, kthresh

## Performance

kamp -- Amplitude of fundamental frequency

kfr -- Fundamental frequency

fsig -- an input pv stream

kthresh -- analysis threshold (between 0 and 1). Higher values will eliminate low-amplitude components from the analysis.

## Performance

The pitch detection algorithm implemented by pvspitch is based upon J. F. Schouten's hypothesis of the neural processes of the brain used to determine the pitch of a sound after the frequency analysis of the basilar membrane. Except for some further considerations, pvspitch essentially seeks out the highest common factor of an incoming sound's spectral peaks to find the pitch that may be attributed to it.

In general, input sounds that exhibit pitch will also exhibit peaks in their spectrum according to where their harmonics lie. There are some the exceptions, however. Some sounds whose spectral representation is continuous can impart a sensation of pitch. Such sounds are explained by the centroid or center of gravity of the spectrum and are beyond the scope of the method of pitch detection implemented by pvspitch (Using opcodes like pvscent might be more appriopriate in these cases).

pvspitch is able (using a previous analysis fsig generated by pvsanal) to locate the spectral peaks of a signal. The threshold parameter (kthresh) is of utmost importance, as adjusting it can introduce weak yet significant harmonics into the calculation of the fundamental. However, bringing kthresh too low would allow harmonically unrelated partials into the analysis algorithm and this will compromise the method's accuracy. These initial steps emulate the response of the basilar membrane by identifying physical characteristics of the input sound. The choice of kthresh depends on the actual level of the input signal, since its range (from 0 to 1) spans the whole dynamic range of an analysis bin (from -inf to 0dBFS).

It is important to remember that the input to the pvspitch opcode is assumed to be characterised by strong partials within its spectrum. If this is not the case, the results outputted by the opcode may not bear any relation to the pitch of the input signal. If a spectral frame with many unrelated partials was analysed, the greatest common factor of these frequency values that allows for adjacent “harmonics” would be chosen. Thus, noisy frames can be characterised by low frequency outputs of pvspitch. This fact allows for a primitive type of instrumental transient detection, as the attack portion of some instrumental tones contain inharmonic components. Should the lowest frequency of the analysed melody be known, then all frequencies detected below this threshold are inaccurate readings, due to the presence of unrelated partials.

In order to facilitate efficient testing of the pvspitch algorithm, an amplitude value proportional to the one in the observed in the signal frame is also outputted (kamp). The results of pvspitch can then be employed to drive an oscillator whose pitch can be audibly compared with that of the original signal (In the example below, an oscillator generates a signal which appears a fifth above the detected pitch).

## Examples

Here is an example of the pvspitch opcode. It uses the file pvspitch.csd. This example uses realtime audio input but can be used for audiofile input as well.

Example 819. Example of the pvspitch 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
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o pvspitch.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 128
    nchnls = 1

    giwave ftgen 0, 0, 4096, 10, 1, 0.5, 0.333, 0.25, 0.2, 0.1666

    instr 1

    ifftsize = 1024
    iwtype = 1    /* cleaner with hanning window */

    a1 inch 1 ;Realtime audio input
    ;a1   soundin "input.wav" ;Use this line for file input

    fsig pvsanal   a1, ifftsize, ifftsize/4, ifftsize, iwtype
    kfr, kamp pvspitch   fsig, 0.01

    adm  oscil     kamp, kfr * 1.5, giwave  ;Generate note a fifth above detected pitch

           out    adm
    endin

    </CsInstruments>
    <CsScore>

    i 1 0 30

    e

    </CsScore>
    </CsoundSynthesizer>

## See Also

pvsanal, pvsynth, pvsadsyn, pvscent

## Credits

Author: Alan OCinneide
August 2005, added by Victor Lazzarini, August 2006
Part of the text has been adapted from the Csound Journal winter 2006 issue's article "Introducing PVSPITCH: A pitch tracking opcode for Csound" by Alan OCinneide. The article is available at: www.csoundjournal.com/2006winter/pvspitch.html

Prev | Up | Next
pvsosc | Home | pvstanal