跳轉至內容

在 SuperCollider 中設計聲音/電話鈴聲

來自華夏公益教科書

29 老式電話鈴聲

[編輯 | 編輯原始碼]

在本書中,共振的一個分音符使用正弦波建模,並透過一個在二次曲線形狀上逐漸衰減的包絡進行調製。然後製作三組這樣的振盪器。

在這裡,我們利用了 SuperCollider 中的一個內建單元 Klank,它為我們做了很多工作:不同之處在於,它提供了指數衰減而不是二次衰減——這並不太糟糕,因為指數衰減通常是您想要的。

圖 29.11:帶有三個音調的簡單金屬共振

[編輯 | 編輯原始碼]
(
{
	var son;
	son = Klank.ar(`[
		[521, 732, 934],  // freqs
		[0.7, 0.45, 0.25],// amps
		[0.8, 0.8, 0.8]   // ring times
		],
	Impulse.ar(1));
	Pan2.ar(son * 0.2)
}.play
)

圖 29.12:敲擊聲

[編輯 | 編輯原始碼]

正如書中所述,我們只需要一個簡短的點選來近似模擬聲音的這部分。

(
x = {
	var son = WhiteNoise.ar(XLine.ar(1, 0.000001, 0.01, doneAction: 2)) * 0.1;
	Pan2.ar(son)
}.play
)

圖 29.13:多個共振器來建立鈴聲的各種模式

[編輯 | 編輯原始碼]
(
SynthDef(\dsaf_phonebell1, { |freq=465, strength=1, decay=3|
	var son;
	son = Klank.ar(`[
		// frequency ratios
		[0.501, 1, 0.7,   2.002, 3, 9.6,   2.49, 11, 2.571,  3.05, 6.242, 12.49, 13, 16, 24],
		// amps
		[0.002,0.02,0.001, 0.008,0.02,0.004, 0.02,0.04,0.02, 0.005,0.05,0.05, 0.02, 0.03, 0.04],
		// ring times - "stutter" duplicates each entry threefold
		[1.2, 0.9, 0.25, 0.14, 0.07].stutter(3)
		]
	, Impulse.ar(1), freq, 0, decay);
	Out.ar(0, Pan2.ar(son));
}).add
)
x = Synth(\dsaf_phonebell1, [\freq, 500]);

注意:在新增以下效果時,讓鈴聲繼續播放

圖 29.14:酚醛樹脂電話外殼的共振效應

[編輯 | 編輯原始碼]
(
SynthDef(\dsaf_phonecase1, { |in=0, out=0, mix=0|
	var casein = In.ar(in, 2);
		
	var delayA = CombC.ar(casein, 0.00077, 0.00077, 0.1);
	var delayB = CombC.ar(delayA, 0.00088, 0.00088, 0.1);
	var bands = BPF.ar(delayB, [1243, 287, 431], 1/12).sum;
	var son = bands.clip2(0.3);
	
	ReplaceOut.ar(out, XFade2.ar(casein, son, mix))

}).add
)
y = Synth(\dsaf_phonecase1, target: x, addAction: \addAfter);

如果您使用的是 sc3.3 或更高版本,您可以視覺化過濾器效果的頻率表示

GUI.stethoscope.defaultServer.boot;
(
// Notice that for this shortcut visualisation, we define the filter as a function taking its 
//  input as an argument, and returning its output (we don't use In.ar or Out.ar)
{ |casein|
	var delayA = CombC.ar(casein, 0.00077, 0.00077, 0.1);
	var delayB = CombC.ar(delayA, 0.00088, 0.00088, 0.1);
	var bands = BPF.ar(delayB, [1243, 287, 431], 1/12).sum;
	var son = bands.clip2(0.3);
	
	// Mouse to the LEFT means flat filter (no change), to the RIGHT means full bakelite
	XFade2.ar(casein, son, MouseX.kr(-1,1));
	
}.scopeResponse
)

圖 29.14:將所有內容整合在一起

[編輯 | 編輯原始碼]

我們將重新使用圖 29.14 中的 SynthDef,因此請確保您已執行它,以便伺服器具有該 SynthDef。(但如果聲音仍在播放,請將其停止。)

// A tweaked version of the phonebell synthdef, to take an on/off from outside, and incorporate the striker
(
SynthDef(\dsaf_phonebell2, { |gate=1, freq=465, strength=1, decay=3, amp=1|
	var trigs, striker, son;
	trigs = Impulse.ar(14) * gate;
	striker = WhiteNoise.ar(EnvGen.ar(Env.perc(0.0000001, 0.01), trigs));
	son = Klank.ar(`[
		// frequency ratios
		[0.501, 1, 0.7,   2.002, 3, 9.6,   2.49, 11, 2.571,  3.05, 6.242, 12.49, 13, 16, 24],
		// amps
		[0.002,0.02,0.001, 0.008,0.02,0.004, 0.02,0.04,0.02, 0.005,0.05,0.05, 0.02, 0.03, 0.04],
		// ring times - "stutter" duplicates each entry threefold
		[1.2, 0.9, 0.25, 0.14, 0.07].stutter(3)
		]
	, striker, freq, 0, decay);
	Out.ar(0, Pan2.ar(son * amp));
}).add
)

// We could launch the patch all at once, but let's do it bit-by-bit so we understand what's going on

// Here we start the phone bells constantly ringing. We put them in a group for convenience
~bellgroup = Group.new(s);
~bell1 = Synth(\dsaf_phonebell2, [\freq, 650], ~bellgroup);
~bell2 = Synth(\dsaf_phonebell2, [\freq, 653], ~bellgroup);

// Now we add the bakelite
y = Synth(\dsaf_phonecase1, [\mix, -0.65], target: ~bellgroup, addAction: \addAfter);

// OK, shush for now
~bellgroup.set(\gate, 0);

// Now let's turn them on and off in a telephone-like pattern.
// This could be done using a synth, but let's use a (client-side) pattern:
p = Pbind(\type, \set, \id, ~bellgroup.nodeID, \args, [\gate], \gate, Pseq([1,0], inf), \dur, 2).play
p.stop
華夏公益教科書