5. CSOUND SPATIAL AUDIO EXAMPLES
Below are working Csound implementations demonstrating spatial reverberation and 3D audio processing:
1. Reverberation Modeling
This example demonstrates how an instrument signal is processed through early delay taps and an artificial reverberator to create room depth:
Orchestra File (ejemplo2.orc):
sr = 44100
kr = 4410
ksmps = 10
nchnls = 2
; Global audio bus for reverb send
ga_reverb init 0
instr 1
; Dry sound source
a_sig oscil p4, p5, 1
; Send portion to global reverb bus
ga_reverb = ga_reverb + (a_sig * 0.3)
; Output direct sound
outs a_sig * 0.7, a_sig * 0.7
endin
instr 99 ; Master Reverberator
; Process global bus through stereo reverberator
a_revL, a_revR reverbsc ga_reverb, ga_reverb, 0.85, 12000
outs a_revL, a_revR
; Clear global bus for next control period
ga_reverb = 0
endin
2. Binaural Spatial Movement
This implementation uses Csound’s spatial opcodes to move a sound source across the listener’s auditory field:
instr 2
; Frequency modulated oscillator
k_mod oscil 20, 5, 1
a_src oscil 10000, 440 + k_mod, 1
; Azimuth sweeps from left (-90 deg) to right (+90 deg)
k_azim line -90, p3, 90
k_elev init 0
; Apply 3D spatial panning / HRTF filtering
a_left, a_right pan2 a_src, (k_azim + 90) / 180
outs a_left, a_right
endin