forked from sonic-pi-net/sonic-pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynth-designs-incubator.clj
465 lines (394 loc) · 16.5 KB
/
synth-designs-incubator.clj
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
;;--
;; This file is part of Sonic Pi: http://sonic-pi.net
;; Full project source: https://github.com/samaaron/sonic-pi
;; License: https://github.com/samaaron/sonic-pi/blob/master/LICENSE.md
;;
;; Copyright 2013, 2014 by Sam Aaron (http://sam.aaron.name).
;; All rights reserved.
;;
;; Permission is granted for use, copying, modification, distribution,
;; and distribution of modified versions of this work as long as this
;; notice is included.
;;++
;; This file uses Overtone to compile the synths from Clojure to
;; SuperCollider compatible binary files. Overtone is Sonic Pi's big
;; brother. See: http://overtone.github.io
(ns sp
(:use [overtone.live])
(:require [clojure.string :as str]
[overtone.sc.dyn-vars :as dvars])
)
;; Utility functions (for creating and storing synthdefs)
(defn save-synthdef [sdef folder]
(let [path (str folder "/" (last (str/split (-> sdef :sdef :name) #"/")) ".scsyndef") ]
(overtone.sc.machinery.synthdef/synthdef-write (:sdef sdef) path)
path))
(defn save-to-pi [sdef]
(save-synthdef sdef "/Users/sam/Development/RPi/sonic-pi/etc/synthdefs/"))
;; Triggered synths
(do
(without-namespace-in-synthdef
;; your synths here
)
(comment
;; (save-to-pi sonic-pi-beep)
))
;;FX
(without-namespace-in-synthdef
;; BPF designs
(defsynth sonic-pi-fx_reverb2
[amp 1
amp_slide 0
amp_slide_shape 5
amp_slide_curve 0
mix 0.4
mix_slide 0
mix_slide_shape 5
mix_slide_curve 0
pre_amp 1
pre_amp_slide 0
pre_amp_slide_shape 5
pre_amp_slide_curve 0
rev_time 0.5
rev_time_slide 0
rev_time_slide_shape 5
room 0.6
max_room 1
damp 0.5
damp_slide 0
damp_slide_shape 5
damp_slide_curve 0
in_damp 0.5
in_damp_slide 0
in_damp_slide_shape 5
in_damp_slide_curve 0
in_bus 0
out_bus 0]
(let [amp (varlag amp amp_slide amp_slide_curve amp_slide_shape)
mix (varlag mix mix_slide mix_slide_curve mix_slide_shape)
pre_amp (varlag pre_amp pre_amp_slide pre_amp_slide_curve pre_amp_slide_shape)
room (* room 300)
max_room (* max_room 300)
damp (varlag damp damp_slide damp_slide_curve damp_slide_shape)
[l r] (* pre_amp (in:ar in_bus 2))
snd (* amp (g-verb l r mix room damp))]
(out out_bus snd)))
(defsynth sonic-pi-fx_chorus
[amp 1
amp_slide 0
amp_slide_shape 5
amp_slide_curve 0
mix 1
mix_slide 0
mix_slide_shape 5
mix_slide_curve 0
pre_amp 1
pre_amp_slide 0
pre_amp_slide_shape 5
pre_amp_slide_curve 0
phase 0.5
phase_slide 0
phase_slide_shape 5
phase_slide_curve 0
decay 0
decay_slide 0
decay_slide_shape 5
decay_slide_curve 0
max_phase 1
amp 1
amp_slide 0
amp_slide_shape 5
amp_slide_curve 0
in_bus 0
out_bus 0]
(let [amp (varlag amp amp_slide amp_slide_curve amp_slide_shape)
mix (varlag mix mix_slide mix_slide_curve mix_slide_shape)
pre_amp (varlag pre_amp pre_amp_slide pre_amp_slide_curve pre_amp_slide_shape)
phase (varlag phase phase_slide phase_slide_curve phase_slide_shape)
decay (varlag decay decay_slide decay_slide_curve decay_slide_shape)
[in-l in-r] (* pre_amp (in in_bus 2))
;; The phase here is the distance between two slow sin-oscs
[new-l new-r] (+ [in-l in-r] (comb-n [in-l in-r] max_phase [(sin-osc:ar 0.0004) (sin-osc:ar (* 0.0001 (+ phase 0.4)))] decay))
fin-l (x-fade2 in-l new-l (- (* mix 2) 1) amp)
fin-r (x-fade2 in-r new-r (- (* mix 2) 1) amp)]
(out out_bus [fin-l fin-r])))
;; END BPF designs
;; (def ab (audio-bus 2))
;; (def g (group :after (foundation-default-group)))
;; (sonic-pi-fx_chorus [:head g] :in_bus ab)
;; (run (out ab (pan2 (saw))))
;; (kill sonic-pi-fx_rbpf)
(do ;;comment
(save-to-pi sonic-pi-fx_chorus)
))
;; Experimental
(comment
(do
;;TODO FIXME!
(defsynth sonic-pi-babbling [out_bus 0 x 0 y 50]
(let [x (abs x)
x (/ x 100000)
x (min x 0.05)
x (max x 0.005)
y (abs y)
y (min y 10000)
y (max y 200)
noise (* 0.003
(rhpf (one-pole (* 0.99 (brown-noise)))
(+ 500 (* 400 (lpf (* (brown-noise) 14))))
x))
noise [noise noise]
noise2 (* 0.005
(rhpf (one-pole (* 0.99 (brown-noise)))
(+ 1000 (* 800 (lpf (* (brown-noise) 20))))
x))
noise2 [noise2 noise2]
mixed (+ noise noise2)
mixed (lpf mixed y)]
(out out_bus (* 0 (mix (* 3 mixed))))))
(save-to-pi sonic-pi-babbling))
(do
(defsynth sonic-pi-woah [note 52 out_bus 0 x 0 y 0]
(let [freq (midicps note)
x (abs x)
x (/ x 700)
x (min x 15)
x (max x 0.5)
snd (lpf (sync-saw
freq
(* (* freq 1.5) (+ 2 (sin-osc:kr x))))
1000)]
(out out_bus (* 0.25 snd))))
(save-to-pi sonic-pi-woah))
(do
(defsynth sonic-pi-arpeg-click [x 10 buf 0 arp-div 2 beat-div 1 out_bus 0]
(let [x (abs x)
x (/ x 70)
x (min x 200)
x (max x 1)
tik (impulse x)
a-tik (pulse-divider tik arp-div)
b-tik (pulse-divider tik beat-div)
cnt (mod (pulse-count a-tik) (buf-frames 1))
note (buf-rd:kr 1 1 cnt)
freq (midicps note)
snd (white-noise)
snd (rhpf snd 2000 0.4)
snd (normalizer snd)
b-env (env-gen (perc 0.01 0.1) b-tik)
a-env (env-gen (perc 0.01 0.4) a-tik)]
(out out_bus (* 0.20 (pan2 (+ (* 0.5 snd b-env)
(* (sin-osc freq) a-env)
(* (sin-osc (* 2 freq)) a-env)))))))
(save-to-pi sonic-pi-arpeg-click) )
(do
(defsynth sonic-pi-space_organ [note 24 amp 1 x 0 y 0 out_bus 0]
(let [freq-shift (/ x 100)
delay (* -1 (/ x 10000))]
(out out_bus (pan2 (g-verb (* 0.2 (mix (map #(blip (+ freq-shift (* (midicps (duty:kr % 0 (dseq [note (+ 3 note) (+ 7 note) (+ 12 note) (+ 17 note)] INF))) %2)) (mul-add:kr (lf-noise1:kr 1/2) 3 4)) (+ delay [1 1/4]) [1 8]))) 200 8)))))
(save-to-pi sonic-pi-space_organ)
(defsynth sonic-pi-saws [note 52 x 0 y 0 out_bus 0]
(let [x (abs x)
x (min x 10000)
x (max x 50)
y (abs y)
y (/ y 10000)
y (min y 0.3)
y (max y 0)
freq (midicps note)]
(out out_bus (mix (* 0.15 (normalizer (lpf (saw [freq (+ freq (* freq y))]) x)))))))
(save-to-pi sonic-pi-saws) )
(mod_dsaw 52)
(def s (freesound 18765))
(defsynth sonic-pi-stereo_warp_sample [buf 0
amp 1
amp_slide 0
amp_slide_shape 5
amp_slide_curve 0
pan 0
pan_slide 0
pan_slide_shape 5
pan_slide_curve 0
start 0
finish 1
rate 1
rate_slide 0
rate_slide_shape 5
rate_slide_curve 0
window_size 0.1
overlaps 8
out_bus 0]
(let [amp (varlag amp amp_slide amp_slide_curve amp_slide_shape)
pan (varlag pan pan_slide pan_slide_curve pan_slide_shape)
rate (varlag rate rate_slide rate_slide_curve rate_slide_shape)
play-time (* (buf-dur buf) (absdif finish start))
snd (warp1:ar 2 buf (line start finish play-time) rate window_size overlaps 0 4)
[snd-l snd-r] snd
snd (balance2 snd-l snd-r pan amp)
]
(out out_bus snd)))
(without-namespace-in-synthdef
(defsynth sonic-pi-singer
"TODO: support vowel changes"
[note 52
note_slide 0
note_slide_shape 5
note_slide_curve 0
amp 1
amp_slide 0
amp_slide_shape 5
amp_slide_curve 0
pan 0
pan_slide 0
pan_slide_shape 5
pan_slide_curve 0
attack 0
decay 0
sustain 0
release 4
attack_level 1
sustain_level 1
env_curve 2
cutoff 110
cutoff_slide 0
cutoff_slide_shape 5
cutoff_slide_curve 0
res 0.3
res_slide 0
res_slide_shape 5
res_slide_curve 0
vibrato_speed 6
vibrato_depth 4
freq0 400
freq1 750
freq2 2400
freq3 2600
freq4 2900
amp0 1
amp1 0.28
amp2 0.08
amp3 0.1
amp4 0.01
qs0 0.1
qs1 0.1
qs2 0.04
qs3 0.04
qs4 0.04
lag-val 0.5
out_bus 0
]
(let [pan (varlag pan pan_slide pan_slide_curve pan_slide_shape)
note (varlag note note_slide note_slide_curve note_slide_shape)
amp (varlag amp amp_slide amp_slide_curve amp_slide_shape)
cutoff (varlag cutoff cutoff_slide cutoff_slide_curve cutoff_slide_shape)
res (varlag res res_slide res_slide_curve res_slide_shape)
freq (midicps note)
freqs-list (map #(lag:kr % lag-val) [freq0 freq1 freq2 freq3 freq4])
amps-list (map #(lag:kr (dbamp %) lag-val) [amp0 amp1 amp2 amp3 amp4])
qs-list (map #(lag:kr % lag-val) [qs0 qs1 qs2 qs3 qs4])
cutoff-freq (midicps cutoff)
vibrato (* vibrato_depth (sin-osc:kr vibrato_speed))
in (saw:ar (lag:kr (+ freq vibrato) 0.2))
env (env-gen:kr (env-adsr-ng attack decay sustain release attack_level sustain_level env_curve) :action FREE)
snd (mix (* amps-list (bpf:ar in freqs-list qs-list)))
snd (rlpf snd cutoff-freq res)
snd (* snd amp)]
(out out_bus (* (pan2 snd pan) env)))))
(defsynth sonic-pi-dark_sea_horn
"Dark, rough and sharp sea horn.
Note: we are purposely not using recusion using busses. Just does not have the same feel."
[out_bus 0
note 52
note_slide 0
note_slide_shape 5
note_slide_curve 0
pan 0
pan_slide 0
pan_slide_shape 5
pan_slide_curve 0
amp 1
amp_slide 0
amp_slide_shape 5
amp_slide_curve 0
attack 1
decay 0
sustain 0
release 4.0
attack_level 1
sustain_level 1
env_curve 2]
(let [note (varlag note note_slide note_slide_curve note_slide_shape)
amp (varlag amp amp_slide amp_slide_curve amp_slide_shape)
pan (varlag pan pan_slide pan_slide_curve pan_slide_shape)
freq (midicps note)
a (tanh (* 6 (lf-noise1:ar 3) (sin-osc:ar freq (* (lf-noise1:ar 0.1) 3))))
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (tanh a)
a (tanh (* 6 (lf-noise1:ar 3) (sin-osc:ar freq (* a (lf-noise1:ar 0.1) 3))))
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (tanh a)
a (tanh (* 6 (lf-noise1:ar 3) (sin-osc:ar freq (* a (lf-noise1:ar 0.1) 3))))
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (tanh a)
a (tanh (* 6 (lf-noise1:ar 3) (sin-osc:ar freq (* a (lf-noise1:ar 0.1) 3))))
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (tanh a)
a (tanh (* 6 (lf-noise1:ar 3) (sin-osc:ar freq (* a (lf-noise1:ar 0.1) 3))))
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (allpass-l:ar a 0.3 [(+ (ranged-rand 0 0.2) 0.1) (+ (ranged-rand 0 0.2) 0.1)] 5)
a (tanh a)
env (env-gen:kr (env-adsr-ng attack decay sustain release attack_level sustain_level env_curve) :action FREE)
snd (* amp a)]
(out out_bus (* env (pan2 snd pan)))))
(comment
(sonic-pi-dark_sea_horn :attack 1 :release 8 :note 40)
(save-to-pi sonic-pi-dark_sea_horn)
)
(comment
(defn bass [] (singer :freq 100))
(defn tenor [] (singer :freq 280))
(defn alto [] (singer :freq 380))
(defn soprano [] (singer :freq 580))
(def v (bass))
(save-to-pi sonic-pi-singer)
)
)