Debian Codegraph @

src/Examples/FLOSS Manual Examples/05 Sound Modification/05B16_udo_ambisonics_2.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 --env:SSDIR+=../../SourceMaterials -odac -m0
4 </CsOptions>
5 <CsInstruments>
6 sr = 44100
7 ksmps = 32
8 nchnls = 1
9 0dbfs = 1
10
11 zakinit 81, 1 ; zak space for up to 81 channels of the 8th order B-format
12
13 ; the opcodes used below are safed in "ambisonics_udos.txt"
14 #include "../../SourceMaterials/ambisonics_udos.txt"
15
16 ; in-phase decoding up to third order for one speaker
17 opcode ambi_dec1_inph3, a, iii
18 ; weights up to 8th order
19 iWeight3D[][] init 8,8
20 iWeight3D array 0.333333,0,0,0,0,0,0,0,
21 0.5,0.1,0,0,0,0,0,0,
22 0.6,0.2,0.0285714,0,0,0,0,0,
23 0.666667,0.285714,0.0714286,0.0079365,0,0,0,0,
24 0.714286,0.357143,0.119048,0.0238095,0.0021645,0,0,0,
25 0.75,0.416667,0.166667,0.0454545,0.00757576,0.00058275,0,0,
26 0.777778,0.466667,0.212121,0.0707071,0.016317,0.002331,0.0001554,0,
27 0.8,0.509091,0.254545,0.0979021,0.027972,0.0055944,0.0006993,0.00004114
28
29 iorder,iaz,iel xin
30 iaz = $M_PI*iaz/180
31 iel = $M_PI*iel/180
32 a0=zar(0)
33 if iorder > 0 goto c0
34 aout = a0
35 goto end
36 c0:
37 a1=iWeight3D[iorder-1][0]*zar(1)
38 a2=iWeight3D[iorder-1][0]*zar(2)
39 a3=iWeight3D[iorder-1][0]*zar(3)
40 icos_el = cos(iel)
41 isin_el = sin(iel)
42 icos_az = cos(iaz)
43 isin_az = sin(iaz)
44 i1 = icos_el*isin_az ; Y = Y(1,-1)
45 i2 = isin_el ; Z = Y(1,0)
46 i3 = icos_el*icos_az ; X = Y(1,1)
47 if iorder > 1 goto c1
48 aout = (3/4)*(a0 + i1*a1 + i2*a2 + i3*a3)
49 goto end
50 c1:
51 a4=iWeight3D[iorder-1][1]*zar(4)
52 a5=iWeight3D[iorder-1][1]*zar(5)
53 a6=iWeight3D[iorder-1][1]*zar(6)
54 a7=iWeight3D[iorder-1][1]*zar(7)
55 a8=iWeight3D[iorder-1][1]*zar(8)
56
57 ic2 = sqrt(3)/2
58
59 icos_el_p2 = icos_el*icos_el
60 isin_el_p2 = isin_el*isin_el
61 icos_2az = cos(2*iaz)
62 isin_2az = sin(2*iaz)
63 icos_2el = cos(2*iel)
64 isin_2el = sin(2*iel)
65
66
67 i4 = ic2*icos_el_p2*isin_2az ; V = Y(2,-2)
68 i5 = ic2*isin_2el*isin_az ; S = Y(2,-1)
69 i6 = .5*(3*isin_el_p2 - 1) ; R = Y(2,0)
70 i7 = ic2*isin_2el*icos_az ; S = Y(2,1)
71 i8 = ic2*icos_el_p2*icos_2az ; U = Y(2,2)
72 aout = (1/3)*(a0 + 3*i1*a1 + 3*i2*a2 + 3*i3*a3 + 5*i4*a4 + 5*i5*a5 + \
73 5*i6*a6 + 5*i7*a7 + 5*i8*a8)
74
75 end:
76 xout aout
77 endop
78
79 ; overloaded opcode for decoding for 1 or 2 speakers
80 ; speaker positions in function table ifn
81 opcode ambi_dec2_inph, a,ii
82 iorder,ifn xin
83 xout ambi_dec1_inph(iorder,table(1,ifn),table(2,ifn))
84 endop
85 opcode ambi_dec2_inph, aa,ii
86 iorder,ifn xin
87 xout ambi_dec1_inph(iorder,table(1,ifn),table(2,ifn)),
88 ambi_dec1_inph(iorder,table(3,ifn),table(4,ifn))
89 endop
90 opcode ambi_dec2_inph, aaa,ii
91 iorder,ifn xin
92 xout ambi_dec1_inph(iorder,table(1,ifn),table(2,ifn)),
93 ambi_dec1_inph(iorder,table(3,ifn),table(4,ifn)),
94 ambi_dec1_inph(iorder,table(5,ifn),table(6,ifn))
95 endop
96
97 instr 1
98 asnd init 1
99 kdist init 1
100 kaz invalue "az"
101 kel invalue "el"
102
103 ambi_encode asnd,8,kaz,kel
104 ao1,ao2,ao3 ambi_dec_inph 8,17
105 outvalue "sp1", downsamp(ao1)
106 outvalue "sp2", downsamp(ao2)
107 outvalue "sp3", downsamp(ao3)
108 zacl 0,80
109 endin
110
111 </CsInstruments>
112 <CsScore>
113 f1 0 1024 10 1
114 f17 0 64 -2 0 0 0 90 0 0 90 0 0 0 0 0 0 0 0 0 0
115 i1 0 100
116 </CsScore>
117 </CsoundSynthesizer>
118 ;example by martin neukom