| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-odac |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
sr = 44100 |
| 7 |
ksmps = 32 |
| 8 |
nchnls = 1 |
| 9 |
0dbfs = 1 |
| 10 |
|
| 11 |
zakinit 9, 1 ; zak space with the 9 channel B-format second order |
| 12 |
|
| 13 |
opcode ambi_encode, 0, aikk |
| 14 |
asnd,iorder,kaz,kel xin |
| 15 |
kaz = $M_PI*kaz/180 |
| 16 |
kel = $M_PI*kel/180 |
| 17 |
kcos_el = cos(kel) |
| 18 |
ksin_el = sin(kel) |
| 19 |
kcos_az = cos(kaz) |
| 20 |
ksin_az = sin(kaz) |
| 21 |
|
| 22 |
zawm asnd,0 ; W |
| 23 |
zawm kcos_el*ksin_az*asnd,1 ; Y = Y(1,-1) |
| 24 |
zawm ksin_el*asnd,2 ; Z = Y(1,0) |
| 25 |
zawm kcos_el*kcos_az*asnd,3 ; X = Y(1,1) |
| 26 |
|
| 27 |
if iorder < 2 goto end |
| 28 |
|
| 29 |
i2 = sqrt(3)/2 |
| 30 |
kcos_el_p2 = kcos_el*kcos_el |
| 31 |
ksin_el_p2 = ksin_el*ksin_el |
| 32 |
kcos_2az = cos(2*kaz) |
| 33 |
ksin_2az = sin(2*kaz) |
| 34 |
kcos_2el = cos(2*kel) |
| 35 |
ksin_2el = sin(2*kel) |
| 36 |
|
| 37 |
zawm i2*kcos_el_p2*ksin_2az*asnd,4 ; V = Y(2,-2) |
| 38 |
zawm i2*ksin_2el*ksin_az*asnd,5 ; S = Y(2,-1) |
| 39 |
zawm .5*(3*ksin_el_p2 - 1)*asnd,6 ; R = Y(2,0) |
| 40 |
zawm i2*ksin_2el*kcos_az*asnd,7 ; S = Y(2,1) |
| 41 |
zawm i2*kcos_el_p2*kcos_2az*asnd,8 ; U = Y(2,2) |
| 42 |
end: |
| 43 |
|
| 44 |
endop |
| 45 |
|
| 46 |
; decoding of order iorder for 1 speaker at position iaz,iel,idist |
| 47 |
opcode ambi_decode1, a, iii |
| 48 |
iorder,iaz,iel xin |
| 49 |
iaz = $M_PI*iaz/180 |
| 50 |
iel = $M_PI*iel/180 |
| 51 |
a0=zar(0) |
| 52 |
if iorder > 0 goto c0 |
| 53 |
aout = a0 |
| 54 |
goto end |
| 55 |
c0: |
| 56 |
a1=zar(1) |
| 57 |
a2=zar(2) |
| 58 |
a3=zar(3) |
| 59 |
icos_el = cos(iel) |
| 60 |
isin_el = sin(iel) |
| 61 |
icos_az = cos(iaz) |
| 62 |
isin_az = sin(iaz) |
| 63 |
i1 = icos_el*isin_az ; Y = Y(1,-1) |
| 64 |
i2 = isin_el ; Z = Y(1,0) |
| 65 |
i3 = icos_el*icos_az ; X = Y(1,1) |
| 66 |
if iorder > 1 goto c1 |
| 67 |
aout = (1/2)*(a0 + i1*a1 + i2*a2 + i3*a3) |
| 68 |
goto end |
| 69 |
c1: |
| 70 |
a4=zar(4) |
| 71 |
a5=zar(5) |
| 72 |
a6=zar(6) |
| 73 |
a7=zar(7) |
| 74 |
a8=zar(8) |
| 75 |
|
| 76 |
ic2 = sqrt(3)/2 |
| 77 |
|
| 78 |
icos_el_p2 = icos_el*icos_el |
| 79 |
isin_el_p2 = isin_el*isin_el |
| 80 |
icos_2az = cos(2*iaz) |
| 81 |
isin_2az = sin(2*iaz) |
| 82 |
icos_2el = cos(2*iel) |
| 83 |
isin_2el = sin(2*iel) |
| 84 |
|
| 85 |
|
| 86 |
i4 = ic2*icos_el_p2*isin_2az ; V = Y(2,-2) |
| 87 |
i5 = ic2*isin_2el*isin_az ; S = Y(2,-1) |
| 88 |
i6 = .5*(3*isin_el_p2 - 1) ; R = Y(2,0) |
| 89 |
i7 = ic2*isin_2el*icos_az ; S = Y(2,1) |
| 90 |
i8 = ic2*icos_el_p2*icos_2az ; U = Y(2,2) |
| 91 |
|
| 92 |
aout = (1/9)*(a0 + 3*i1*a1 + 3*i2*a2 + 3*i3*a3 + 5*i4*a4 + \ |
| 93 |
5*i5*a5 + 5*i6*a6 + 5*i7*a7 + 5*i8*a8) |
| 94 |
|
| 95 |
end: |
| 96 |
xout aout |
| 97 |
endop |
| 98 |
|
| 99 |
; overloaded opcode for decoding of order iorder |
| 100 |
; speaker positions in function table ifn |
| 101 |
opcode ambi_decode, a,ii |
| 102 |
iorder,ifn xin |
| 103 |
xout ambi_decode1(iorder,table(1,ifn),table(2,ifn)) |
| 104 |
endop |
| 105 |
opcode ambi_decode, aa,ii |
| 106 |
iorder,ifn xin |
| 107 |
xout ambi_decode1(iorder,table(1,ifn),table(2,ifn)), |
| 108 |
ambi_decode1(iorder,table(3,ifn),table(4,ifn)) |
| 109 |
endop |
| 110 |
opcode ambi_decode, aaa,ii |
| 111 |
iorder,ifn xin |
| 112 |
xout ambi_decode1(iorder,table(1,ifn),table(2,ifn)), |
| 113 |
ambi_decode1(iorder,table(3,ifn),table(4,ifn)), |
| 114 |
ambi_decode1(iorder,table(5,ifn),table(6,ifn)) |
| 115 |
endop |
| 116 |
|
| 117 |
instr 1 |
| 118 |
asnd init 1 |
| 119 |
;kdist init 1 |
| 120 |
kaz invalue "az" |
| 121 |
kel invalue "el" |
| 122 |
|
| 123 |
ambi_encode asnd,2,kaz,kel |
| 124 |
|
| 125 |
ao1,ao2,ao3 ambi_decode 2,17 |
| 126 |
outvalue "sp1", downsamp(ao1) |
| 127 |
outvalue "sp2", downsamp(ao2) |
| 128 |
outvalue "sp3", downsamp(ao3) |
| 129 |
zacl 0,8 |
| 130 |
endin |
| 131 |
|
| 132 |
|
| 133 |
</CsInstruments> |
| 134 |
<CsScore> |
| 135 |
;f1 0 1024 10 1 |
| 136 |
f17 0 64 -2 0 0 0 90 0 0 90 0 0 0 0 0 0 |
| 137 |
i1 0 100 |
| 138 |
</CsScore> |
| 139 |
</CsoundSynthesizer> |
| 140 |
;example by martin neukom |