--env:SSDIR+=../../SourceMaterials
-m 128
/*****Universal Convolution*****/
;example for CsoundQt
;written by joachim heintz
;jul 2009
;please send bug reports and suggestions
;to jh at joachimheintz.de
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1
opcode TakeAll2, aa, Skii
Sfil, kspeed, iskip, iloop xin
ichn filenchnls Sfil
if ichn == 1 then
aL diskin2 Sfil, kspeed, iskip, iloop
aR = aL
else
aL, aR diskin2 Sfil, kspeed, iskip, iloop
endif
xout aL, aR
endop
opcode ShowLED_k, 0, Skkik
Soutchan, kdispval, ktrig, idb, kdbrange xin
if idb != 0 then
kdb = dbfsamp(kdispval)
kval = (kdbrange + kdb) / kdbrange
else
kval = kdispval
endif
if ktrig == 1 then
outvalue Soutchan, kval
endif
endop
opcode ShowOver_k, 0, Skkk
Soutchan, kmax, ktrig, khold xin
kon init 0
ktim times
kstart init 0
kend init 0
khold = (khold < .01 ? .01 : khold); avoiding too short hold times
if kon == 0 && kmax > 1 && ktrig == 1 then
kstart = ktim
kend = kstart + khold
outvalue Soutchan, kmax
kon = 1
endif
if kon == 1 && ktim > kend && ktrig == 1 then
outvalue Soutchan, 0
kon = 0
endif
endop
instr 1
;;values for file 1 (playback)
Sfile1 invalue "_Browse1"; soundfile which is played back
kspeed invalue "speed"; playback speed (1 = original speed)
kskip invalue "skip"; skiptime in seconds
kloop invalue "loop"; 0 = no loop, 1 = loop
;;values and calculations for file 2 (convolution)
Sfile2 invalue "_Browse2"; soundfile which is used as impulse response
kstartabs invalue "startabs"; 0-1
kirlen invalue "irlen"; length of selected impulse response in secs (0 = take the whole length)
kpartsiz invalue "partsiz"; partitionsize of convolution
kplen = (kpartsiz == 0 ? 256 : (kpartsiz == 1 ? 512 : (kpartsiz == 2 ? 1024 : (kpartsiz == 3 ? 2048 : 4096))))
iconvsr filesr Sfile2; sample rate of convolution file
iconvlen filelen Sfile2; length of convolution file in seconds ...
iconvlensmps = iconvlen * iconvsr; ... and in samples
kselstart = kstartabs * iconvlen; startpoint of selection for convolution in seconds ...
outvalue "start", kselstart
kskpsmps = kselstart * iconvsr; ... and in samples
kirlensmps = (kirlen == 0? (iconvlen - kselstart) * iconvsr : kirlen * iconvsr); length of selection in samples
;;creating two ftables (left and right channel) for ftconv
ichnlsfil2 filenchnls Sfile2
if ichnlsfil2 == 2 then
iftlen = 2 ^ ceil(log(iconvlensmps / 2) / log(2))
giftL ftgen 0, 0, iftlen, 1, Sfile2, 0, 0, 1
giftR ftgen 0, 0, iftlen, 1, Sfile2, 0, 0, 2
else; if mono impulse response, create two identical tables
iftlen = 2 ^ ceil(log(iconvlensmps) / log(2))
giftL ftgen 0, 0, iftlen, 1, Sfile2, 0, 0, 1
giftR ftgen 0, 0, iftlen, 1, Sfile2, 0, 0, 1
endif
;;creating the playback audio stream as global audio
gaL, gaR TakeAll2 Sfile1, kspeed, i(kskip), i(kloop)
;;calling a subinstrument with a release time (to avoid clicks) for performing the convolution
ktrig changed kplen, kskpsmps, kirlensmps; if there are new values for the selection in file 2:
if ktrig == 1 then
event "i", -10, 0, 0; stop previous instance of instr 10
event "i", 10, 0, -p3, kplen, kskpsmps, kirlensmps; call new instance with new values
endif
;;show output
gkshowL init 0
gkshowR init 0
kTrigDisp metro 10
ShowLED_k "outL", gkshowL, kTrigDisp, 0, 50
ShowLED_k "outR", gkshowR, kTrigDisp, 0, 50
ShowOver_k "outLover", gkshowL, kTrigDisp, 2
ShowOver_k "outRover", gkshowR, kTrigDisp, 2
endin
instr 10
;;input values
iplen = p4; partitionsize of convolution
iskpsmps = p5; how many samples to skip
iirlen = p6; length of selection for impulse response in samples
kwdmix invalue "wdmix"; 0 = dry (just playback stream), 1 = wet (just convoluted signal)
kgaindb invalue "gaindb"
kgain = ampdb(kgaindb)
;;performing convolution
acvL ftconv gaL, giftL, iplen, iskpsmps, iirlen
acvR ftconv gaR, giftR, iplen, iskpsmps, iirlen
;;mixing dry and wet parts
awetL = acvL * kwdmix
awetR = acvR * kwdmix
adryL = gaL * (1 - kwdmix)
adryR = gaR * (1 - kwdmix)
aL = (awetL + adryL) * kgain
aR = (awetR + adryR) * kgain
;;declicking envelope and output
aenv linsegr 0, .01, 1, p3-.01, 1, .01, 0
aoutL = aL * aenv
aoutR = aR * aenv
outs aoutL, aoutR
gaL = 0; zero global audio
gaR = 0
;;send the peak information to the display
kTrigDisp metro 10
gkshowL max_k aoutL, kTrigDisp, 1
gkshowR max_k aoutR, kTrigDisp, 1
endin
i 1 0 9999
e
605
171
532
741
true
170
170
127
68
6
398
43
{0dfd9349-d4f3-44ba-9392-436787965358}
true
0
-3
center
top
Lucida Grande
26
3
0
0
0
255
255
255
noborder
1
0
20
91
472
141
{1b921b24-730c-404d-9d46-89e1854ef34f}
true
0
-3
left
top
Lucida Grande
10
3
0
0
0
255
255
255
border
1
1
20
468
474
209
{efd6b17f-4c09-4e23-ad57-5744401d6a82}
true
0
-3
left
top
Lucida Grande
10
3
0
0
0
255
255
255
border
1
1
20
237
474
223
{bfc8f118-c544-4857-bb8b-a1612fe3334c}
true
0
-3
left
top
Lucida Grande
10
3
0
0
0
255
255
255
border
1
1
_Browse1
36
134
346
25
{bf9e3246-29ee-46d2-a3f3-7de50d473ea5}
true
0
-3
left
Lucida Grande
10
3
0
0
0
239
239
239
nobackground
_Browse1
386
133
100
30
{56887738-e5d6-4df8-8232-fbdef66f33aa}
true
0
-3
value
1.00000000
ClassicalGuitar.wav
Open File 1
/
false
false
false
10
147
96
192
29
{d76dc890-5021-4e65-a76a-423a9fceac95}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
52
162
63
27
{1f2442dd-02f4-4114-8e10-53936f7caa61}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
skip
169
199
80
25
{4f293280-0835-4944-8ace-9e355fab1f41}
true
0
-3
left
Lucida Grande
10
0
0
0
255
255
255
0.00100000
-1e+12
1e+12
false
0
163
163
85
27
{5fe3eed0-b448-4d85-a9eb-ee43242ea31c}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
292
165
85
27
{e8b4fc19-b152-414e-83d7-a18fe5ec2b18}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
loop
309
199
56
22
{6fe0f726-7021-4795-b5a4-35c1d8db2aee}
true
0
-3
no
0
yes
1
1
false
speed
46
197
80
25
{0ed6e4f8-a586-459a-b882-ac734ca54253}
true
0
-3
left
Lucida Grande
10
0
0
0
255
255
255
0.00100000
-1e+12
1e+12
false
1
_Browse2
32
269
348
25
{732ed584-df46-47ed-b98d-239c33707191}
true
0
-3
left
Lucida Grande
10
3
0
0
0
239
239
239
nobackground
_Browse2
390
279
100
30
{133f0f35-a0e6-48b9-945b-d92a4b8bf5d6}
true
0
-3
value
1.00000000
fox.wav
Open File 2
/
false
false
false
10
144
242
192
29
{4593c21f-d695-47ab-95c6-5be8156ba5f0}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
21
294
280
29
{f96477f6-1a88-4eb4-99aa-2b3d85b02539}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
75
372
63
27
{3f5d63e6-aea0-46fd-9270-b66473655ec2}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
247
370
63
27
{f2ee5559-ba39-454b-951d-af2053e1263a}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
341
333
105
29
{f61b9803-c1d1-4420-b7bb-bdbdd7a838a9}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
partsiz
354
370
84
24
{7495ceb2-acc3-42ef-9ea3-f18958e87542}
true
0
-3
256
0
512
1
1024
2
2048
3
4096
4
2
false
startabs
31
397
156
29
{71469a99-1292-40c0-8709-97538dc3fd29}
true
0
-3
0.00000000
1.00000000
0.03846154
lin
continuous
-1.00000000
false
irlen
201
396
156
29
{dd3fe5d5-9446-4332-82bf-f5108f9d4a7d}
true
0
-3
0.00000000
1.00000000
0.02564103
lin
continuous
-1.00000000
false
start
81
430
62
34
{a951505a-e910-470b-8e8a-9fb704ae8bbf}
true
0
-3
left
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
irlen
226
429
55
28
{130f73fc-6a52-491b-95b0-b05dbe596ca2}
true
0
-3
left
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
281
429
212
29
{e9c56d17-9b8c-48eb-8fcd-e2fb581dfd28}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
wdmix
110
521
282
29
{fa18f494-a9df-4ad5-ae0a-4723109db6fc}
true
0
-3
0.00000000
1.00000000
0.80141844
lin
continuous
-1.00000000
false
188
483
130
30
{d8a31d59-1afd-49f9-bf11-3360d83fafdc}
true
0
-3
center
top
DejaVu Sans
14
3
0
0
0
255
255
255
noborder
1
0
70
521
34
27
{90a871c4-2519-45eb-ba44-b742fa87438a}
true
0
-3
left
top
Lucida Grande
12
3
0
0
0
255
255
255
noborder
1
0
399
522
34
27
{1ac3bf90-8661-42b7-bbbd-2f8006716234}
true
0
-3
left
top
Lucida Grande
12
3
0
0
0
255
255
255
noborder
1
0
305
570
130
28
{3def89e0-8953-4d4a-85bb-2e2e193a9331}
true
0
-3
center
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
gaindb
99
566
201
34
{1eef7045-2e40-475c-9543-8bbb1b26235d}
true
0
0
-50.00000000
0.00000000
-21.39303483
lin
continuous
-1.00000000
false
gaindb
33
566
62
34
{4d3d0bad-8090-450e-b6e7-84dd8c07988c}
true
0
-3
left
top
Bitstream Vera Sans
14
3
0
0
0
255
255
255
false
1
0
wdmix
322
481
62
34
{0c2ae3bd-ee97-4699-96ef-4d1ff316e427}
true
0
-3
left
top
Lucida Grande
14
3
0
0
0
255
255
255
noborder
1
0
outL
121
614
250
19
{52e33137-e648-4c88-81de-ebddb3f0905d}
true
0
-3
out1_post
0.00000000
1.00000000
0.00000000
1.00000000
0.09971676
0.57894700
fill
1
0.00000000
jump
noborder
#00FF00
0
234
0
false
0
0
0
true
outLover
368
614
21
19
{729db991-6c0e-46d7-b7d6-7ba7efeae81f}
true
0
-3
outLover
0.00000000
1.00000000
0.00000000
1.00000000
0.00000000
0.00000000
fill
1
0.00000000
jump
noborder
#00FF00
196
14
12
false
0
0
0
true
outR
121
641
250
19
{c68846ac-172c-49bd-8cd3-a9742c17d0e0}
true
0
-3
out2_post
0.00000000
1.00000000
0.00000000
1.00000000
0.07993188
1.00000000
fill
1
0.00000000
jump
noborder
#00FF00
0
234
0
false
0
0
0
true
outRover
368
641
21
19
{f56fef73-44c7-4e1f-a62b-a18512955ca3}
true
0
-3
outRover
0.00000000
1.00000000
0.00000000
1.00000000
0.00000000
0.00000000
fill
1
0.00000000
jump
noborder
#00FF00
196
14
12
false
0
0
0
true
23
49
468
37
{1812f769-c632-4bc3-9080-c213690435d4}
true
0
-3
left
top
Bitstream Vera Sans
14
3
0
0
0
255
255
255
false
1
0
22
323
280
47
{107a5b8a-97f4-413f-a9f1-d207027795ec}
true
0
-3
center
top
Bitstream Vera Sans
14
3
0
0
0
255
255
255
false
1
0