-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsh-improElectronics_main.scd
374 lines (265 loc) · 10.1 KB
/
rsh-improElectronics_main.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
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
// rsh-improElectronics
// This is the main file for performing live.
// Make sure to follow the order of execution within this file and "rsh-improElectronics_setup". The setup starts in the setup file
// Note that some lines are out commented. They are often alternatives that one can also use/modify.
// Expressions like "B-B-7" are named like this: First letter A or B indicating the MIDI Layer. Second one tells if top (T) or bottom (B) row. Last numbers tells you which column exactly.
// #2: ... then choose and run your desired instruments and go back to the setup file, search for "#3:" ...
(
// Horizontal reflection. Shifts your live-input by ~shift
~shift = -0.5.midiratio;
Ndef(\horizontalReflection, {
var input, buffer, sig;
input = SoundIn.ar(0);
input = HPF.ar(input, freq: 30);
buffer = RecordBuf.ar(input, ~b_shift.bufnum, loop: 1);
sig = PlayBuf.ar(
numChannels: 1,
bufnum: buffer,
rate: ~shift,
loop: 1
);
sig = sig * 0.dbamp * ~mainVol.kr(1);
sig = PanX.ar(~numChannels, sig, pos: LFNoise2.kr(~panFreq.kr(1)).range(0.0, 1.0));
sig = Limiter.ar(sig, 1.0);
Out.ar(\delBus.kr, sig * 0.4 * EnvGate.new);
Out.ar(\revBus.kr, sig * 1.0 * EnvGate.new);
sig * EnvGate.new
}).set(\delBus, ~delBus, \revBus, ~revBus).play(out: ~outBus, group: ~defaultGroup).fadeTime_(0.02);
// Constant rebuilding to vanish clicks
Tdef(\rebuild, {
var loopOffset = ((~b_shift.duration / (1 - ~shift)) / 2);
loop({
Ndef(\horizontalReflection).rebuild;
loopOffset.wait;
});
}).play;
)
Ndef(\horizontalReflection).free;
(
// Frequency scrambling. Randomly swaps frequency bins of your live input with every new trigger.
Ndef(\frequencyScrambling, {
arg fftSize = 2048;
var input, chain;
input = SoundIn.ar(~input2);
input = HPF.ar(input, freq: 30);
chain = FFT(LocalBuf(fftSize, 1), input);
chain = PV_BinScramble(
chain,
wipe: 0.5,
width: 0.6,
// trig: Dust.kr(10)
trig: { InTrig.kr(~trigBus) } // Push A-T-1 to trigger a new random order.
);
chain = IFFT(chain);
chain = chain * -3.dbamp * ~mainVol.kr(1);
chain = PanX.ar(~numChannels, chain, pos: LFNoise2.kr(~panFreq.kr(1)).range(0.0, 1.0));
chain = Limiter.ar(chain, 1.0);
Out.ar(\delBus.kr, chain * 0.3 * EnvGate.new);
Out.ar(\revBus.kr, chain * 1.0 * EnvGate.new);
chain * EnvGate.new;
}).set(\delBus, ~delBus, \revBus, ~revBus).play(out: ~outBus, group: ~defaultGroup).fadeTime_(~ndefFadeTime);
)
Ndef(\frequencyScrambling).free;
(
// Spectral enhancement. Enriches your live input with additional partials.
Ndef(\spectralEnhancement, {
arg fftSize = 2048, amp = 2.0;
var input, chain;
input = SoundIn.ar(~input3);
input = HPF.ar(input, freq: 30);
chain = FFT(LocalBuf(fftSize, 1), input);
chain = PV_SpectralEnhance(
chain,
numPartials: 16,
// numPartials: LFNoise0.kr(1).curverange(1, 32, 5),
// ratio: 1.5,
ratio: ~ratioBus.kr(1), // Use MIDI encoder A-7. Watch out: When ratio is going below 1.0 this will get you into a spectral panic attack.
// ratio: Phasor.kr(Dust.kr(0.1), rate: 1, start: 1, end: LFNoise2.kr(0.1).range(1.0, 5.5), resetPos: 1.0),
strength: 1.0
);
chain = IFFT(chain);
chain = chain * -6.dbamp * ~mainVol.kr(1);
chain = PanX.ar(~numChannels, chain, pos: LFNoise2.kr(~panFreq.kr(1)).range(0.0, 1.0), level: amp);
chain = Limiter.ar(chain, 1.0);
Out.ar(\delBus.kr, chain * 0.3 * EnvGate.new);
Out.ar(\revBus.kr, chain * 0.8 * EnvGate.new);
chain * EnvGate.new;
}).set(\delBus, ~delBus, \revBus, ~revBus).play(out: ~outBus, group: ~defaultGroup).fadeTime_(~ndefFadeTime);
)
Ndef(\spectralEnhancement).free;
(
// Granulation with pitch shifting
// Use custom grain envelope
var winenv = Env([0, 1, 0], [0.5, 0.5], [8, -8]);
var grainEnv = Buffer.sendCollection(s, winenv.discretize, 1);
Ndef(\granulation, {
arg gate = 1;
var input, env, sig;
input = SoundIn.ar(~input2);
input = HPF.ar(input, freq: 30);
RecordBuf.ar(input, ~b_gran, loop: 1, doneAction: 0);
env = EnvGen.kr(Env.asr, gate, doneAction: 2);
sig = GrainBuf.ar(
trigger: Impulse.kr(8),
dur: 0.2,
sndbuf: ~b_gran.bufnum,
// rate: LFNoise0.kr(10).range(-0.5.midiratio, 0.5.midiratio),
rate: Demand.kr(
trig: Dust.kr(9),
reset: 0,
demandUGens: Dwrand(
// list: [LFNoise0.kr(5).range(-1.midiratio, 1.0), 1, LFNoise0.kr(5).range(1, 1.midiratio)], // Clusters
list: [-7.midiratio, 1, 7.midiratio], // Fifths
// list: [-0.5.midiratio, 1, 0.5.midiratio], // quarter-tones
weights: [0.05, 0.9, 0.05],
repeats: inf
)
),
interp: 4,
envbufnum: grainEnv // choose grainEnv or -1 for built-in grain envelope
);
sig = sig * env * ~mainVol.kr(1);
sig = PanX.ar(~numChannels, sig, pos: LFNoise2.kr(~panFreq.kr(1)).range(0.0, 1.0), level: -2.dbamp);
sig = Limiter.ar(sig, 1.0);
Out.ar(\delBus.kr, sig * 0.0 * EnvGate.new);
Out.ar(\revBus.kr, sig * 1.0 * EnvGate.new);
sig * EnvGate.new;
}).set(\delBus, ~delBus, \revBus, ~revBus).play(out: ~outBus, group: ~defaultGroup).fadeTime_(~ndefFadeTime);
)
Ndef(\granulation).free;
(
// Interpolate the spectra between input A and B
Ndef(\spectrumInterpolation, {
arg amp = 1;
var inputA, inputB, sig;
// choose from ~sourceWater, ~sourceFire, ~sourceBirds
inputA = PlayBuf.ar(1, ~sourceBirds.bufnum, loop: 1);
// inputA = SoundIn.ar(~input1);
inputB = SoundIn.ar(~input2);
// sig = FluidAudioTransport.ar(inputA, inputB, 0.95);
// sig = FluidAudioTransport.ar(inputA, inputB, MouseX.kr(0, 1));
sig = FluidAudioTransport.ar(inputA, inputB, ~interpolBus.kr(1)); // Use MIDI encoder A-8
sig = sig * -2.dbamp * ~mainVol.kr(1);
sig = PanX.ar(~numChannels, sig, pos: LFNoise2.kr(~panFreq.kr(1)).range(0.0, 1.0), level: amp);
sig = Limiter.ar(sig, 1.0);
Out.ar(\delBus.kr, sig * 0.1 * EnvGate.new);
Out.ar(\revBus.kr, sig * 0.4 * EnvGate.new);
sig * EnvGate.new;
}).set(\delBus, ~delBus, \revBus, ~revBus).play(out: ~outBus, group: ~defaultGroup).fadeTime_(~ndefFadeTime);
)
Ndef(\spectrumInterpolation).free;
(
// Template for basic reverb & delay
Ndef(\template, {
var input, sig;
input = SoundIn.ar(~input4);
sig = HPF.ar(input, freq: 30);
sig = sig * 0.dbamp * ~mainVol.kr(1);
sig = PanX.ar(~numChannels, sig, pos: LFNoise2.kr(~panFreq.kr(1)).range(0.0, 1.0));
sig = Limiter.ar(sig, 1.0);
Out.ar(\delBus.kr, sig * 0.0 * EnvGate.new);
Out.ar(\revBus.kr, sig * 1.0 * EnvGate.new);
sig * EnvGate.new;
}).set(\delBus, ~delBus, \revBus, ~revBus).play(out: ~outBus, group: ~defaultGroup).fadeTime_(~ndefFadeTime);
)
Ndef(\template).free;
// Sample Playback
// Fire up via buttons on Layer B...
// Order of MIDI-assignment starting at B-T-1:
// Top: #1 Finnegans Sake, #2 Berge, #3 Trumpet, #4 Signature
// Control each volume with MIDI encoder B-1 to B-4
// Of course you can use your own samples by adding them into the "buffers" folder before you adjust the corresponding code
// In case of complications free what you need to free:
Node.basicNew(s, 1036).free;
// Source-Target-Resynthesis with optional live-recording-playback
// Please evaluate the block below to start via MIDI on A-B-1 to A-B-4
(
// #1: Record some live input for x seconds and free it
~dur = 4; // x seconds
~recording = {
Tdef(\strRecording, {
~target = Buffer.alloc(s, s.sampleRate * ~dur, numChannels: 1);
1.do({
(~recorder = SynthDef(\recorder, {
arg bufnum;
var input;
input = SoundIn.ar(~input1);
input = HPF.ar(input, freq: 70);
RecordBuf.ar(input, bufnum, recLevel: 1.0, preLevel: 0.0, doneAction: 2);
}).play(s, [\bufnum, ~target]);
)});
(~dur + 0.1).wait;
~recorder.free;
"ready for playback/resynthesis!".postln
}).play;
};
// #2 If wanted: play it back
~recPlayBack = {
SynthDef(\playBack, {
arg bufnum, amp;
var sig, env;
env = Env([0, 1, 1, 0], [0.2, ~dur-0.3, 0.1], 'sin').kr(2);
sig = PlayBuf.ar(1, bufnum, doneAction: 2);
sig = sig * ~mainVol.kr(1);
sig = PanX.ar(~numChannels, sig * env, pos: LFNoise2.kr(~panFreq.kr(1)).range(0.0, 1.0), level: amp);
sig = Limiter.ar(sig, 1);
Out.ar(\outBus.kr, sig);
}).play(s, [\bufnum, ~target, \amp, -2.dbamp, \outBus, ~outBus]);
};
// #3 Resynthesise the target sound based on the source sound. Wait some time...
~resynthesis = {
Routine{
~crossSynthesis = FluidBufNMFCross.process(
s,
~sourceWater, // choose from ~sourceWater, ~sourceFire, ~sourceBirds
~target,
~output,
timeSparsity: 4,
polyphony: 7,
continuity: 20,
windowSize: 2048
);
{ FreeSelfWhenDone.kr(~crossSynthesis.kr).poll }.play;
~crossSynthesis.wait;
"Resynthesis done".postln;
}.play;
};
// #4 fire up!
~resynthesisPlayback = {
~mainVol.set(1); // For unknown reasons FluidBufNMFCross sets the ~mainVol bus to 0 after performing the ~resynthesis.
SynthDef(\strPlayBack, {
arg bufnum, amp;
var sig, env;
env = Env([0, 1, 1, 0], [0.2, ~dur-0.4, 0.2], 'sin').kr(2);
sig = PlayBuf.ar(1, bufnum, doneAction: 2);
sig = sig * ~mainVol.kr(1);
sig = PanX.ar(~numChannels, sig * env, pos: LFNoise2.kr(~panFreq.kr(1)).range(0.0, 1.0), level: amp);
sig = Limiter.ar(sig, 1);
Out.ar(\outBus.kr, sig);
}).play(s, [\bufnum, ~output, \amp, 1, \outBus, ~outBus]);
};
)
(
// Pulsar synthesis!
// Based on Alberto de Campos approach in chapter 16, p. 487 - 488 of the SuperCollider book (MIT press, 2011)
// Code taken from here: https://github.com/madskjeldgaard/scbookcode/blob/master/Ch%2016%20Microsound/c16_micro_figures5_pulsar.scd
// Please follow the notes in the _readMe.txt.
// Input Touch OSC data first, then evaluate:
Ndef(\pulsar, {
arg waveBuf, envBuf = -1;
var fundFreq, formFreq, trig, grDur, rate, sig;
fundFreq = ~fundFreqBus.kr(1).lag(0.01);
// fundFreq = MouseX.kr(1, 3000.0, 1);
formFreq = ~formFreqBus.kr(1).lag(0.01);
// formFreq = MouseY.kr(1, 10000.0, 1);
// trig = Impulse.ar(fundFreq * Duty.kr(dur: LFNoise0.kr(15).range(0.01, 0.05), level: Dseq([1, 0, 1, 1, 0, 0, 1, 0], inf))); // masking
trig = Impulse.ar(fundFreq);
grDur = formFreq.reciprocal;
rate = formFreq * BufDur.kr(waveBuf);
sig = GrainBuf.ar(1, trig, grDur, waveBuf, rate, 0, 4, envbufnum: envBuf);
sig = sig * -12.dbamp * ~mainVol.kr(1);
sig = PanX.ar(~numChannels, sig, pos: LFNoise2.kr(~panFreq.kr(1)).range(0.0, 1.0), level: ~pulsarVolBus.kr(1));
sig = Limiter.ar(sig, 1);
}).play(out: ~outBus, group: ~defaultGroup);
)
Ndef(\pulsar).free;