| Hi there,
Here is a part of my gardverb orchestra which does some doppler effects.
The iex & iey are the location of the ear, isx & isy is the x, y location of
the source and iwx & iwy are the x, y location of two walls of a rectangular
room (the other two walls are at 0,0). Instrument 18 allows for a rotation
of the source (ie. a rotating speaker or a pesky misquito) Hmmm looks like i
forgot to make any comments. I'll do it now and hopefully I won't screw up
anything. OK thats the comments. I didn't add them to 18.
Thoughts on 3D sound:
I had these all written down on a scrap of paper somewhere but now its gone.
I'll try to remember.
1. Reverb - do the reverb before you adjust the amplitude. That way distant
sounds will have more reverb.
2. Volume - Sound waves are quieter the further away they come from.
Supposedly 1/r^2 but 1/(r+1) seems better to me. That way the sound does
not go to infinity when it gets close and does not fade to nothing so soon.
3. Doppler - Delay lines work well for simulating the pitch shift due to
doppler effects.
4. Air absorption - air absorbs the high frequencies more than the low
frequencies. Use a low pass filter on distant sounds.
5. HRTF - Sound bouncing off the ears gives a clue to where it is coming
from. Apply the HRTF.
6. Early reflections - Echos from the nearby walls give a clue to the size
of the place.
That's all I can remember. Please correct any of my mistakes!
Good luck,
Hans Mikelson
;---------------------------------------------------------------------------
-------
; 2D Echos
;---------------------------------------------------------------------------
-------
instr 17
idur = p3 ; Duration
iamp = p4 ; Amplitude
iex = p5 ; Ear X coordinate
iey = p6 ; Ear Y coordinate
isx = p7 ; Source X coordinate
isy = p8 ; Source Y coordinate
iwx = p9 ; Wall X coordinate
iwy = p10 ; Wall Y coordinate
iinch = p11 ; Input Channel
ioutch1 = p12 ; Output Channel 1
ioutch2 = p13 ; Output Channel 2
ipi = 3.14159265 ; Pi
inv4pi = 1/4/3.14159265 ; 1 over 4*pi
kamp linseg 0, .002, iamp, idur-.004, iamp, .002, 0 ; Declick evelope
ain zar iinch ; Read from an audio channel
iemsx = iex-isx ; Delta X
iemsy = iey-isy ; Delta Y
iepsx = iex+isx ; Echo from wall X0
iepsy = iey+isy ; Echo from wall Y=0
iw2x = 2*iwx-iex-isx ; Echo from wall Wx
iw2y = 2*iwy-iey-isy ; Echo from wall Wy
iang0 = atan(iemsx/iemsy) ; Angle of direct sound
idist0 = sqrt(iemsx*iemsx+iemsy*iemsy); Distance to sound
iang1 = atan(iemsx/iepsy) ; Angle from wall Y=0
idist1 = sqrt(iemsx*iemsx+iepsy*iepsy); Distance from wall Y=0
iang2 = atan(iemsy/iepsx) ; Angle from wall X=0
idist2 = sqrt(iemsy*iemsy+iepsx*iepsx); Distance from wall X=0
iang3 = atan(iemsx/iw2y) ; Angle from wall Wx
idist3 = sqrt(iemsx*iemsx+iw2y*iw2y) ; Distance from wall Wx
iang4 = atan(iemsy/iw2x) ; Angle from wall Wy
idist4 = sqrt(iemsy*iemsy+iw2x*iw2x) ; Distance from wall Wy
adel0 delay ain/(1+idist0/2), idist0/333 ; Speed of sound in meters/sec
adel1 delay ain/(1+idist1/4), idist1/333 ; The further away a sound is
adel2 delay ain/(1+idist2/4), idist2/333 ; the quieter it is. But not
adel3 delay ain/(1+idist3/4), idist3/333 ; too quiet!
adel4 delay ain/(1+idist4/4), idist4/333
;al1, ar1 hrtfer adel1, kang1, 0, "hrtfcomp" ; Apply optional head related
transfer
;al2, ar2 hrtfer adel2, kang2, 0, "hrtfcomp" ; function if you want it to
really
;al3, ar3 hrtfer adel3, kang3, 0, "hrtfcomp" ; render slowly and be full
of clicks.
;al4, ar4 hrtfer adel4, kang4, 0, "hrtfcomp"
al0 = adel0*sqrt( (iang0+ipi)*inv4pi) ; Compute left and right
speaker
ar0 = adel0*sqrt(1-(iang0+ipi)*inv4pi) ; volume from the angles.
al1 = adel1*sqrt( (iang1+ipi)*inv4pi)
ar1 = adel1*sqrt(1-(iang1+ipi)*inv4pi)
al2 = adel2*sqrt( (iang2+ipi)*inv4pi)
ar2 = adel2*sqrt(1-(iang2+ipi)*inv4pi)
al3 = adel3*sqrt( (iang3+ipi)*inv4pi)
ar3 = adel3*sqrt(1-(iang3+ipi)*inv4pi)
al4 = adel4*sqrt( (iang4+ipi)*inv4pi)
ar4 = adel4*sqrt(1-(iang4+ipi)*inv4pi)
aoutl = (al0+al1+al2+al3+al4)*kamp ; Sum and declick
aoutr = (ar0+ar1+ar2+ar3+ar4)*kamp
outs aoutl, aoutr ; Output results
zaw aoutl, ioutch1 ; Output to audio
channels
zaw aoutr, ioutch2
endin
;---------------------------------------------------------------------------
-------
; 2D Echos Rotating
;---------------------------------------------------------------------------
-------
instr 18
idur = p3
iamp = p4
kex init p5
key init p6
isx init p7
isy init p8
iwx init p9
iwy init p10
iinch = p11
ioutch1 = p12
ioutch2 = p13
ipi = 3.14159265
inv4pi = 1/4/3.14159265
imaxdel = sqrt(iwx*iwx+iwy*iwy)*2
kamp linseg 0, .002, iamp, idur-.004, iamp, .002, 0
kramp linseg .3, .2, 1, p3/2-.2, .3, .2, 1, p3/2-.2, .5
ks1 oscil 5, kramp, 1
kc1 oscil 5, kramp, 1, .25
ksx = kc1+isx
ksy = ks1+isy
ain zar iinch
kemsx = kex-ksx
kemsy = key-ksy
kepsx = kex+ksx
kepsy = key+ksy
kw2x = 2*iwx-kex-ksx
kw2y = 2*iwy-key-ksy
kang0 = atan(kemsx/kemsy)
kdist0 = sqrt(kemsx*kemsx+kemsy*kemsy)
kang1 = atan(kemsx/kepsy)
kdist1 = sqrt(kemsx*kemsx+kepsy*kepsy)
kang2 = atan(kemsy/kepsx)
kdist2 = sqrt(kemsy*kemsy+kepsx*kepsx)
kang3 = atan(kemsx/kw2y)
kdist3 = sqrt(kemsx*kemsx+kw2y*kw2y)
kang4 = atan(kemsy/kw2x)
kdist4 = sqrt(kemsy*kemsy+kw2x*kw2x)
adeli0 vdelay ain, kdist0/.333, imaxdel
adeli1 vdelay ain, kdist1/.333, imaxdel
adeli2 vdelay ain, kdist2/.333, imaxdel
adeli3 vdelay ain, kdist3/.333, imaxdel
adeli4 vdelay ain, kdist4/.333, imaxdel
adel0 = adeli0/(1+kdist0/4)
adel1 = adeli1/(1+kdist1/4)
adel2 = adeli2/(1+kdist2/4)
adel3 = adeli3/(1+kdist3/4)
adel4 = adeli4/(1+kdist4/4)
;al1, ar1 hrtfer adel1, kang1, 0, "hrtfcomp"
;al2, ar2 hrtfer adel2, kang2, 0, "hrtfcomp"
;al3, ar3 hrtfer adel3, kang3, 0, "hrtfcomp"
;al4, ar4 hrtfer adel4, kang4, 0, "hrtfcomp"
al0 = adel0*sqrt( (kang0+ipi)*inv4pi)
ar0 = adel0*sqrt(1-(kang0+ipi)*inv4pi)
al1 = adel1*sqrt( (kang1+ipi)*inv4pi)
ar1 = adel1*sqrt(1-(kang1+ipi)*inv4pi)
al2 = adel2*sqrt( (kang2+ipi)*inv4pi)
ar2 = adel2*sqrt(1-(kang2+ipi)*inv4pi)
al3 = adel3*sqrt( (kang3+ipi)*inv4pi)
ar3 = adel3*sqrt(1-(kang3+ipi)*inv4pi)
al4 = adel4*sqrt( (kang4+ipi)*inv4pi)
ar4 = adel4*sqrt(1-(kang4+ipi)*inv4pi)
aoutl = (al0+al1+al2+al3+al4)*kamp
aoutr = (ar0+ar1+ar2+ar3+ar4)*kamp
outs aoutl, aoutr
zaw (adeli0+adeli1+adeli2), ioutch1
zaw (adeli0+adeli3+adeli4), ioutch2
endin
|