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


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,.


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


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] 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).

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.


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.


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

Example 321. Example of the hrtfstat opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    ; Select flags here
    ; realtime audio out
 -o dac
    ; For Non-realtime ouput leave only the line below:
   ; -o hrtf.wav

    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 2

    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


    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



    ; Play Instrument 1: a plucked string
    i1 0 2 20000 8.00

    ; Play Instrument 10 for 2 seconds.
    i10 0 2


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

Example 322. Example two of the hrtfstat opcode

; 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

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

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

See Also

hrtfmove, hrtfmove2, hrtfer.

More information on this opcode: , written by Brian Carty


Author: Brian Carty