| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-odac -m128 |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
sr = 44100 |
| 7 |
ksmps = 32 |
| 8 |
nchnls = 2 |
| 9 |
0dbfs = 1 |
| 10 |
|
| 11 |
//load sample to table and create half sine envelope |
| 12 |
giSample ftgen 0, 0, 0, -1, "fox.wav", 0, 0, 1 |
| 13 |
giHalfSine ftgen 0, 0, 1024, 9, .5, 1, 0 |
| 14 |
|
| 15 |
instr Granulator |
| 16 |
//input parameters as described in text |
| 17 |
iSndTab = giSample ;table with sample |
| 18 |
iSampleLen = ftlen(iSndTab)/sr |
| 19 |
kPointer = linseg:k(0,iSampleLen,iSampleLen) |
| 20 |
iGrainDur = 30 ;milliseconds |
| 21 |
iTranspos = -100 ;cent |
| 22 |
iVolume = -6 ;dB |
| 23 |
iEnv = giHalfSine ;table with envelope |
| 24 |
iPan = .5 ;panning 0-1 |
| 25 |
iDensity = 50 ;Hz (grains per second) |
| 26 |
iDistribution = .5 ;0-1 |
| 27 |
//perform: call grains over time |
| 28 |
kTrig = metro(iDensity) |
| 29 |
if kTrig==1 then |
| 30 |
kOffset = random:k(0,iDistribution/iDensity) |
| 31 |
schedulek("Grain", kOffset, iGrainDur/1000, iSndTab, iSampleLen, |
| 32 |
kPointer, cent(iTranspos), iVolume, iEnv, iPan) |
| 33 |
endif |
| 34 |
endin |
| 35 |
|
| 36 |
instr Grain |
| 37 |
//input parameters |
| 38 |
iSndTab = p4 |
| 39 |
iSampleLen = p5 |
| 40 |
iStart = p6 |
| 41 |
iSpeed = p7 |
| 42 |
iVolume = p8 ;dB |
| 43 |
iEnvTab = p9 |
| 44 |
iPan = p10 |
| 45 |
//perform |
| 46 |
aEnv = poscil3:a(ampdb(iVolume),1/p3,iEnvTab) |
| 47 |
aSound = poscil3:a(aEnv,iSpeed/iSampleLen,iSndTab,iStart/iSampleLen) |
| 48 |
aL, aR pan2 aSound, iPan |
| 49 |
out(aL,aR) |
| 50 |
endin |
| 51 |
|
| 52 |
</CsInstruments> |
| 53 |
<CsScore> |
| 54 |
i "Granulator" 0 3 |
| 55 |
</CsScore> |
| 56 |
</CsoundSynthesizer> |
| 57 |
;example by joachim heintz |