いらないモノ、ひつようなモノ

書籍、音楽、そして若干のテクノロジー

楽器ライブラリ/霧の中を左右に通り過ぎる、ドップラー効果を伴った音源

←csoundメモ 目次に戻る

かなり減衰する暗い濃密な霧の中を、音源が左から右へ、右から左へとドップラー効果伴って動いていくようす*1

;
; Title: moving sound source in a thick fog with doppler effect
; Date:  2009/01/06
; Author: a9a9qq@gmail.com
;
; description:
;  the sound source is moving in front of the observer from left to right 
;  or the right to left with doppler effect.
;  -p4: amp( around 500 )
;  -p5: note(Hz)
;  -p6: direction(-1 or 1)
;  

<CsoundSynthesizer>
<CsOptions>
-+msg_color=no -dWm0  -o doppler.wav
</CsOptions>
<CsInstruments>
sr     = 44100
kr     = 4410
ksmps  = 10
nchnls = 2

gitab   ftgen 1, 0,65536,10,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
gitab   ftgen 2, 0,65536,10,1,0.5,0.25,0.125
garvbl  init 0
garvbr  init 0
gacombl init 0
gacombr init 0

instr 100
 ar1 comb gacombr, p4, p5
 ar2 comb gacombr, p4, p5/4
 al1 comb gacombl, p4, p5*.66
 al2 comb gacombl, p4, p5/2
 a1  = ar1+(ar2*.5)
 a2  = (al1*.2)+(al2*.8)
 outs  a1,a2
 gacombr  =         0
 gacombl  =         0
endin

instr   101
 idur    = p3
 irvbtim = p4
 ihiatn  = p5
 arvb1   nreverb garvbl, irvbtim, ihiatn
 arvb2   nreverb garvbr, irvbtim, ihiatn
 outs    arvb1, arvb2
 garvbl  = 0
 garvbr  = 0
endin

instr 1
  idur   = p3
  kA     = p4
  kfrq   = p5
  ifn    = 2
  ka     = 0.2             ; attenuation rate
  idist  = 10.0            ; the initial or the final distance between 
                           ; the observer and the sound source.
  idist  = idist*p6        ; if p6>0 right to left, p6<0 right to left. 
  ih     = 0.3             ; min Y-axis distance bet. the obv. and the source
  idf    = 10.0            ; intensify the doppler effect (1.0 - 500)
  kh     = k(ih)
  kvs    = 340.0           ; the speed of sound
  kdist  = k(idist)    
  kdur   = k(idur)
  kv     = 2.0*kdist/kdur  ; the velocity of sound source
  kv     = kv*idf
  ; X-axis 
  kx       linseg -idist,idur/2.0,0,idur/2.0,idist

  ; the simulation to dump the amplitude.
  ; assume the wave equation is "y=exp(-ka*X)*sin(t)"
  kamp   = kA*(exp(-ka*sqrt(kx*kx+kh*kh))*exp(-ka*sqrt(kx*kx+kh*kh)))

  ; the simulation of doppler effect
  ; if you change the sign of kx in the equation below, 
  ; the revered doppler effect, which would never happen in the 
  ; real world, would happen.
  ; kfrqd  = kfrq*kvs/(kvs-kv*kx/sqrt(kh*kh +kx*kx))
  kfrqd  = kfrq*kvs/(kvs+kv*kx/sqrt(kh*kh +kx*kx))

  ; sound source
  aout     oscil  kamp, kfrqd, ifn

  ; the simulation of pannning
  ktheta   linseg taninv(-idist/ih),idur,taninv(idist/ih)
  al    = sqrt(2.0)/2.0*(cos(ktheta)+sin(ktheta)) * kamp * aout
  ar    = sqrt(2.0)/2.0*(cos(ktheta)-sin(ktheta)) * kamp * aout
  outs    al, ar

  ; for effect
  garvbl    = garvbl +(al*.1)
  garvbr    = garvbr +(ar*.1)
  gacombl   = gacombl+(al*.3)
  gacombr   = gacombr+(ar*.3)

endin

</CsInstruments>
<CsScore>
i100  0  50   6  .66
i101  0  50   5   .7
i1    0  10 500  40    1
i1   10  10 500  80   -1
i1   20  10 500 120    1
i1   30  10 500 220    1
i1   40  10 500 440   -1

</CsScore>
</CsoundSynthesizer>

*1:音自身をもう少し色の付け方があるがUDOにして移動効果だけを別にすると言う手もあるが手っ取り早く作ってみたので記録。かなーり久しぶりにドップラー効果とかなんとか物理チックな数式を思い出した。ここまでやると音源が丸くて両端に穴が開いててそれがくるくる回りながら通りすぎるとかやってみたいなー(能力の限界を越えているかもしれないけど)。