| 1 | |
| 2 | <refentry id="pvspitch"> |
| 3 | <indexterm id="Indexpvspitch"><primary>pvspitch</primary></indexterm> |
| 4 | |
| 5 | <refentryinfo><title>Spectral Processing:Streaming</title></refentryinfo> |
| 6 | <refmeta> |
| 7 | <refentrytitle>pvspitch</refentrytitle> |
| 8 | </refmeta> |
| 9 | |
| 10 | <refnamediv> |
| 11 | <refname>pvspitch</refname> |
| 12 | <refpurpose> |
| 13 | Track the pitch and amplitude of a PVS signal. |
| 14 | </refpurpose> |
| 15 | </refnamediv> |
| 16 | |
| 17 | <refsect1> |
| 18 | <title>Description</title> |
| 19 | <para> |
| 20 | Track the pitch and amplitude of a PVS signal as k-rate variables. |
| 21 | </para> |
| 22 | </refsect1> |
| 23 | |
| 24 | <refsect1> |
| 25 | <title>Syntax</title> |
| 26 | <synopsis>kfr, kamp <command>pvspitch</command> fsig, kthresh</synopsis> |
| 27 | </refsect1> |
| 28 | |
| 29 | <refsect1> |
| 30 | <title>Performance</title> |
| 31 | <para> |
| 32 | <emphasis>kamp</emphasis> -- Amplitude of fundamental frequency |
| 33 | </para> |
| 34 | <para> |
| 35 | <emphasis>kfr</emphasis> -- Fundamental frequency |
| 36 | </para> |
| 37 | <para> |
| 38 | <emphasis>fsig</emphasis> -- an input pv stream |
| 39 | </para> |
| 40 | <para> |
| 41 | <emphasis>kthresh</emphasis> -- analysis threshold (between 0 and 1). Higher values will eliminate low-amplitude components from the analysis. |
| 42 | </para> |
| 43 | </refsect1> |
| 44 | |
| 45 | <refsect1> |
| 46 | <title>Performance</title> |
| 47 | <para> |
| 48 | The pitch detection algorithm implemented by <emphasis>pvspitch</emphasis> 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, <emphasis>pvspitch</emphasis> essentially seeks out the highest common factor of an incoming sound's spectral peaks to find the pitch that may be attributed to it. |
| 49 | </para> |
| 50 | <para> |
| 51 | 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 <emphasis>pvspitch</emphasis> (Using opcodes like <link linkend="pvscent"><citetitle>pvscent</citetitle></link> might be more appriopriate in these cases). |
| 52 | </para> |
| 53 | <para> |
| 54 | <emphasis>pvspitch</emphasis> is able (using a previous analysis <emphasis>fsig</emphasis> generated by <link linkend="pvsanal"><citetitle>pvsanal</citetitle></link>) to locate the spectral peaks of a signal. The threshold parameter (<emphasis>kthresh</emphasis>) is of utmost importance, as adjusting it can introduce weak yet significant harmonics into the calculation of the fundamental. However, bringing <emphasis>kthresh</emphasis> 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 <emphasis>kthresh</emphasis> 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). |
| 55 | </para> |
| 56 | <para> |
| 57 | It is important to remember that the input to the <emphasis>pvspitch</emphasis> 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 <emphasis>pvspitch</emphasis>. 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. |
| 58 | </para> |
| 59 | <para> |
| 60 | In order to facilitate efficient testing of the <emphasis>pvspitch</emphasis> algorithm, an amplitude value proportional to the one in the observed in the signal frame is also outputted (<emphasis>kamp</emphasis>). The results of <emphasis>pvspitch</emphasis> 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). |
| 61 | </para> |
| 62 | </refsect1> |
| 63 | |
| 64 | <refsect1> |
| 65 | <title>Examples</title> |
| 66 | <para> |
| 67 | Here is an example of the pvspitch opcode. It uses the file <ulink url="examples/pvspitch.csd"><citetitle>pvspitch.csd</citetitle></ulink>. This example uses realtime audio input but can be used for audiofile input as well. |
| 68 | <example> |
| 69 | <title>Example of the pvspitch opcode</title> |
| 70 | <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para> |
| 71 | <xi:include href="examples-xml/pvspitch.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 72 | </example> |
| 73 | </para> |
| 74 | </refsect1> |
| 75 | |
| 76 | <refsect1> |
| 77 | <title>See also</title> |
| 78 | <para><link linkend="SpectralRealTime"><citetitle>Tools for Real-time Spectral Processing (pvs opcodes)</citetitle></link></para> |
| 79 | <para><link linkend="ControlSensing"><citetitle>Sensing and Control: Tempo and Pitch estimation</citetitle></link></para> |
| 80 | </refsect1> |
| 81 | |
| 82 | <refsect1> |
| 83 | <title>Credits</title> |
| 84 | <para> |
| 85 | <simplelist> |
| 86 | <member>Author: Alan OCinneide</member> |
| 87 | <member>August 2005, added by &namevictor;, August 2006</member> |
| 88 | <member>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: <ulink url="http://www.csoundjournal.com/2006winter/pvspitch.html"><citetitle>www.csoundjournal.com/2006winter/pvspitch.html</citetitle></ulink></member> |
| 89 | </simplelist> |
| 90 | </para> |
| 91 | |
| 92 | </refsect1> |
| 93 | </refentry> |