-
Notifications
You must be signed in to change notification settings - Fork 1
/
13.1 Intro to Ambisonics.scd
144 lines (114 loc) · 4.1 KB
/
13.1 Intro to Ambisonics.scd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//13
//intro to ambisonics
//first... intro to mid-side (MS) microphone technique
//ambisonic approacj is encoding a full sphere of sound into 4 channels
//DXARTS studios in Raitt (205, 117, 113) have a running decoder, so you can feed it with this 4-channel signal directly
//you can also decode the signal yourself into any number of speakers (or for headphone listening)
//---------------
// simple ambisonics panner
//--------------
//this uses external decoder (e.g. rooms 205/117/113)
s.options.numOutputBusChannels_(8);
s.reboot;
//radians vs degrees
0.raddeg;
pi.raddeg;
pi
1.57.raddeg;
0.degrad;
90.degrad;
180.degrad;
(
var synth, note, window, azKnob, elKnob;
s.waitForBoot({
synth = CtkSynthDef(\bfNoise, {arg out = 2, amp = 0.5, azimuth = 0, elevation = 0; //azimuth and elevation in radians
Out.ar(out, FoaPanB.ar(PinkNoise.ar(amp), azimuth, elevation));
});
s.sync; //so the synth is ready before we call it
note = synth.note.out_(2).play; //
window = Window.new.front;
window.onClose_({note.free});
azKnob = EZKnob(window, 60@60, \azimuth, ControlSpec(-180, 180, default: 0), {|knob| note.azimuth_(knob.value.degrad.neg)});
elKnob = EZKnob(window, 60@60, \elevation, ControlSpec(-90, 90, default: 0), {|knob| note.elevation_(knob.value.degrad)});
window.layout_(
HLayout(
VLayout(azKnob.labelView, azKnob.knobView, azKnob.numberView),
VLayout(elKnob.labelView, elKnob.knobView, elKnob.numberView),
);
);
});
)
//more advanced examples (including HRTF decoding for headphones):
"Introducing the Ambisonic Toolkit".openHelpFile;
//---------------
// simple ambisonics with switchable decoding (stereo, 6-channel, or exteranal decoder
//--------------
FoaDecoderMatrix.openHelpFile;
(
var synths, notes, window, azKnob, elKnob;
var decoderType, decoderMatrix;
var mainVolume;
var mainGroup, decGroup;
var bfBus;
mainVolume = 0.dbamp;
decoderType = \uhj; //possible \uhj - stereo, \hex - 6-channel, \bf - b-format directly to external decoder, \hrtf - for headphone listning
notes = IdentityDictionary.new;
s.waitForBoot({
if(decoderType == \hrtf, {
decoderMatrix = FoaDecoderKernel.newSpherical; //prepare internal buffers for hrtf decoder
s.sync;
});
synths = CtkProtoNotes(
SynthDef(\bfNoise, {arg out = 2, amp = 4, azimuth = 0, elevation = 0; //azimuth and elevation in radians
Out.ar(out, FoaPanB.ar(
PinkNoise.ar(amp) * Impulse.ar(2).lagud(0, 0.5),
azimuth, elevation));
}),
SynthDef(\decoder, {arg in = 0, out = 0; //azimuth and elevation in radians
var sndIn, sndOut;
sndIn = In.ar(in, 4); //4-channel bus input
decoderType.switch(
\uhj, {sndOut = B2UHJ.ar(sndIn[0], sndIn[1], sndIn[2])},
\bf, {sndOut = sndIn},
\hex, {sndOut = FoaDecode.ar(sndIn, FoaDecoderMatrix.newPanto(6, k: 'energy')).at([0, 5, 4, 3, 2, 1])},
\hrtf, {sndOut = FoaDecode.ar(sndIn, decoderMatrix)}
);
Out.ar(out, sndOut.clip(-1, 1) * mainVolume);
})
);
mainGroup = CtkGroup.play;
s.sync;
decGroup = CtkGroup.play(addAction: \tail);
bfBus = CtkAudio.new(4);
s.sync; //so the synth is ready before we call it
// notes[\dec] = synths[\decoder].note.in_(bfBus).out_(0).play; //start decider
// s.sync;
// notes[\src] = synths[\bfNoise].note(target: notes[\dec], addAction: \before).out_(bfBus).play;
notes[\dec] = synths[\decoder].note(target: decGroup).in_(bfBus).out_(0).play; //start decider
notes[\src] = synths[\bfNoise].note(target: mainGroup).out_(bfBus).play;
~src = notes[\src];
window = Window.new.front;
azKnob = EZKnob(window, nil, \azimuth, ControlSpec(-180, 180, default: 0), {|knob| notes[\src].azimuth_(knob.value.degrad.neg)});
elKnob = EZKnob(window, nil, \elevation, ControlSpec(-90, 90, default: 0), {|knob| notes[\src].elevation_(knob.value.degrad)});
window.layout_(
HLayout(
VLayout(azKnob.labelView, azKnob.knobView, azKnob.numberView),
VLayout(elKnob.labelView, elKnob.knobView, elKnob.numberView),
);
);
window.onClose_({
notes.do({arg thisNote;
thisNote.free;
});
mainGroup.free;
decGroup.free;
bfBus.free;
if(decoderMatrix.notNil, {
decoderMatrix.free;
}); //free the kernel
});
s.plotTree;
});
)
~src.amp_(12)
~src.amp_(48)