/
ixi_SC_tutorial_12.sc
1413 lines (991 loc) · 32.5 KB
/
ixi_SC_tutorial_12.sc
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// =====================================================================
// - SuperCollider Basics -
// =====================================================================
// Tutorial 12 - Audio Effects
// =====================================================================
// - ixi audio tutorial - www.ixi-audio.net
// =====================================================================
/*
---------------------------------------------------------------
Copyright (c) 2005-2008, ixi audio.
This work is licensed under a Creative Commons
Attribution-NonCommercial-ShareAlike 2.0 England & Wales License.
http://creativecommons.org/licenses/by-nc-sa/2.0/uk/
---------------------------------------------------------------
*/
// ========== Contents of this tutorial ==========
// 1) Delays
// 2) Phaser (Phase Shifting)
// 3) Flanger
// 4) Chorus
// 5) Reverb
// 6) Tremolo
// 7) Distortion
// 8) Compressor
// 9) Limiter
// 10) Sustainer
// 11) Noise gate
// 12) Normalizer
// 13) Limiter (Ugen)
// 14) Amplitude
// 15) Pitch
// 16) Filters
// 17) Making Audio Unit plugins
// 1) ========= Delays ==========
/*
Delays come with different functionalities. In SC there are 3 main types of delays,
(Delay, Comb and Allpass)
- DelayN/DelayL/DelayC are simple echos with no feedback.
- CombN/CombL/CombC are comb delays with feedback (decaytime)
- AllpassN/AllpassL/AllpassC die out faster than the comb, and have feedback as well
Delays can have fixed delay time and generate different effects according to delay time:
Short ( < 10 ms)
Medium ( 10 - 50 ms)
Long ( > 50 ms)
A short delay (1-2 samples) can create a FIR lowpass filter.
Increase the delay time (1-10 ms) and a comb filter appears.
Medium delays result in thin signal but also an ambience and width in the sound.
Long delays create discrete echos which imitates sound bouncing of hard walls.
Delays can also have variable delay time which can result in the following effects:
Phase Shifting
Flanging
Chorus
These effects are explained in dedicated sections here below
*/
// load some sound files into buffers (use your own)
(
d = Buffer.read(s,"sounds/digireedoo.aif");
e = Buffer.read(s,"sounds/holeMONO.aif");
e = Buffer.read(s, "sounds/a11wlk01.wav"); // this one is in SC sounds folder
)
// -------------------- a) Short delays
// DelayL is a simple delay line without decay time arguments
// let's play with it (impulse in left ear, delayed signal in the right)
// and mouseX controlling the delay time
(
{
var signal;
var delaytime = MouseX.kr(0.001,0.2, 1);
signal = Impulse.ar(1); // the sound source
d = DelayL.ar(signal, 0.6, delaytime);
[d, signal]
}.play
)
// now what happens if we add two signals where one has a short delay ( < 10 ms)
// - we get a lowpass filter.
// NOTE: 0.000022675 is roughly the same as 1/44100 or 44100.reciprocal
(
{
var signal;
var delaytime = MouseX.kr(0.000022675, 0.01); // from a sample to 10 ms
signal = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
d = DelayN.ar(signal, 0.6, delaytime); // try replacing with CombN (with 0 decayTime)
(signal + d).dup
}.play
)
// We have replaced DelayN with CombN and use mouseY for decayTime ( < 10 ms)
(
{
var signal;
var delaytime = MouseX.kr(0.00022675,0.01, 1); // NOTE: sample is too short here - it explodes!
signal = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
d = CombC.ar(signal, 0.6, delaytime, MouseY.kr(0.001,1, 1));
(signal + d).dup
}.play
)
(
{
var signal;
var delaytime = MouseX.kr(0.1,0.4, 1);
signal = Impulse.ar(1);
// delaying the impulse with 4 delays
d = DelayL.ar(signal, 0.6, delaytime);
e = DelayL.ar(signal, 0.6, delaytime*1.1);
f = DelayL.ar(signal, 0.6, delaytime*1.2);
g = DelayL.ar(signal, 0.6, delaytime*1.3);
(d+e+f+g).dup
}.play
)
// karplus gone really wrong - no decay, just a line of 10 delays
(
{
var signal;
var delaytime = MouseX.kr(0.01,2, 1);
signal = Impulse.ar(MouseY.kr(0.5, 2));
a = Mix.fill(10, {arg i; DelayL.ar(signal, 2, delaytime*(i/10+1));});
(a).dup
}.play
)
// Comb and Allpass have decaytime arguments
// the old Karplus-Strong
(
{
var signal;
var delaytime = MouseX.kr(0.001,0.2, 1);
var decaytime = MouseY.kr(0.1,2, 1);
signal = Impulse.ar(1);
d = CombL.ar(signal, 0.6, delaytime, decaytime);
d!2
}.play(s)
)
// compare the Comb and the Allpass
(
{ // use the mouse !!!
var signal;
var delaytime = MouseX.kr(0.001,0.2, 1);
var decaytime = MouseY.kr(0.1,2, 1);
signal = Impulse.ar(1);
d = AllpassC.ar(signal, 0.6, delaytime, decaytime);
d!2
}.play
)
// and we add the good old Decay with WhiteNoise as the source
(
{ // use the mouse !!!
var signal;
var delaytime = MouseX.kr(0.001,0.2, 1);
var decaytime = MouseY.kr(0.1,2, 1);
signal = Decay.ar(Impulse.ar(1), 0.3, WhiteNoise.ar * 0.3, 0);
d = CombL.ar(signal, 0.6, delaytime, decaytime);
d!2
}.play(s)
)
// -------------------- b) Medium delays ( 10 - 50 ms)
f = Buffer.read(s, "sounds/a11wlk01.wav");
// try out the following different delays (uncomment)
// the signals are not added (the dry and wet)
(
{
var signal;
var delaytime = MouseX.kr(0.01,0.05); // between 10 and 50 ms.
signal = PlayBuf.ar(1, f.bufnum, BufRateScale.kr(f.bufnum), loop:1);
// compare DelayL, CombL and AllpassL
//d = DelayL.ar(signal, 0.6, delaytime);
//d = CombL.ar(signal, 0.6, delaytime, MouseY.kr(1,4));
d = AllpassL.ar(signal, 0.6, delaytime, MouseY.kr(1,4));
[signal, d] // dry signal in left channel, delay in the right
}.play(s)
)
// same as above, but here we add the signals
(
{
var signal;
var delaytime = MouseX.kr(0.01,0.05); // between 10 and 50 ms.
signal = PlayBuf.ar(1, f.bufnum, BufRateScale.kr(f.bufnum), loop:1);
// compare DelayL, CombL and AllpassL
//d = DelayL.ar(signal, 0.6, delaytime);
//d = CombL.ar(signal, 0.6, delaytime, MouseY.kr(0.001,4));
d = AllpassL.ar(signal, 0.6, delaytime, MouseY.kr(0.001,4));
(signal+d).dup
}.play(s)
)
// same as above, here using AudioIn for the signal
(
{
var signal;
var delaytime = MouseX.kr(0.01,0.05);
signal = AudioIn.ar(1);
// compare DelayL, CombL and AllpassL
//d = DelayL.ar(signal, 0.6, delaytime);
d = CombL.ar(signal, 0.6, delaytime, MouseY.kr(0.001,4));
//d = AllpassL.ar(signal, 0.6, delaytime, MouseY.kr(0.001,4));
(signal+d).dup
}.play(s)
)
// -------------------- c) Longer delays ( > 50 ms)
(
{
var signal;
var delaytime = MouseX.kr(0.05, 2, 1); // between 50 ms and 2 seconds - exponential.
signal = PlayBuf.ar(1, f.bufnum, BufRateScale.kr(f.bufnum), loop:1);
// compare DelayL, CombL and AllpassL
//d = DelayL.ar(signal, 0.6, delaytime);
//d = CombL.ar(signal, 0.6, delaytime, MouseY.kr(0.1, 10, 1)); // decay using mouseY
d = AllpassL.ar(signal, 0.6, delaytime, MouseY.kr(0.1,10, 1));
(signal+d).dup
}.play(s)
)
// same as above, here using AudioIn for the signal instead of the NASA irritation
(
{
var signal;
var delaytime = MouseX.kr(0.05, 2, 1); // between 50 ms and 2 seconds - exponential.
signal = AudioIn.ar(1);
// compare DelayL, CombL and AllpassL
//d = DelayL.ar(signal, 0.6, delaytime);
//d = CombL.ar(signal, 0.6, delaytime, MouseY.kr(0.1, 10, 1)); // decay using mouseY
d = AllpassL.ar(signal, 0.6, delaytime, MouseY.kr(0.1,10, 1));
(signal+d).dup
}.play(s)
)
// -------------------- d) Random experiments
//
Server.default = s = Server.internal
FreqScope.new;
{CombL.ar(Impulse.ar(10), 6, 1, 1)}.play(s)
(
{
var signal;
var delaytime = MouseX.kr(0.01,6, 1);
var decaytime = MouseY.kr(1,2, 1);
signal = Impulse.ar(1);
d = CombL.ar(signal, 6, delaytime, decaytime);
d!2
}.play(s)
)
// we can see the Comb effect by plotting the signal.
(
{
a = Impulse.ar(1);
d = CombL.ar(a, 1, 0.001, 0.9);
d
}.plot(0.1)
)
// a little play with AudioIn
(
{
var signal;
var delaytime = MouseX.kr(0.001,2, 1);
signal = AudioIn.ar(1);
a = Mix.fill(10, {arg i; var dt;
dt = delaytime*(i/10+0.1).postln;
DelayL.ar(signal, 3.2, dt);});
(signal+a).dup
}.play(s)
)
/*
TIP: if you get this line printed ad infinitum:
exception in real time: alloc failed
You could go into the ServerOptions.sc (source file) and change
var <>memSize = 8192;
to
var <>memSize = 32768;
which allows the server to use up more memory (RAM)
*/
(
{ // watch your ears !!! Use headphones and lower the volume !!!
var signal;
var delaytime = MouseX.kr(0.001,2, 1);
signal = AudioIn.ar(1);
a = Mix.fill(13, {arg i; var dt;
dt = delaytime*(i/10+0.1).postln;
CombL.ar(signal, 3.2, dt);});
(signal+a).dup
}.play(s)
)
// A source code for a Comb filter might look something like this:
int i, j, s;
for(i=0; i <= delay_size;i++)
{ if (i >= delay)
j = i - delay; // work out the buffer position
else
j = i - delay + delay_size + 1;
// add the delayed sample to the input sample
s = input + delay_buffer[j]*decay;
// store the result in the delay buffer, and output
delay_buffer[i] = s;
output = s;
}
// 2) ========= Phaser (phase shifting) ==========
/*
In a Phaser, a signal is sent through an allpass filter, not filtering anything out,
but just shifting the phase of the sound by delaying it. This sound is then added to
the original signal. If the phase is 180 degrees, the sound is cancelled out, but if
it is less than that, it will create variations in the spectra.
*/
// phaser with a soundfile
e = Buffer.read(s, "sounds/a11wlk01.wav");
(
{
var signal;
var phase = MouseX.kr(0.000022675,0.01, 1); // from a sample resolution to 10 ms delay line
var ph;
signal = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
ph = AllpassL.ar(PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1), 4, phase+(0.01.rand), 0);
/* // try 4 phasers
ph = Mix.ar(Array.fill(4,
{ AllpassL.ar(PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1), 4, phase+(0.01.rand), 0)}
));
*/
(signal + ph).dup
}.play
)
// try it with a sinewave (the mouse is shifting the phase of the input signal
(
{
var signal;
var phase = MouseX.kr(0.000022675,0.01); // from a sample to 10 ms delay line
var ph;
signal = SinOsc.ar(444,0,0.5);
//signal = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
ph = AllpassL.ar(SinOsc.ar(444,0,0.5), 4, phase, 0);
(signal + ph).dup
}.play
)
// using an oscillator to control the phase instead of MouseX
// here using the .range trick:
{SinOsc.ar(SinOsc.ar(0.3).range(440, 660), 0, 0.5) }.play
(
{
var signal;
var ph;
// base signal
signal = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
// phased signal
ph = AllpassC.ar(
PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1),
4,
LFPar.kr(0.1, 0, 1).range(0.000022675,0.01), // a circle every 10 seconds
0); // experiment with what happens if you increase the decay length
(signal + ph).dup // we add them together and route to two speakers
}.play
)
/*
NOTE: Theoretically you could use DelayC or CombC instead of AllpassC.
In the case of DelayC, you would have to delete the last argument (0)
(as DelayC doesn't have decay argument).
*/
// 3) ========= Flanger ==========
/*
In a Flanger, a delayed signal is added to the original signal with a continuously-variable delay (usually smaller than 10 ms) creating a phasing effect. The term comes from times where tapes were used in studios and an operator would place the finger on the flange of one of the tapes to slow it down, thus causing the flanging effect.
Flanger is like a Phaser with dynamic delay filter (allpass), but usually it has a feedback loop.
*/
(
SynthDef(\flanger, { arg out=0, in=0, delay=0.1, depth=0.08, rate=0.06, fdbk=0.0, decay=0.0;
var input, maxdelay, maxrate, dsig, mixed, local;
maxdelay = 0.013;
maxrate = 10.0;
input = In.ar(in, 1);
local = LocalIn.ar(1);
dsig = AllpassL.ar( // the delay (you could use AllpassC (put 0 in decay))
input + (local * fdbk),
maxdelay * 2,
LFPar.kr( // very similar to SinOsc (try to replace it) - Even use LFTri
rate * maxrate,
0,
depth * maxdelay,
delay * maxdelay),
decay);
mixed = input + dsig;
LocalOut.ar(mixed);
Out.ar([out, out+1], mixed);
}).load(s);
)
// audioIn on audio bus nr 10
{Out.ar(10, AudioIn.ar(1))}.play(s, addAction:\addToHead)
a = Synth(\flanger, [\in, 10], addAction:\addToTail)
a.set(\delay, 0.04)
a.set(\depth, 0.04)
a.set(\rate, 0.01)
a.set(\fdbk, 0.08)
a.set(\decay, 0.01)
// or if you prefer a buffer:
b = Buffer.read(s, "sounds/a11wlk01.wav"); // replace this sound with a nice sounding one !!!
{Out.ar(10, PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum), loop:1))}.play(addAction:\addToHead)
a = Synth(\flanger, [\in, 10], addAction:\addToTail)
a.set(\delay, 0.04)
a.set(\depth, 0.04)
a.set(\rate, 1)
a.set(\fdbk, 0.08)
a.set(\decay, 0.01)
// a parameter explosion results in a Chorus like effect:
a.set(\decay, 0)
a.set(\delay, 0.43)
a.set(\depth, 0.2)
a.set(\rate, 0.1)
a.set(\fdbk, 0.08)
// or just go mad:
a.set(\delay, 0.93)
a.set(\depth, 0.9)
a.set(\rate, 0.8)
a.set(\fdbk, 0.8)
// 4) ========= Chorus ==========
/*
The chorus effect happens when we add a delayed signal with the original with a time-varying delay.
The delay has to be short in order not to be perceived as echo, but above 5 ms to be audible. If the
delay is too short, it will destructively interfere with the un-delayed signal and create a flanging
effect. Often, the delayed signals will be pitch shifted to create a harmony with the original signal.
There is no definite algorithm to create a chorus. There are many different ways to achieve it.
As opposed to the Flanger above, this Chorus does not have a feedback loop. But you could create a
chorus effect out of a Flanger by using longer delay time (20-30 ms instead of 1-10 ms in Flanger)
*/
// a simple chorus
SynthDef(\chorus, { arg inbus=10, outbus=0, predelay=0.08, speed=0.05, depth=0.1, ph_diff=0.5;
var in, sig, modulators, numDelays = 12;
in = In.ar(inbus, 1);
modulators = Array.fill(numDelays, {arg i;
ÊÊÊÊÊÊ LFPar.kr(speed * rrand(0.94, 1.06), ph_diff * i, depth, predelay);});Ê
sig = DelayC.ar(in, 0.5, modulators);ÊÊ
sig = sig.sum; //Mix(sig);
Out.ar(outbus, sig!2); // output in stereo
}).load(s)
// try it with audio in
{Out.ar(10, AudioIn.ar(1))}.play(addAction:\addToHead)
// or a buffer:
b = Buffer.read(s, "sounds/a11wlk01.wav"); // replace this sound with a nice sounding one !!!
{Out.ar(10, PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum), loop:1))}.play(addAction:\addToHead)
a = Synth(\chorus, addAction:\addToTail)
a.set(\predelay, 0.02);
a.set(\speed, 0.22);
a.set(\depth, 0.5);
a.set(\pd_diff, 0.7);
a.set(\predelay, 0.2);
// 5) ========= Reverb ==========
/*
Achieving realistic reverb is a science on its own, to deep to delve into here.
The most common reverb technique in digital acoustics is to use parallel comb delays
that are fed into few Allpass delays.
Reverb can be analysed into 3 stages:
Direct sound (from the soundsource)
Early reflections (discrete 1st generation reflections from walls)
Reverberation (Nth generation reflections that take time to build up, and fade out slowly)
*/
SynthDef(\reverb, {arg inbus=0, outbus=0, predelay=0.048, combdecay=15, allpassdecay=1, revVol=0.31;
var sig, y, z;
sig = In.ar(inbus, 1);
// predelay
z = DelayN.ar(sig, 0.1, predelay); // max 100 ms predelay
// 7 length modulated comb delays in parallel :
y = Mix.ar(Array.fill(7,{ CombL.ar(z, 0.05, rrand(0.03, 0.05), combdecay) }));
6.do({ y = AllpassN.ar(y, 0.050, rrand(0.03, 0.05), allpassdecay) });
Out.ar(outbus, sig + (y * revVol) ! 2); // as fxlevel is 1 then I lower the vol a bit
}).load(s);
{Out.ar(10, AudioIn.ar(1))}.play(addAction:\addToHead)
b = Buffer.read(s, "sounds/a11wlk01.wav"); // replace this sound with a nice sounding one !!!
{Out.ar(10, PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum), loop:1))}.play(addAction:\addToHead)
a = Synth(\reverb, [\inbus, 10], addAction:\addToTail)
a.set(\predelay, 0.048)
a.set(\combdecay, 2.048)
a.set(\allpassdecay, 1.048)
a.set(\revVol, 0.048)
// 6) ========= Tremolo ==========
/*
Tremolo is fluctuating amplitude of a signal
*/
SynthDef(\tremolo, {arg inbus=0, outbus=0, freq=1, strength=1;
Ê Êvar fx, sig;
Ê Êsig = In.ar(inbus, 1);
Ê Êfx = sig * SinOsc.ar(freq, 0, strength, 0.5, 2);
Ê ÊOut.ar(outbus, (fx+ sig).dup )
}).load(s);
{Out.ar(10, AudioIn.ar(1))}.play(addAction:\addToHead)
b = Buffer.read(s, "sounds/a11wlk01.wav"); // replace this sound with a nice sounding one !!!
{Out.ar(10, PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum), loop:1))}.play(addAction:\addToHead)
a = Synth(\tremolo, [\inbus, 10], addAction:\addToTail)
a.set(\freq, 4.8)
a.set(\strength, 0.8)
// 7) ========= Distortion ==========
// use headphones!
(
{
var in, gain;
in = AudioIn.ar(1);
gain = MouseX.kr(1,100);
in=in.abs;
((in.squared + (gain*in))/(in.squared + ((gain-1)*in) + 1))
!2}.play
)
(
{ // mouseX is pregain, mouseY is postgain
var in, distortion, fx, y, z;
in = AudioIn.ar(1);
distortion = ((in * MouseX.kr(1,10)).distort * MouseY.kr(1,10)).distort;
fx = Compander.ar(distortion, distortion, 1, 0, 1 ); // sustain
Out.ar(0, LeakDC.ar(fx + in ) !2 );
}.play
)
// Here not using AudioIN:
b = Buffer.read(s, "sounds/a11wlk01.wav"); // replace this sound with a nice sounding one !!!
{Out.ar(10, PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum), loop:1))}.play(addAction:\addToHead)
(
{ // mouseX is pregain, mouseY is postgain
var in, distortion, fx, y, z;
in = In.ar(10);
distortion = ((in * MouseX.kr(1,10)).distort * MouseY.kr(1,10)).distort;
fx = Compander.ar(distortion, distortion, 1, 0, 1 ); // sustain
Out.ar(0, LeakDC.ar(fx + in ) !2 );
}.play(addAction:\addToTail) // for addAction, see Synth helpfile or tutorial 13
)
// 8) ========= Compressor ==========
e = Buffer.read(s, "sounds/a11wlk01.wav");
/*
The compressor reduces the dynamic range of a signal if it exceeds certain threshold.
The compression ratio determines how much the signal that exceeds the threshold is turned
down. 4:1 compression ratio means that for every 4 dB of signal that goes into the unit,
it turns it down so that only 1 dB comes out.
*/
(
// compressor - Audio In
{
var in, compander;
in = AudioIn.ar(1);
compander = Compander.ar(in, in, MouseX.kr(0.001, 1, 1), 1, 0.5, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
(
// compressor - Soundfile
{
var in, compander;
in = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
compander = Compander.ar(in, in, MouseX.kr(0.0001, 1, 1), 1, 0.5, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
// 9) ========= Limiter ==========
/*
The limiter does essentially the same as the compressor, but it looks at the signal's
peaks whereas the compressor looks at the average energy level. A limiter will not let
the signal past the threshold, while the compressor does, according to the ratio settings.
The difference is in the slopeAbove argument of the Compander.
(0.5 in the compressor, but 0.1 in the limiter)
*/
(
// limiter - Audio In
{
var in, compander;
in = AudioIn.ar(1);
compander = Compander.ar(in, in, MouseX.kr(0.001, 1, 1), 1, 0.1, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
(
// limiter - Soundfile
{
var in, compander;
in = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
compander = Compander.ar(in, in, MouseX.kr(0.0001, 1, 1), 1, 0.1, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
// 10) ========= Sustainer ==========
/*
The sustainer works like an inverted compressor, it exaggerates the low amplitudes and
tries to raise them up to the threshold defined.
*/
(
// sustainer - Audio In
{
var in, compander;
in = AudioIn.ar(1);
compander = Compander.ar(in, in, MouseX.kr(0.001, 1, 1), 0.1, 1, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
(
// sustainer - Soundfile
{
var in, compander;
in = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
compander = Compander.ar(in, in, MouseX.kr(0.0001, 1, 1), 0.1, 1, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
// for comparison, here is the file without sustain:
{PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1)!2}.play
// 11) ========= Noise gate ==========
/*
The noise gate allows a signal to pass through the filter only when it is above a
certain threshold. If the energy of the signal is below the threshold, no sound is
allowed to pass. It is often used in settings where there is background noise and
one only wants to record the signal and not the (in this case) uninteresting noise.
*/
(
// noisegate - Audio In
{
var in, compander;
in = AudioIn.ar(1);
compander = Compander.ar(in, in, MouseX.kr(0.005, 1, 1), 10, 1, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
(
// noisegate - sound file
{
var in, compander;
in = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
compander = Compander.ar(in, in, MouseX.kr(0.001, 1), 10, 1, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
// The noise gate needs a bit of parameter tweeking to get what you want, so here is
// the same version as above, just with a MouseY controlling the slopeAbove parameter.
(
// noisegate - Audio In
{
var in, compander;
in = AudioIn.ar(1);
compander = Compander.ar(in, in, MouseX.kr(0.005, 1, 1), MouseY.kr(1,20), 1, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
(
// noisegate - soundfile
{
var in, compander;
in = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
compander = Compander.ar(in, in, MouseX.kr(0.001, 1), MouseY.kr(1,20), 1, 0.01, 0.01);
compander ! 2 // stereo
}.play
)
(
// for fun: a noisegater with a bit of reverb (controlled by mouseY)
// better use headphones - danger of feedback!
{
var in, compander;
var predelay=0.048, combdecay=3.7, allpassdecay=0.21, revVol=0.21;
in = AudioIn.ar(1);
compander = Compander.ar(in, in, MouseX.kr(0.005, 1, 1), 10, 1, 0.01, 0.01);
z = DelayN.ar(compander, 0.1, predelay);
y = Mix.ar(Array.fill(7,{ CombL.ar(z, 0.05, rrand(0.03, 0.05), MouseY.kr(1,20, 1)) }));
6.do({ y = AllpassN.ar(y, 0.050, rrand(0.03, 0.05), allpassdecay) });
y!2
}.play
)
// 12) ========= Normalizer ==========
/*
Normalizer uses a buffer to store the sound in a small delay and look ahead in the audio.
It will not overshoot like a Compander will, but the downside is the delay.
The normalizer normalizes the input amplitide to a given level.
*/
(
// normalizer - Audio In
{
var in, normalizer;
in = AudioIn.ar(1);
normalizer = Normalizer.ar(in, MouseX.kr(0.1, 0.9), 0.01);
normalizer ! 2 // stereo
}.play
)
(
// normalizer - sound file
{
var in, normalizer;
in = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
normalizer = Normalizer.ar(in, MouseX.kr(0.1, 0.9), 0.01);
normalizer ! 2 // stereo
}.play
)
// 13) ========= Limiter (ugen) ==========
/*
Limiter uses a buffer to store the sound in a small delay and look ahead in the audio.
It will not overshoot like a Compander will, but the downside is the delay.
The limiter limits the input amplitide to a given level
*/
(
// limiter - Audio In
{
var in, normalizer;
in = AudioIn.ar(1);
normalizer = Limiter.ar(in, MouseX.kr(0.1, 0.9), 0.01);
normalizer ! 2 // stereo
}.play
)
(
// limiter - sound file
{
var in, normalizer;
in = PlayBuf.ar(1, e.bufnum, BufRateScale.kr(e.bufnum), loop:1);
normalizer = Limiter.ar(in, MouseX.kr(0.1, 0.9), 0.01);
normalizer ! 2 // stereo
}.play
)
// 14) ========= Amplitude ==========
/*
Amplitude tracks the peak amplitude of a signal
*/
// mapping input amplitude to frequency of a sine
{SinOsc.ar(Amplitude.kr(AudioIn.ar(1), 0.1, 0.1, 12000, 0), 0, 0.3)}.play;
// with a noise gater as explained above
(
{
var noisegate, in;
in = AudioIn.ar(1);
noisegate = Compander.ar(in, in, MouseX.kr(0.005, 1, 1), MouseY.kr(1,20), 1, 0.01, 0.01);
SinOsc.ar(Amplitude.kr(noisegate, 0.1, 0.1, 12000, 0), 0, 0.3) ! 2
}.play;
)