hrtfearly
Prev | Orchestra Opcodes and Operators | Next

## hrtfearly

hrtfearly — Generates 3D binaural audio with high-fidelity early reflections in a parametric room using a Phase Truncation algorithm.

## Description

This opcode essentially nests the hrtfmove opcode in an image model for a user-definable shoebox-shaped room. A default room can be selected, or advanced room parameters can be used. Room surfaces can be controlled with high and low-frequency absorption coefficients and gain factors of a three-band equaliser.

Although valid as a stand alone opcode, hrtfearly is designed to work with hrtfreverb to provide spatially accurate, dynamic binaural reverberation. A number of sources can be processed dynamically using a number of hrtfearly instances. All can then be processed with one instance of hrtfreverb.

## Syntax

    aleft, aright, irt60low, irt60high, imfp hrtfearly asrc, ksrcx, ksrcy, ksrcz, klstnrx, klstnry, klstnrz, \
          ifilel, ifiler, idefroom [,ifade, isr, iorder, ithreed, kheadrot, iroomx, iroomy, iroomz, iwallhigh, \
          iwalllow, iwallgain1, iwallgain2, iwallgain3, ifloorhigh, ifloorlow, ifloorgain1, ifloorgain2, \
          ifloorgain3, iceilinghigh, iceilinglow, iceilinggain1, iceilinggain2, iceilinggain3]

## Initialization

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.

idefroom - default room, medium (1: 10*10*3), small (2: 3*4*3) or large (3: 20*25*7). Wall details (high coef, low coef, gain1, gain2, gain3): .3, .1, .75, .95, .9. Floor: .6, .1, .95, .6, .35. Ceiling: .2, .1, 1, 1, 1. If 0 is entered, optional room parameters will be read.

ifade - optional, number of processing buffers for phase change crossfade (default 8). Legal range is 1-24. See hrtfmove.

isr - optional, default 44.1kHz, legal values: 44100, 48000 and 96000.

iorder - optional, order of images processed: higher order: more reflections. Defaults to 1, legal range: 0-4.

ithreed - optional, process image sources in three dimensions (1) or two (0: default).

iroomx - optional, x room size in metres, will be read if no valid default room is entered (all below parameters behave similarly). Minimum room size is 2*2*2.

iroomy - optional, y room size.

iroomz - optional, z room size.

iwallhigh - optional, high frequency wall absorption coefficient (all 4 walls are assumed identical). Absorption coefficients will affect reverb time output.

iwalllow - optional, low frequency wall absorption coefficient.

iwallgain1 - optional, gain on filter centred at 250 Hz (all filters have a Q implying 4 octaves).

iwallgain2 - optional, as above, centred on 1000 Hz.

iwallgain3 - optional, as above, centred on 4000 Hz.

ifloorhigh, ifloorlow, ifloorgain1, ifloorgain2, ifloorgain3 - as above for floor.

iceilinghigh, iceilinglow, iceilinggain1, iceilinggain2, iceilinggain3 - as above for ceiling.

ksrcx source x location, must be 10 cm inside room. Also, near-field HRTFs are not processed, so source will not change spatially within a 45 cm radius of the listener. These restrictions also apply to location parameters below.

ksrcy source y location.

ksrcz source z location.

klstnrx, klstnry, klstnrz listener location, as above.

kheadrot - optional, angular value for head rotation.

asrc - Input/source signal.

irt60low - suggested low frequency reverb time for later binaural reverb.

irt60high - as above, for high frequency.

imfp - mean free path of room, to be used with later reverb.

## Examples

Here is an example of the hrtfearly and hrtfreverb opcodes. It uses the file hrtfearly.csd.

Example 414. Example of the htrfearly opcode.

    <CsoundSynthesizer>
    <CsOptions>

    ; Select flags here
    ; realtime audio out
     -o dac
    ; file ouput
    ; -o hrtf.wav

    </CsOptions>
    <CsInstruments>

    nchnls = 2

    gasrc init 0	;global

    instr 1		;a plucked string, distorted and filtered

      iamp = 15000
      icps = cpspch(p4)

      a1 pluck iamp, icps, icps, 0, 1
      adist distort1 a1, 10, .5, 0, 0
      afilt moogvcf2 adist, 8000, .5
      aout linen afilt, 0, p3, .01

      gasrc = gasrc + aout

    endin

    instr 10	;uses output from instr1 as source

      ;simple path for source
      kx line 2, p3, 9

      ;early reflections, room default 1
      aearlyl,aearlyr, irt60low, irt60high, imfp hrtfearly gasrc, kx, 5, 1, 5, 1, 1, "hrtf-44100-left.dat", "hrtf-44100-right.dat", 1

      ;later reverb, uses outputs from above
      arevl, arevr, idel hrtfreverb gasrc, irt60low, irt60high, "hrtf-44100-left.dat", "hrtf-44100-right.dat", 44100, imfp

      ;delayed and scaled
      alatel delay arevl * .1, idel
      alater delay arevr * .1, idel

      outs	aearlyl + alatel, aearlyr + alater

      gasrc = 0

    endin

    </CsInstruments>
    <CsScore>

    ; Play Instrument 1: a simple arpeggio
    i1 0 .2 8.00
    i1 + .2 8.04
    i1 + .2 8.07
    i1 + .2 8.11
    i1 + .2 9.02
    i1 + 1.5 8.11
    i1 + 1.5 8.07
    i1 + 1.5 8.04
    i1 + 1.5 8.00
    i1 + 1.5 7.09
    i1 + 4 8.00

    ; Play Instrument 10 for 13 seconds.
    i10 0 13

    </CsScore>
    </CsoundSynthesizer>

## See Also

hrtfreverb hrtfmove, hrtfmove2, hrtfstat, hrtfer.

## Credits

Author: Brian Carty
Maynooth
2011

Prev | Up | Next
hilbert2 | Home | hrtfmove