-
Notifications
You must be signed in to change notification settings - Fork 745
/
ASA.scd
233 lines (185 loc) · 6.47 KB
/
ASA.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/**
* Two Auditory Scene Analysis (ASA) experiences
* as proposed by Albert Bregman, Auditory Scene Analysis, MIT Press, 1990
*
* 1. Streaming: if rate of presentation and
* frequency gap between the two series of sinusoidal tones are varied,
* one or two stream(s) appear(s).
*
* 2. Miniature ASA Problem:
* Three short sinusoidal segments.
* Varying frequency distance of A and C with respect to B, and attack time of C, two groupings are possible:
* (A-B)/C: a two note melody with a low tone (parallel)
* A-(B+C): a simple tone and a complex tone (sequence)
*
* (andrea valle)
*/
(
// start server
s = Server.local.boot;
)
(
// Streaming
var r;
var rateSlide, deltaSlide, volumeSlide;
var pauseButton1, pauseButton2, recButton;
var volume1 = 1.0, volume2 = 1.0;
var base = 500;
var durVar1 = [0.05, 0.3, 0.15, 0.5], durVar2 = [0.5, 0.05, 0.3, 0.15];
var levels1 = [0, 1, 1, 0, 0], levels2 = [0, 0, 1, 1, 0];
var synth1, synth2;
var ezFunc = { |ez| ez.() };
var rateSpec = ControlSpec(0.05, 2.0, \exp, 1e-3, 0.01);
var deltaSpec = ControlSpec(0, 1000, \lin, 1, 1);
var volumeSpec = ControlSpec(0.0, 1.0, \lin, 0.1, 0.1);
// a SynthDef
SynthDef(\asaSine1, { |out=0, freq=440, dur=1.0, levels=#[0, 1, 1, 0, 0], durVar=#[1, 1, 1, 1], mul=0.5|
var env, snd;
env = Env.new(levels, dur * durVar, 'welch');
snd = SinOsc.ar(freq, mul: mul);
Out.ar(out, snd * EnvGen.kr(env));
}).add;
// a Routine
r = Routine {
inf.do { |i|
var k;
var arr1 = [0, 0, 1, 0, 2],
arr2 = [1, 0, 3, 1, 2];
// 1st Synth
synth1 = Synth.new(\asaSine1, [\levels, levels1, \durVar, durVar1]);
k = arr1[i.mod(5)] * 100 + base;
synth1.set(\freq, k);
synth1.set(\dur, rateSlide.value);
synth1.set(\mul, volumeSlide.value * volume1);
// 2nd Synth
synth2 = Synth(\asaSine1, [\levels, levels2, \durVar, durVar2]);
k = arr2[i.mod(5)] * 100 + base + deltaSlide.value;
synth2.set(\freq, k);
synth2.set(\dur, rateSlide.value);
synth2.set(\mul, volumeSlide.value * volume2);
// wait and free the Synths
rateSlide.value.wait;
[synth1, synth2].do(_.free);
}
};
// GUI stuff
w = Window("ASA: Streaming", Rect(20, 400, 440, 150)).front;
w.view.decorator = FlowLayout(w.view.bounds);
rateSlide = EZSlider(w, 400@20, "DurEach", rateSpec, ezFunc, 0.1);
deltaSlide = EZSlider(w, 400@20, "Delta", deltaSpec, ezFunc, 500);
volumeSlide = EZSlider(w, 400@20, "Volume", volumeSpec, ezFunc, 0.5);
w.view.decorator.nextLine.shift(50, 20);
pauseButton1 = Button(w, 110@30);
pauseButton1.states = [
["1 now is active", Color.black, Color.red],
["1 now is muted", Color.white, Color.black],
];
pauseButton1.action = { |state|
switch(state.value,
1, { volume1 = 0; "muted 1".postln },
0, { volume1 = 1; "activated 1".postln }
)
};
w.view.decorator.shift(10, 0);
pauseButton2 = Button(w, 110@30);
pauseButton2.states = [
["2 now is active", Color.black, Color.red],
["2 now is muted", Color.white, Color.black],
];
pauseButton2.action = { |state|
switch(state.value,
1, { volume2 = 0; "muted 2".postln },
0, { volume2 = 1; "activated 2".postln }
)
};
w.onClose_({ r.stop; [synth1, synth2].do(_.free); });
SystemClock.play(r);
)
(
// The miniature ASA problem
var r1, r2, r3;
var text;
var rateSlide, volumeSlide, freqASlide, freqBSlide, freqCSlide, shiftSlide;
var pauseButton1, pauseButton2, recButton;
var volume1 = 1.0, volume2 = 1.0, volume3 = 1.0;
var base = 500;
var durVar1 = [0.1, 0, 0.3, 0, 0.6], durVar2 = [0.6, 0, 0.3, 0, 0.1];
var durVar3 = durVar2;
var synth1, synth2, synth3;
var ezFunc = { |ez| ez.() };
var rateSpec = ControlSpec(0.2, 2.0, \exp, 1e-3, 0.01);
var freqASpec = ControlSpec(50, 2000, \exp, 1, 1);
var freqCSpec = ControlSpec(50, 500, \exp, 1, 1);
var shiftSpec = ControlSpec(-0.5, 0.0, \lin, 0.01, 0.01);
var volumeSpec = ControlSpec(0.0, 1.0, \lin, 0.1, 0.1);
// a SynthDef
SynthDef(\asaSine2, { |out=0, freq=1000, dur=1.0, durVar=#[1,1,1,1,1], mul=0.35, shift=0|
var env, snd;
env = Env.new([0, 0, 1, 1, 0, 0], dur * (durVar + (shift * [1, 0, 0, 0, 1])), 'welch');
snd = SinOsc.ar(freq, 0, mul);
Out.ar(out, snd * EnvGen.kr(env));
}).add;
// a Routine
r = Routine {
inf.do { |i|
// 1st Synth
synth1 = Synth(\asaSine2, [\durVar, durVar1]);
synth1.set(\freq, freqASlide.value);
synth1.set(\dur, rateSlide.value);
synth1.set(\mul, volumeSlide.value * volume1);
// 2nd Synth
synth2 = Synth(\asaSine2, [\freq, 500, \durVar, durVar2]);
synth2.set(\dur, rateSlide.value);
synth2.set(\mul, volumeSlide.value * volume2);
// 3rd Synth
synth3 = Synth(\asaSine2, [\durVar, durVar3]);
synth3.set(\freq, freqCSlide.value);
synth3.set(\dur, rateSlide.value);
synth3.set(\mul, volumeSlide.value * volume3);
synth3.set(\shift, shiftSlide.value);
// wait and free the Synths
rateSlide.value.wait;
[synth1, synth2, synth3].do(_.free);
}
};
// GUI stuff
w = Window("ASA: Miniature problem", Rect(20, 400, 440, 220)).front;
w.view.decorator = FlowLayout(w.view.bounds);
rateSlide = EZSlider(w, 400@20, "DurEach", rateSpec, ezFunc, 1.0);
freqASlide = EZSlider(w, 400@20, "Freq A", freqASpec, ezFunc, 1e3);
w.view.decorator.nextLine.shift(30);
text = TextField(w,Rect(0,0,200,30));
text.string = "Freq B = fixed at 500 Hz";
text.background_(Color.grey);
text.stringColor_(Color.white);
w.view.decorator.nextLine;
freqCSlide = EZSlider(w, 400@20, "Freq C", freqCSpec, ezFunc, 250);
shiftSlide = EZSlider(w, 400@20, "Shift C", shiftSpec, ezFunc, 0.0);
volumeSlide = EZSlider(w, 400@20, "Volume", volumeSpec, ezFunc, 0.5);
w.view.decorator.nextLine.shift(50, 20);
pauseButton1 = Button(w, 110@30);
pauseButton1.states = [
["A now is active", Color.black, Color.red],
["A now is muted", Color.white, Color.black],
];
pauseButton1.action = { |state|
switch(state.value,
1, { volume1 = 0; "muted A".postln },
0, { volume1 = 1; "activated A".postln }
)
};
w.view.decorator.shift(10, 0);
pauseButton2 = Button(w, 110@30);
pauseButton2.states = [
["C now is active", Color.black, Color.red],
["C now is muted", Color.white, Color.black],
];
pauseButton2.action = { |state|
switch(state.value,
1, { volume3 = 0; "muted C".postln },
0, { volume3 = 1; "activated C".postln }
)
};
w.onClose_({ r.stop; [synth1, synth2, synth3].do(_.free); });
SystemClock.play(r);
)