| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-odac |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
sr = 44100 |
| 7 |
ksmps = 32 |
| 8 |
nchnls = 2 |
| 9 |
0dbfs = 1 |
| 10 |
|
| 11 |
giSine ftgen 0, 0, 2^10, 10, 1 |
| 12 |
seed 0 |
| 13 |
|
| 14 |
opcode PlayPartials, aa, iiipo |
| 15 |
;plays inumparts partials with frequency deviation and own envelopes and |
| 16 |
;durations for each partial |
| 17 |
;ibasfreq: base frequency of sound mixture |
| 18 |
;inumparts: total number of partials |
| 19 |
;ipan: panning |
| 20 |
;ipartnum: which partial is this (1 - N, default=1) |
| 21 |
;ixtratim: extra time in addition to p3 needed for this partial (default=0) |
| 22 |
|
| 23 |
ibasfreq, inumparts, ipan, ipartnum, ixtratim xin |
| 24 |
ifreqgen = ibasfreq * ipartnum; general frequency of this partial |
| 25 |
ifreqdev random -10, 10; frequency deviation between -10% and +10% |
| 26 |
ifreq = ifreqgen + (ifreqdev*ifreqgen)/100; real frequency |
| 27 |
ixtratim1 random 0, p3; calculate additional time for this partial |
| 28 |
imaxamp = 1/inumparts; maximum amplitude |
| 29 |
idbdev random -6, 0; random deviation in dB for this partial |
| 30 |
iamp = imaxamp * ampdb(idbdev-ipartnum); higher partials are softer |
| 31 |
ipandev random -.1, .1; panning deviation |
| 32 |
ipan = ipan + ipandev |
| 33 |
aEnv transeg 0, .005, 0, iamp, p3+ixtratim1-.005, -10, 0; envelope |
| 34 |
aSine poscil aEnv, ifreq, giSine |
| 35 |
aL1, aR1 pan2 aSine, ipan |
| 36 |
if ixtratim1 > ixtratim then |
| 37 |
ixtratim = ixtratim1 ;set ixtratim to the ixtratim1 if the latter is larger |
| 38 |
endif |
| 39 |
if ipartnum < inumparts then ;if this is not the last partial |
| 40 |
; -- call the next one |
| 41 |
aL2, aR2 PlayPartials ibasfreq, inumparts, ipan, ipartnum+1, ixtratim |
| 42 |
else ;if this is the last partial |
| 43 |
p3 = p3 + ixtratim; reset p3 to the longest ixtratim value |
| 44 |
endif |
| 45 |
xout aL1+aL2, aR1+aR2 |
| 46 |
endop |
| 47 |
|
| 48 |
instr 1; time loop with metro |
| 49 |
kfreq init 1; give a start value for the trigger frequency |
| 50 |
kTrig metro kfreq |
| 51 |
if kTrig == 1 then ;if trigger impulse: |
| 52 |
kdur random 1, 5; random duration for instr 10 |
| 53 |
knumparts random 8, 14 |
| 54 |
knumparts = int(knumparts); 8-13 partials |
| 55 |
kbasoct random 5, 10; base pitch in octave values |
| 56 |
kbasfreq = cpsoct(kbasoct) ;base frequency |
| 57 |
kpan random .2, .8; random panning between left (0) and right (1) |
| 58 |
event "i", 11, 0, kdur, kbasfreq, knumparts, kpan; call instr 11 |
| 59 |
kfreq random .25, 1; set new value for trigger frequency |
| 60 |
endif |
| 61 |
endin |
| 62 |
|
| 63 |
instr 11; plays one mixture with 8-13 partials |
| 64 |
aL, aR PlayPartials p4, p5, p6 |
| 65 |
outs aL, aR |
| 66 |
endin |
| 67 |
|
| 68 |
</CsInstruments> |
| 69 |
<CsScore> |
| 70 |
i 1 0 300 |
| 71 |
</CsScore> |
| 72 |
</CsoundSynthesizer> |
| 73 |
;Example by Joachim Heintz |