Debian Codegraph @

examples/pconvolve.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 ; Select audio/midi flags here according to platform
4 -odac ;;;realtime audio out
5 -iadc ;;;uncomment -iadc if real audio input is needed too
6 ; For Non-realtime ouput leave only the line below:
7 ; -o pconvolve.wav -W ;;; for file output any platform
8 </CsOptions>
9 <CsInstruments>
10
11 ; additions by Menno Knevel 2022
12
13 sr = 44100
14 ksmps = 32
15 nchnls = 2
16 nchnls_i = 1 ; assume only one mono signal for audio input!
17 0dbfs = 1
18
19 instr 1
20
21 kmix = .5 ; Wet/dry mix
22 kvol = .05*kmix ; volume level of reverb
23
24 kmix = (kmix < 0 || kmix > 1 ? .5 : kmix) ; do some safety checking
25 kvol = (kvol < 0 ? 0 : .5*kvol*kmix) ; to make sure we the parameters a good
26
27 ipartitionsize = p4 ; size of each convolution partion
28 ; for best performance, this parameter needs to be tweaked
29 idel = (ksmps < ipartitionsize ? ipartitionsize + ksmps : ipartitionsize)/sr ; calculate latency
30 prints "\nConvolving with a latency of %f seconds\n", idel
31 prints "***if no live input is given, nothing will sound...***\n\n"
32
33 alive in ; get live input (mono)
34 awetl, awetr pconvolve kvol* (alive), "drumsSlp.wav", ipartitionsize
35
36 adryl delay (1-kmix)*alive, idel ; delay dry signal, to align it with the convoled sig
37 adryr delay (1-kmix)*alive, idel
38 outs adryl+awetl, adryr+awetr
39
40 endin
41
42 instr 2
43
44 imix = 0.5 ; Wet/dry mix
45 ivol = .05*imix ; volume level of reverb when wet/dry mix is changed, to avoid clipping
46
47 ipartitionsize = 1024 ; size of each convolution partion
48 idel = (ksmps < ipartitionsize ? ipartitionsize + ksmps : ipartitionsize)/sr ; latency of pconvolve opcode
49
50 kcount init idel*kr
51 ; since we are using a soundin [instead of in] we can do a kind of "look ahead"
52 ; without output, creating zero-latency by looping during one k-pass
53 loop:
54 asig soundin p4, 0
55 awetl, awetr pconvolve ivol*(asig),"rv_stereo.wav", ipartitionsize
56 adry delay (1-imix)*asig,idel ; Delay dry signal, to align it with
57 kcount = kcount - 1
58 if kcount > 0 kgoto loop
59 outs awetl+adry, awetr+adry
60
61 endin
62
63 </CsInstruments>
64 <CsScore>
65
66 i 1 0 20 1024 ;play live for 20 seconds
67
68 i 2 20 5 "fox.wav"
69 i 2 25 5 "flute.aiff"
70 e
71 </CsScore>
72 </CsoundSynthesizer>