| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-odac -m128 |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
|
| 7 |
sr = 44100 |
| 8 |
ksmps = 32 |
| 9 |
nchnls = 2 |
| 10 |
0dbfs = 1 |
| 11 |
|
| 12 |
;create IR table |
| 13 |
giIR_record ftgen 0, 0, 131072, 2, 0 |
| 14 |
|
| 15 |
instr Input |
| 16 |
|
| 17 |
ain diskin "beats.wav", 1, 0, 1 |
| 18 |
chnset ain, "input" |
| 19 |
if timeinsts() < 2 then |
| 20 |
outch 2, ain/2 |
| 21 |
endif |
| 22 |
endin |
| 23 |
|
| 24 |
instr Record_IR |
| 25 |
|
| 26 |
;set p3 to table duration |
| 27 |
p3 = ftlen(giIR_record)/sr |
| 28 |
iskip = p4 |
| 29 |
irlen = p5 |
| 30 |
|
| 31 |
;mimic live input for impulse response |
| 32 |
asnd diskin "fox.wav", 1, iskip |
| 33 |
amp linseg 0, 0.01, 1, irlen, 1, 0.01, 0 |
| 34 |
asnd *= amp |
| 35 |
|
| 36 |
;fill IR table |
| 37 |
andx_IR line 0, p3, ftlen(giIR_record) |
| 38 |
tablew asnd, andx_IR, giIR_record |
| 39 |
|
| 40 |
;send 1 at first k-cycle, otherwise 0 |
| 41 |
ktrig init 1 |
| 42 |
chnset ktrig, "conv_update" |
| 43 |
ktrig = 0 |
| 44 |
|
| 45 |
;output the IR for reference |
| 46 |
outch 1, asnd |
| 47 |
|
| 48 |
endin |
| 49 |
|
| 50 |
instr Convolver |
| 51 |
|
| 52 |
;receive information about updating the table |
| 53 |
kupdate chnget "conv_update" |
| 54 |
|
| 55 |
;different dB values for the different IR |
| 56 |
kdB[] fillarray -34, -35, -40, -28, -40, -40, -40 |
| 57 |
kindx init -1 |
| 58 |
if kupdate==1 then |
| 59 |
kindx += 1 |
| 60 |
endif |
| 61 |
|
| 62 |
;apply live convolution |
| 63 |
ain chnget "input" |
| 64 |
aconv liveconv ain, giIR_record, 2048, kupdate, 0 |
| 65 |
outch 2, aconv*ampdb(kdB[kindx]) |
| 66 |
|
| 67 |
endin |
| 68 |
|
| 69 |
|
| 70 |
</CsInstruments> |
| 71 |
<CsScore> |
| 72 |
;play input sound alone first |
| 73 |
i "Input" 0 15.65 |
| 74 |
|
| 75 |
;record impulse response multiple times |
| 76 |
; skip IR_dur |
| 77 |
i "Record_IR" 2 1 0.17 0.093 |
| 78 |
i . 4 . 0.50 0.13 |
| 79 |
i . 6 . 0.76 0.19 |
| 80 |
i . 8 . 0.97 0.12 |
| 81 |
i . 10 . 1.72 0.12 |
| 82 |
i . 12 . 2.06 0.12 |
| 83 |
i . 14 . 2.37 0.27 |
| 84 |
|
| 85 |
;convolve continuously |
| 86 |
i "Convolver" 2 13.65 |
| 87 |
</CsScore> |
| 88 |
</CsoundSynthesizer> |
| 89 |
;example by Oeyving Brandtsegg and Sigurd Saue |