«R2D2» by DSastre

on 22 Jul'12 15:20 in scifistar warsfmr2d2

A "computer babble" sound and a FM Synthesizer for computer noises. Based on pure data code from the book "Designing Sound" by Andy Farnell.

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
//****************************************
// Fig 57.3: Babbling R2D2 computer noises

// "[...] it might not even make any good noises for a while, 
// but sometimes it makes great computer babble sounds". (Andy Farnell)

(
w = {   |period=0|
        var change, rate, sig, carrierFreq, cfRamp, carrierLvl, clRamp, 
        modulatorRatio, mrRamp, modulatorIndex, miRamp, outputAmplitude, oaRamp;
 
        period = period * 600 + 100;
 
        // Calculation of a recursive working metronome (Impulse.kr) that generates its 
        // changing frequency out of its own impulses.
        change = Impulse.kr(LocalIn.kr(1,10));
        rate = CoinGate.kr(1/3, change);
        rate = (TChoose.kr(rate, period/((0..1) + 1))/1000).reciprocal; 
        LocalOut.kr(rate);
 
        # carrierFreq, cfRamp = TIRand.kr(0, [1000, 1], change);
        carrierFreq = Ramp.kr( carrierFreq / 1000, (cfRamp * period) / 1000 ) * 0.6;
 
        # carrierLvl, clRamp = TIRand.kr(0, [9000, 1], CoinGate.kr(1/3, change));
        carrierLvl = Ramp.kr( carrierLvl, (clRamp * period) / 1000) + 100;
 
        # modulatorRatio, mrRamp = TIRand.kr([800,1], CoinGate.kr(1/4, change));
        modulatorRatio = Ramp.kr(modulatorRatio, (mrRamp * period) / 1000) + 20;
 
        # modulatorIndex, miRamp = TIRand.kr(0, [100, 1], CoinGate.kr(1/4, change));
        modulatorIndex = Ramp.kr(modulatorIndex / 200, (miRamp * period) / 1000) + 0.2;
 
        # outputAmplitude, oaRamp = TIRand.kr(0!2, 1!2, CoinGate.kr(1/2, change));
        outputAmplitude = Ramp.kr(outputAmplitude, (oaRamp * period + 3) / 1000);
 
        // jointed FM Synthesizer 
        sig = LFSaw.ar(carrierFreq, 1, 0.5, 0.5) * carrierLvl;
        sig = sig + SinOsc.ar(carrierFreq * modulatorRatio) * modulatorIndex;
        sig = cos(sig * 2pi) * outputAmplitude;
 
        // One pole filters:
        sig = OnePole.ar(sig, exp(-2pi * (10000 * SampleDur.ir)));
        sig = OnePole.ar(sig, exp(-2pi * (10000 * SampleDur.ir)));
        sig = (sig - OnePole.ar(sig, exp(-2pi * (100 * SampleDur.ir))));
        sig = (sig - OnePole.ar(sig, exp(-2pi * (100 * SampleDur.ir))));
        sig = sig!2 * 0.06;     
}.play;
)
 
// period controls the talk-speed. range: 0-1. 0 matches to fast, 1 to slow:
w.set(\period, 1);
w.set(\period, 0);
w.set(\period, 0.5);
w.set(\period, 0.7);
w.set(\period, 0.3);
 
// To stop:
w.free;



//*********************************************
// Fig 57.2: FM synthesiser for computer noises

(
SynthDef(\fmSynth, { |carrierFreq=100, carrierLvl=0.5, modulatorRatio=5, modulatorIndex=1.5, outputAmp=0.2, sig, out=0|
 
        // the simple FM core
        sig = LFSaw.ar(carrierFreq, 1, 0.5, 0.5) * carrierLvl;
        sig = sig + SinOsc.ar(carrierFreq * modulatorRatio) * modulatorIndex;
        sig = cos( sig * 2pi) * outputAmp * 0.06;
        Out.ar(out, sig);
},1!5).add;
)
 
// At first start the synth:
g = Synth(\fmSynth);
 
// Play with the parameters:
g.set(\carrierFreq, 800);
g.set(\carrierFreq, 50);
g.set(\carrierFreq, 100, \modulatorRatio, 5, \modulatorIndex, 0.5);
g.set(\carrierFreq, 40, \modulatorRatio, 7, \modulatorIndex, 1.5);
g.set(\carrierFreq, 955, \carrierLvl, 0.4, \modulatorRatio, 3, \modulatorIndex, 4);
// ... etc.
 
// To stop:
g.free;

// code also available here: 
// http://en.wikibooks.org/wiki/Designing_Sound_in_SuperCollider/R2D2
raw 3432 chars (focus & ctrl+a+c to copy)
comments