SuperCollider/Alarms 中的声音设计
外观
注意,为了清楚起见,我们将它分成了多行。练习: 将它重写为单行 - 并使用数组展开而不是两次编写 "SinOsc"。
(
Ndef(\alarm, {
var tone1 = SinOsc.ar(600);
var tone2 = SinOsc.ar(800);
// We switch between the tones using LFPulse, but soften the crossfade with the low-pass:
var control = LPF.kr(LFPulse.kr(2), 70);
var out = SelectX.ar(control, [tone1, tone2]);
Pan2.ar(out * 0.1)
}).play
)
(
Ndef(\alarm, {
var tone1 = SinOsc.ar(723);
var tone2 = SinOsc.ar(932);
var tone3 = SinOsc.ar(1012);
// Stepper is perfect for stepping through the options:
var control = LPF.kr(Stepper.kr(Impulse.kr(2), 0, 0, 2), 70);
var out = SelectX.ar(control, [tone1, tone2, tone3]);
Pan2.ar(out * 0.1)
}).play
)
或者,我们可以使用 Demand 单位更通用地编写完全相同的内容。频率只需作为数组给出 - 更改值,或在末尾添加新值。
(
Ndef(\alarm, {
var freq, out;
freq = Duty.kr(0.5, 0, Dseq([723, 932, 1012], inf));
freq = LPF.kr(freq, 70);
out = SinOsc.ar(freq);
Pan2.ar(out * 0.1)
}).play
)
这使用 .cos 和 .sin 进行波形整形 - 向左或向右移动鼠标以从我们的 4 种音色选项中进行选择。
(
Ndef(\alarm, {
var freq, out, operations;
freq = Duty.kr(0.05, 0, Dseq([723, 932, 1012], inf));
freq = LPF.kr(freq, 70);
out = SinOsc.ar(freq);
operations = [out, (out * pi).sin, (out * pi).cos, ((out+0.25) * pi).cos];
out = Select.ar(MouseX.kr(0,4).poll, operations);
Pan2.ar(out * 0.1)
}).play
)
练习: 修改 "Duty" 行,以便您可以为每个音符设置不同的持续时间。(提示:您可以像指定频率一样轻松地使用 Dseq 指定时间。)
正如您将在下面看到的,此 SynthDef 能够执行各种各样的序列。
(
SynthDef(\dsaf_multialarm, {
|length=0.05, freqs=#[600,800,600,800], timbre=1, repeats=inf|
var freq, out, operations;
freq = Duty.ar(length, 0, Dseq(freqs, repeats), doneAction: 2);
freq = LPF.ar(freq, 70);
out = LeakDC.ar(SinOsc.ar(freq));
out = Select.ar(timbre, [out, (out * pi).sin, (out * pi).cos, ((out+0.25) * pi).cos]);
// NOTE: when writing a synthdef always remember the Out ugen!
// (Handy shortcuts like Ndef and {}.play often add Out on your behalf)
Out.ar(0, Pan2.ar(out * 0.1))
}).add;
)
... 现在我们可以使用书中使用的序列来播放它。
// happy blips
Synth(\dsaf_multialarm, [\length, 0.1, \freqs, [349, 0, 349, 0], \timbre, 1, \repeats, 1]);
// affirmative
Synth(\dsaf_multialarm, [\length, 0.1, \freqs, [238, 0, 317, 0], \timbre, 2, \repeats, 1]);
// activate
Synth(\dsaf_multialarm, [\length, 0.02, \freqs, [300, 125, 0, 0], \timbre, 2, \repeats, 10]);
// invaders?
Synth(\dsaf_multialarm, [\length, 0.03, \freqs, [360, 238, 174, 158], \timbre, 1]);
// information
Synth(\dsaf_multialarm, [\length, 0.05, \freqs, [2000, 2010, 2000, 2010], \timbre, 1, \repeats, 6]);
// message alert
Synth(\dsaf_multialarm, [\length, 0.15, \freqs, [619, 571, 365, 206], \timbre, 1, \repeats, 2]);
// finished
Synth(\dsaf_multialarm, [\length, 0.15, \freqs, [365, 571, 619, 206], \timbre, 3, \repeats, 1]);
// error code
Synth(\dsaf_multialarm, [\length, 0.01, \freqs, [1000, 0, 1000, 0], \timbre, 3, \repeats, 30]);
// wronnnnnnnnnng
(
Pbind(
\instrument, \dsaf_multialarm,
\freqs, [[1000, 476, 159, 0]],
\timbre, 2,
\repeats, 25,
\length, Pseq([0.003, 0.005]),
\dur, 0.5
).play
)
练习: 找出为什么这些多警报示例中的一些听起来不太像 Andy 的音频示例!;)