1<CsoundSynthesizer> 2<CsOptions> 3--env:SSDIR+=../SourceMaterials </CsOptions> 4<CsInstruments> 5sr = 44100 6ksmps = 32 7nchnls = 4 80dbfs = 1 9 10;#include "ambisonics_udos.txt" 11 12; opcode AEP1 is the same as in udo_AEP_xyz.csd 13 14opcode AEP1, a, akiiiikkkkkk ; soundin, order, ixs, iys, izs, idsmax, kx, ky, kz 15ain,korder,ixs,iys,izs,idsmax,kx,ky,kz,kdist,kfade,kgain xin 16idists = sqrt(ixs*ixs+iys*iys+izs*izs) 17kpan = kgain*((1-kfade+kfade*(kx*ixs+ky*iys+kz*izs)/(kdist*idists))^korder) 18 xout ain*kpan*idists/idsmax 19endop 20 21; opcode AEP calculates ambisonics equivalent panning for n speaker 22; the number n of output channels defines the number of speakers (overloaded function) 23; inputs: sound ain, order korder (any real number >= 1) 24; ifn = number of the function containing the speaker positions 25; position and distance of the sound source kaz,kel,kdist in degrees 26 27opcode AEP, aaaa, akikkk 28ain,korder,ifn,kaz,kel,kdist xin 29kaz = $M_PI*kaz/180 30kel = $M_PI*kel/180 31kx = kdist*cos(kel)*cos(kaz) 32ky = kdist*cos(kel)*sin(kaz) 33kz = kdist*sin(kel) 34ispeaker[] array 0, 35 table(3,ifn)*cos(($M_PI/180)*table(2,ifn))*cos(($M_PI/180)*table(1,ifn)), 36 table(3,ifn)*cos(($M_PI/180)*table(2,ifn))*sin(($M_PI/180)*table(1,ifn)), 37 table(3,ifn)*sin(($M_PI/180)*table(2,ifn)), 38 table(6,ifn)*cos(($M_PI/180)*table(5,ifn))*cos(($M_PI/180)*table(4,ifn)), 39 table(6,ifn)*cos(($M_PI/180)*table(5,ifn))*sin(($M_PI/180)*table(4,ifn)), 40 table(6,ifn)*sin(($M_PI/180)*table(5,ifn)), 41 table(9,ifn)*cos(($M_PI/180)*table(8,ifn))*cos(($M_PI/180)*table(7,ifn)), 42 table(9,ifn)*cos(($M_PI/180)*table(8,ifn))*sin(($M_PI/180)*table(7,ifn)), 43 table(9,ifn)*sin(($M_PI/180)*table(8,ifn)), 44 table(12,ifn)*cos(($M_PI/180)*table(11,ifn))*cos(($M_PI/180)*table(10,ifn)), 45 table(12,ifn)*cos(($M_PI/180)*table(11,ifn))*sin(($M_PI/180)*table(10,ifn)), 46 table(12,ifn)*sin(($M_PI/180)*table(11,ifn)) 47 48idsmax table 0,ifn 49kdist = kdist+0.000001 50kfade = .5*(1 - exp(-abs(kdist))) 51kgain = taninv(kdist*1.5708)/(kdist*1.5708) 52 53a1 AEP1 ain,korder,ispeaker[1],ispeaker[2],ispeaker[3], 54 idsmax,kx,ky,kz,kdist,kfade,kgain 55a2 AEP1 ain,korder,ispeaker[4],ispeaker[5],ispeaker[6], 56 idsmax,kx,ky,kz,kdist,kfade,kgain 57a3 AEP1 ain,korder,ispeaker[7],ispeaker[8],ispeaker[9], 58 idsmax,kx,ky,kz,kdist,kfade,kgain 59a4 AEP1 ain,korder,ispeaker[10],ispeaker[11],ispeaker[12], 60 idsmax,kx,ky,kz,kdist,kfade,kgain 61 xout a1,a2,a3,a4 62endop 63 64instr 1 65ain rand 1 66;ain soundin "/Users/user/csound/ambisonic/violine.aiff" 67kt line 0,p3,360 68korder init 24 69;kdist Dist kx, ky, kz 70a1,a2,a3,a4 AEP ain,korder,17,kt,0,1 71 outc a1,a2,a3,a4 72endin 73 74</CsInstruments> 75<CsScore> 76 77;fuction for speaker positions 78; GEN -2, parameters: max_speaker_distance, xs1,ys1,zs1,xs2,ys2,zs2,... 79;octahedron 80;f17 0 32 -2 1 1 0 0 -1 0 0 0 1 0 0 -1 0 0 0 1 0 0 -1 81;cube 82;f17 0 32 -2 1,732 1 1 1 1 1 -1 1 -1 1 -1 1 1 83;octagon 84;f17 0 32 -2 1 0.924 -0.383 0 0.924 0.383 0 0.383 0.924 0 -0.383 0.924 0 -0.924 0.383 0 -0.924 -0.383 0 -0.383 -0.924 0 0.383 -0.924 0 85;f17 0 32 -2 1 0 0 1 45 0 1 90 0 1 135 0 1 180 0 1 225 0 1 270 0 1 315 0 1 86;f17 0 32 -2 1 0 -90 1 0 -70 1 0 -50 1 0 -30 1 0 -10 1 0 10 1 0 30 1 0 50 1 87f17 0 32 -2 1 -45 0 1 45 0 1 135 0 1 225 0 1 88i1 0 2 89 90</CsScore> 91</CsoundSynthesizer> 92;example by martin neukom 93