<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>hrtfstat</title> <link rel="stylesheet" type="text/css" href="csound.css" /> <link rel="stylesheet" type="text/css" href="syntax-highlighting.css" /> <meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /> <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" /> <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" /> <link rel="prev" href="hrtfreverb.html" title="hrtfreverb" /> <link rel="next" href="hsboscil.html" title="hsboscil" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">hrtfstat</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="hrtfreverb.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="hsboscil.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry"> <a id="hrtfstat"></a> <div class="titlepage"></div> <a id="IndexHrtfstat" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">hrtfstat</span> </h2> <p>hrtfstat — Generates static 3d binaural audio for headphones using a Woodworth based spherical head model with improved low frequency phase accuracy. </p> </div> <div class="refsect1"> <a id="idm281472925371416"></a> <h2>Description</h2> <p> This opcode takes a source signal and spatialises it in the 3 dimensional space around a listener using head related transfer function (HRTF) based filters. It produces a static output (azimuth and elevation parameters are i-rate), because a static source allows much more efficient processing than <a class="link" href="hrtfmove.html" title="hrtfmove"><em class="citetitle">hrtfmove</em></a> and <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a>,. </p> </div> <div class="refsect1"> <a id="idm281472925325576"></a> <h2>Syntax</h2> <pre class="synopsis"> aleft, aright <span class="command"><strong>hrtfstat</strong></span> asrc, iAz, iElev, ifilel, ifiler [,iradius, isr] </pre> </div> <div class="refsect1"> <a id="idm281472925323336"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>iAz</em></span> -- azimuth value in degrees. Positive values represent position on the right, negative values are positions on the left. </p> <p> <span class="emphasis"><em>iElev</em></span> -- elevation value in degrees. Positive values represent position above horizontal, negative values are positions below horizontal (min -40). </p> <p> <span class="emphasis"><em>ifilel </em></span> -- left HRTF spectral data file </p> <p> <span class="emphasis"><em>ifiler </em></span> -- right HRTF spectral data file </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <table border="0" summary="Note"> <tr> <td rowspan="2" align="center" valign="top" width="25"> <img alt="[Note]" src="images/note.png" /> </td> <th align="left">Note</th> </tr> <tr> <td align="left" valign="top"> <p> Spectral datafiles (based on the MIT HRTF database) are available in 3 different sampling rates: 44.1, 48 and 96 khz and are labelled accordingly. Input and processing sr should match datafile sr. Files should be in the current directory or the SADIR (see <a class="link" href="CommandEnvironment.html" title="Csound Environment Variables"><em class="citetitle">Environment Variables</em></a>). </p> </td> </tr> </table> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <table border="0" summary="Note"> <tr> <td rowspan="2" align="center" valign="top" width="25"> <img alt="[Note]" src="images/note.png" /> </td> <th align="left">Note</th> </tr> <tr> <td align="left" valign="top"> <p> HRTF Data files for use with <a class="link" href="hrtfmove.html" title="hrtfmove"><em class="citetitle">hrtfmove</em></a>, <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a>, <a class="link" href="hrtfstat.html" title="hrtfstat"><em class="citetitle">hrtfstat</em></a>, <a class="link" href="hrtfearly.html" title="hrtfearly"><em class="citetitle">hrtfearly</em></a>, <a class="link" href="hrtfreverb.html" title="hrtfreverb"><em class="citetitle">hrtfreverb</em></a> were updated for Csound 5.15 and later (the code was updated and is more efficient). Old datafiles are now deprecated. </p> </td> </tr> </table> </div> <p> <span class="emphasis"><em>iradius</em></span> -- optional, head radius used for phase spectra calculation in centimeters (default 9.0) </p> <p> <span class="emphasis"><em>isr</em></span> - optional (default 44.1kHz). Legal values are 44100, 48000 and 96000. </p> </div> <div class="refsect1"> <a id="idm281472925309416"></a> <h2>Performance</h2> <p> Artifact-free user-defined static spatialisation is made possible using an interpolation algorithm based on spectral magnitude interpolation and a derived phase based on the Woodworth spherical head model. Accuracy is increased for the data set provided by extracting and applying a frequency dependent scaling factor to the phase spectra, leading to a more precise low frequency interaural time difference. Users can control head radius for the phase derivation, allowing a crude level of individualisation. The static source version of the opcode uses overlap add convolution (it does not need STFT processing, see <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a>), and is thus considerably more efficient than <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a> or <a class="link" href="hrtfmove.html" title="hrtfmove"><em class="citetitle">hrtfmove</em></a>, but cannot generate moving sources. </p> </div> <div class="refsect1"> <a id="idm281472925305288"></a> <h2>Examples</h2> <p> Here is an example of the hrtfstat opcode. It uses the file <a class="ulink" href="examples/hrtfstat.csd" target="_top"><em class="citetitle">hrtfstat.csd</em></a>. </p> <div class="example"> <a id="idm281472925303384"></a> <p class="title"> <strong>Example 406. Example of the hrtfstat opcode. </strong> </p> <div class="example-contents"> <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p> <div class="refsect1"> <a id="idm281472754337704"></a> <pre class="programlisting"> <span class="nt"><CsoundSynthesizer></span> <span class="nt"><CsOptions></span> <span class="c1">; Select audio/midi flags here according to platform</span> -odac <span class="c1">;;;realtime audio out</span> <span class="c1">;-iadc ;;;uncomment -iadc if realtime audio input is needed too</span> <span class="c1">; For Non-realtime ouput leave only the line below:</span> <span class="c1">; -o hrtfstat.wav -W ;;; for file output any platform</span> <span class="nt"></CsOptions></span> <span class="nt"><CsInstruments></span> <span class="vg">sr</span> <span class="o">=</span> <span class="mi">44100</span> <span class="vg">ksmps</span> <span class="o">=</span> <span class="mi">32</span> <span class="vg">nchnls</span> <span class="o">=</span> <span class="mi">2</span> <span class="vg">0dbfs</span> <span class="o">=</span> <span class="mi">1</span> ga<span class="n">src</span> <span class="nb">init</span> <span class="mi">0</span> <span class="kd">instr</span> <span class="nf">1</span> <span class="c1">;a plucked string</span> k<span class="n">amp</span> <span class="o">=</span> <span class="nb">p4</span> k<span class="n">cps</span> <span class="o">=</span> <span class="nb">cpspch</span><span class="p">(</span><span class="nb">p5</span><span class="p">)</span> i<span class="n">cps</span> <span class="o">=</span> <span class="nb">cpspch</span><span class="p">(</span><span class="nb">p5</span><span class="p">)</span> a<span class="n">1</span> <span class="nb">pluck</span> k<span class="n">amp</span><span class="p">,</span> k<span class="n">cps</span><span class="p">,</span> i<span class="n">cps</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> ga<span class="n">src</span> <span class="o">=</span> a<span class="n">1</span> <span class="kd">endin</span> <span class="kd">instr</span> <span class="nf">10</span><span class="c1">;uses output from instr1 as source</span> a<span class="n">left</span><span class="p">,</span>a<span class="n">right</span> <span class="nb">hrtfstat</span> ga<span class="n">src</span><span class="p">,</span> <span class="mi">90</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span> <span class="s">"hrtf-44100-left.dat"</span><span class="p">,</span><span class="s">"hrtf-44100-right.dat"</span> <span class="nb">outs</span> a<span class="n">left</span><span class="p">,</span> a<span class="n">right</span> <span class="nb">clear</span> ga<span class="n">src</span> <span class="kd">endin</span> <span class="nt"></CsInstruments></span> <span class="nt"><CsScore></span> <span class="nb">i</span><span class="mi">1</span> <span class="mi">0</span> <span class="mi">2</span> <span class="mf">.7</span> <span class="mf">8.00</span> <span class="c1">; Play Instrument 1: a plucked string</span> <span class="nb">i</span><span class="mi">1</span> <span class="mf">.5</span> <span class="mi">2</span> <span class="mf">.7</span> <span class="mf">8.00</span> <span class="nb">i</span><span class="mi">1</span> <span class="mi">1</span> <span class="mi">2</span> <span class="mf">.7</span> <span class="mf">8.00</span> <span class="nb">i</span><span class="mi">1</span> <span class="mi">2</span> <span class="mi">2</span> <span class="mf">.7</span> <span class="mf">7.00</span> <span class="nb">i</span><span class="mi">10</span> <span class="mi">0</span> <span class="mi">12</span> <span class="c1">; Play Instrument 10 for 2 seconds.</span> <span class="nt"></CsScore></span> <span class="nt"></CsoundSynthesizer></span> </pre> </div> </div> </div> <br class="example-break" /> <p> Here is another example of the hrtfstat opcode. It uses the file <a class="ulink" href="examples/hrtfstat-2.csd" target="_top"><em class="citetitle">htrfstat-2.csd</em></a>, and <a class="ulink" href="examples/Church.wav" target="_top"><em class="citetitle">Church.wav</em></a>, which is a looped sample. </p> <div class="example"> <a id="idm281472925297352"></a> <p class="title"> <strong>Example 407. Example two of the hrtfstat opcode</strong> </p> <div class="example-contents"> <div class="refsect1"> <a id="idm281472754264168"></a> <pre class="programlisting"> <span class="nt"><CsoundSynthesizer></span> <span class="nt"><CsOptions></span> <span class="c1">; Select audio/midi flags here according to platform</span> -odac <span class="c1">;;;realtime audio out</span> <span class="c1">;-iadc ;;;uncomment -iadc if realtime audio input is needed too</span> <span class="c1">; For Non-realtime ouput leave only the line below:</span> <span class="c1">; -o hrtfstat-2.wav -W ;;; for file output any platform</span> <span class="nt"></CsOptions></span> <span class="nt"><CsInstruments></span> <span class="vg">sr</span> <span class="o">=</span> <span class="mi">44100</span> <span class="vg">ksmps</span> <span class="o">=</span> <span class="mi">32</span> <span class="vg">nchnls</span> <span class="o">=</span> <span class="mi">2</span> <span class="vg">0dbfs</span> <span class="o">=</span> <span class="mi">1</span> <span class="kd">instr</span> <span class="nf">1</span> i<span class="n">Az</span> <span class="o">=</span> <span class="nb">p4</span> i<span class="n">Elev</span> <span class="o">=</span> <span class="nb">p5</span> i<span class="n">tim</span> <span class="o">=</span> <span class="nb">ftlptim</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c1">; transeg a dur ty b dur ty c dur ty d</span> k<span class="n">amp</span> <span class="nb">transeg</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">p3</span><span class="o">*</span><span class="mf">.1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mf">.9</span><span class="p">,</span> <span class="nb">p3</span><span class="o">*</span><span class="mf">.3</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="mf">.5</span><span class="p">,</span> <span class="nb">p3</span><span class="o">*</span><span class="mf">.3</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span> a<span class="n">in</span> <span class="nb">loscil3</span> k<span class="n">amp</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">1</span> a<span class="n">left</span><span class="p">,</span>a<span class="n">right</span> <span class="nb">hrtfstat</span> a<span class="n">in</span><span class="p">,</span> i<span class="n">Az</span><span class="p">,</span> i<span class="n">Elev</span><span class="p">,</span> <span class="s">"hrtf-44100-left.dat"</span><span class="p">,</span><span class="s">"hrtf-44100-right.dat"</span> <span class="nb">outs</span> a<span class="n">left</span><span class="p">,</span> a<span class="n">right</span> <span class="kd">endin</span> <span class="nt"></CsInstruments></span> <span class="nt"><CsScore></span> <span class="nb">f</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">1</span> <span class="s">"Church.wav"</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span> <span class="c1">;Csound computes tablesize</span> <span class="c1">; Azim Elev</span> <span class="nb">i</span><span class="mi">1</span> <span class="mi">0</span> <span class="mi">7</span> <span class="mi">90</span> <span class="mi">0</span> <span class="c1">;to the right</span> <span class="nb">i</span><span class="mi">1</span> <span class="mi">3</span> <span class="mi">7</span> <span class="o">-</span><span class="mi">90</span> <span class="o">-</span><span class="mi">40</span> <span class="c1">;to the left and below</span> <span class="nb">i</span><span class="mi">1</span> <span class="mi">6</span> <span class="mi">7</span> <span class="mi">180</span> <span class="mi">90</span> <span class="c1">;behind and up</span> <span class="nb">e</span> <span class="nt"></CsScore></span> <span class="nt"></CsoundSynthesizer></span> </pre> </div> </div> </div> <p><br class="example-break" /> </p> </div> <div class="refsect1"> <a id="idm281472925295432"></a> <h2>See Also</h2> <p> <a class="link" href="hrtfmove.html" title="hrtfmove"><em class="citetitle">hrtfmove</em></a>, <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a>, <a class="link" href="hrtfer.html" title="hrtfer"><em class="citetitle">hrtfer</em></a>. </p> <p> More information on this opcode: <a class="ulink" href="http://www.csoundjournal.com/issue9/newHRTFOpcodes.html" target="_top"><em class="citetitle">http://www.csoundjournal.com/issue9/newHRTFOpcodes.html</em></a> , written by Brian Carty </p> </div> <div class="refsect1"> <a id="idm281472925290072"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: Brian Carty</td> </tr> <tr> <td>Maynooth</td> </tr> <tr> <td>2008</td> </tr> </table> <p> </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="hrtfreverb.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="OpcodesTop.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="hsboscil.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">hrtfreverb </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> hsboscil</td> </tr> </table> </div> </body> </html>