Debian Codegraph @

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

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