Debian Codegraph @

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

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 -odac
4 </CsOptions>
5 <CsInstruments>
6
7 sr = 44100
8 ksmps = 32
9 nchnls = 4
10 0dbfs = 1
11
12 ; ambisonics2D encoding fifth order
13 ; decoding for 8 speakers symmetrically positioned on a circle
14 ; all instruments write the B-format into a buffer (zak space)
15 ; instr 10 decodes
16
17 ; zak space with the 21 channels of the B-format up to 10th order
18 zakinit 21, 1
19
20 ;explicit encoding third order
21 opcode ambi2D_encode_3, 0, ak
22 asnd,kaz xin
23
24 kaz = $M_PI*kaz/180
25
26 zawm asnd,0
27 zawm cos(kaz)*asnd,1 ;a11
28 zawm sin(kaz)*asnd,2 ;a12
29 zawm cos(2*kaz)*asnd,3 ;a21
30 zawm sin(2*kaz)*asnd,4 ;a22
31 zawm cos(3*kaz)*asnd,5 ;a31
32 zawm sin(3*kaz)*asnd,6 ;a32
33
34 endop
35
36 ; encoding arbitrary order n(zakinit 2*n+1, 1)
37 opcode ambi2D_encode_n, 0, aik
38 asnd,iorder,kaz xin
39 kaz = $M_PI*kaz/180
40 kk = iorder
41 c1:
42 zawm cos(kk*kaz)*asnd,2*kk-1
43 zawm sin(kk*kaz)*asnd,2*kk
44 kk = kk-1
45
46 if kk > 0 goto c1
47 zawm asnd,0
48 endop
49
50 ; basic decoding for arbitrary order n for 1 speaker
51 opcode ambi2D_decode_basic, a, ii
52 iorder,iaz xin
53 iaz = $M_PI*iaz/180
54 igain = 2/(2*iorder+1)
55 kk = iorder
56 a1 = .5*zar(0)
57 c1:
58 a1 += cos(kk*iaz)*zar(2*kk-1)
59 a1 += sin(kk*iaz)*zar(2*kk)
60 kk = kk-1
61 if kk > 0 goto c1
62 xout igain*a1
63 endop
64
65 ; decoding for 2 speakers
66 opcode ambi2D_decode_basic, aa, iii
67 iorder,iaz1,iaz2 xin
68 iaz1 = $M_PI*iaz1/180
69 iaz2 = $M_PI*iaz2/180
70 igain = 2/(2*iorder+1)
71 kk = iorder
72 a1 = .5*zar(0)
73 c1:
74 a1 += cos(kk*iaz1)*zar(2*kk-1)
75 a1 += sin(kk*iaz1)*zar(2*kk)
76 kk = kk-1
77 if kk > 0 goto c1
78
79 kk = iorder
80 a2 = .5*zar(0)
81 c2:
82 a2 += cos(kk*iaz2)*zar(2*kk-1)
83 a2 += sin(kk*iaz2)*zar(2*kk)
84 kk = kk-1
85 if kk > 0 goto c2
86 xout igain*a1,igain*a2
87 endop
88
89 instr 1
90 asnd rand p4
91 ares reson asnd,p5,p6,1
92 kaz line 0,p3,p7*360 ;turns around p7 times in p3 seconds
93 ambi2D_encode_n asnd,10,kaz
94 endin
95
96 instr 2
97 asnd oscil p4,p5,1
98 kaz line 0,p3,p7*360 ;turns around p7 times in p3 seconds
99 ambi2D_encode_n asnd,10,kaz
100 endin
101
102 instr 10 ;decode all instruments (the first 4 speakers of a 18 speaker setup)
103 a1,a2 ambi2D_decode_basic 10,0,20
104 a3,a4 ambi2D_decode_basic 10,40,60
105 outc a1,a2,a3,a4
106 zacl 0,20 ; clear the za variables
107 endin
108
109
110 </CsInstruments>
111 <CsScore>
112 f1 0 32768 10 1
113 ; amp cf bw turns
114 i1 0 3 .7 1500 12 1
115 i1 2 18 .1 2234 34 -8
116 ; amp fr 0 turns
117 i2 0 3 .1 440 0 2
118 i10 0 3
119 </CsScore>
120 </CsoundSynthesizer>
121 ;example by martin neukom