René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback
 

stereo

sr     = 44100
kr     = 44100
nchnls = 2


instr 1

  ilen    = p3
  iamp    = p4
  ifrq    = cpspch(p5)

  ix      = p6
  iy      = p7
  
  idistr  = sqrt ( iy*iy + (ix-0.1) * (ix-0.1) )
  idistl  = sqrt ( iy*iy + (ix+0.1) * (ix+0.1) )

  ;print idistr
  ;print idistl

  idelayr = idistr/340
  idelayl = idistl/340

  ;print idelayr
  ;print idelayl

  p3      = p3 + (idelayr > idelayl ? idelayr : idelayl)

  iloudr  = iamp/(idistr*idistr)
  iloudl  = iamp/(idistl*idistl)

  kenvr     linseg 0, idelayr, 0, 0.02, iloudr, ilen-0.02 - 0.1, iloudr*0.7, 0.1, 0
  kenvl     linseg 0, idelayl, 0, 0.02, iloudl, ilen-0.02 - 0.1, iloudl*0.7, 0.1, 0

  asigr     oscili kenvr, ifrq, 1
  asigl     oscili kenvl, ifrq, 1
   
  outs asigl, asigr
endin


The parameters p6 and p7 are the coordinates of the tone (in meters). The positive x axis goes out through the right ear, the positive y axis goes out through the eyes. The coordinates 0/0 are in the head.

idistr and idistl are the calculated distance of the tone from the right and left ear respectively.
This leads to the calculation of how much the tone is delayed until it reaches the ears: idelayl and idelayr.
Also, the amplitude ildoudr and ildoudl is dependent on idistn
Unfortunately, the values for idistn are so small that they don't appear to have an influence on the perception of the tone.
f1 0 2048 10 1

i1 0.0 0.2 10000 7.00  1.00000 0.00000
i1 0.2 0.2 10000 7.00 -1.00000 0.00000
i1 0.4 0.2 10000 7.00  1.00000 1.00000
i1 0.6 0.2 10000 7.00 -1.00000 1.00000