hrtfstat
Prev | Orchestra Opcodes and Operators | Next

## hrtfstat

hrtfstat — Generates static 3d binaural audio for headphones using a Woodworth based spherical head model with improved low frequency phase accuracy.

## Description

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 hrtfmove and hrtfmove2,.

## Syntax

          aleft, aright hrtfstat asrc, iAz, iElev, ifilel, ifiler [,iradius, isr]

## Initialization

iAz -- azimuth value in degrees. Positive values represent position on the right, negative values are positions on the left.

iElev -- elevation value in degrees. Positive values represent position above horizontal, negative values are positions below horizontal (min -40).

ifilel -- left HRTF spectral data file

ifiler -- right HRTF spectral data file

| Note
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 Environment Variables).

| Note
HRTF Data files for use with hrtfmove, hrtfmove2, hrtfstat, hrtfearly, hrtfreverb were updated for Csound 5.15 and later (the code was updated and is more efficient). Old datafiles are now deprecated.

iradius -- optional, head radius used for phase spectra calculation in centimeters (default 9.0)

isr - optional (default 44.1kHz). Legal values are 44100, 48000 and 96000.

## Performance

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 hrtfmove2), and is thus considerably more efficient than hrtfmove2 or hrtfmove, but cannot generate moving sources.

## Examples

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

Example 448. Example of the hrtfstat 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 realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o hrtfstat.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    gasrc init 0

    instr 1	;a plucked string

    kamp = p4
    kcps = cpspch(p5)
    icps = cpspch(p5)
    a1 pluck kamp, kcps, icps, 0, 1

    gasrc = a1

    endin

    instr 10;uses output from instr1 as source

    aleft,aright hrtfstat gasrc, 90,0, "hrtf-44100-left.dat","hrtf-44100-right.dat"
                 outs     aleft, aright

    clear gasrc
    endin

    </CsInstruments>
    <CsScore>

    i1 0 2 .7 8.00	; Play Instrument 1: a plucked string
    i1 .5 2 .7 8.00
    i1 1 2 .7 8.00
    i1 2 2 .7 7.00

    i10 0 12	; Play Instrument 10 for 2 seconds.

    </CsScore>
    </CsoundSynthesizer>

Here is another example of the hrtfstat opcode. It uses the file htrfstat-2.csd, and Church.wav, which is a looped sample.

Example 449. Example two of the hrtfstat opcode

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -odac     ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o hrtfstat-2.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    instr 1

    iAz   = p4
    iElev = p5

    itim = ftlptim(1)
    ;    transeg a   dur   ty  b  dur    ty  c    dur   ty  d
    kamp transeg 0, p3*.1, 0, .9, p3*.3, -3, .5,  p3*.3, -2, 0
    ain  loscil3 kamp, 50, 1
    aleft,aright hrtfstat ain, iAz, iElev, "hrtf-44100-left.dat","hrtf-44100-right.dat"
         outs aleft, aright

    endin
    </CsInstruments>
    <CsScore>
    f 1 0 0 1 "Church.wav" 0 0 0 ;Csound computes tablesize

    ;      Azim Elev
    i1 0 7  90   0  ;to the right
    i1 3 7 -90  -40 ;to the left and below
    i1 6 7 180   90 ;behind and up
    e
    </CsScore>
    </CsoundSynthesizer>

## See also

Panning and Spatialization: Binaural spatialization

More information on this opcode: http://www.csoundjournal.com/issue9/newHRTFOpcodes.html, written by Brian Carty

## Credits

Author: Brian Carty
Maynooth
2008

Prev | Up | Next
hrtfreverb | Home | hsboscil