| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
; Select audio/midi flags here according to platform |
| 4 |
-odac ;;;realtime audio out |
| 5 |
-m128 ;;;reduce console output |
| 6 |
;-iadc ;;;uncomment -iadc if realtime audio input is needed too |
| 7 |
; For Non-realtime ouput leave only the line below: |
| 8 |
; -o Schedulek_Heintz.wav -W ;;; for file output any platform |
| 9 |
|
| 10 |
; by joachim heintz 2024 |
| 11 |
|
| 12 |
</CsOptions> |
| 13 |
<CsInstruments> |
| 14 |
|
| 15 |
sr = 48000 |
| 16 |
ksmps = 64 |
| 17 |
nchnls = 2 |
| 18 |
0dbfs = 1 |
| 19 |
seed 0 |
| 20 |
|
| 21 |
opcode RndHarm,i[],iop |
| 22 |
//generates an array with iLen random numbers |
| 23 |
iLen,iMin,iMax xin //defaults to iMin=0 and iMax=1 |
| 24 |
iOut[] init iLen |
| 25 |
indx = 0 |
| 26 |
while (indx<iLen) do |
| 27 |
iOut[indx] = random:i(iMin,iMax) |
| 28 |
indx += 1 |
| 29 |
od |
| 30 |
xout iOut |
| 31 |
endop |
| 32 |
|
| 33 |
|
| 34 |
instr GenerateSpectrum |
| 35 |
iHarmonics[] = RndHarm(p4) |
| 36 |
giSound = ftgen(0,0,4096,10,iHarmonics) |
| 37 |
endin |
| 38 |
schedule("GenerateSpectrum",0,0,4) |
| 39 |
|
| 40 |
instr Call |
| 41 |
iStartPitch = 80 //MIDI note number |
| 42 |
kPitch init iStartPitch |
| 43 |
kStep init 3 |
| 44 |
kNoteCount init 0 |
| 45 |
kTrigMaxFreq init 3 |
| 46 |
kTrigFreq init 2 |
| 47 |
kPan init 0.9 |
| 48 |
kNumHarm init 4 |
| 49 |
kCycleCount init 1 |
| 50 |
if (metro:k(kTrigFreq) == 1) then |
| 51 |
// call instrument |
| 52 |
schedulek("Play",0,kCycleCount/kTrigMaxFreq,kPitch,kPan) |
| 53 |
// update values |
| 54 |
kTrigFreq = random:k(kTrigMaxFreq/2,kTrigMaxFreq) |
| 55 |
kNoteCount += 1 |
| 56 |
kPan -= 0.8/7 |
| 57 |
kPitch -= kStep |
| 58 |
// if seven tones have been played, start again differently |
| 59 |
if (kNoteCount == 7) then |
| 60 |
kPitch = iStartPitch |
| 61 |
kPan = 0.9 |
| 62 |
kStep /= 1.5 |
| 63 |
kTrigMaxFreq /= 1.5 |
| 64 |
kNoteCount = 0 |
| 65 |
kNumHarm *= 1.5 |
| 66 |
kCycleCount += 1 |
| 67 |
schedulek("GenerateSpectrum",0,0,int(kNumHarm)) |
| 68 |
endif |
| 69 |
// stop after six cycles |
| 70 |
if (kCycleCount == 7) then |
| 71 |
schedulek("Terminate",kCycleCount/kTrigMaxFreq,1) |
| 72 |
turnoff |
| 73 |
endif |
| 74 |
endif |
| 75 |
// print main values |
| 76 |
if (changed(kCycleCount) == 1) then |
| 77 |
printks("Cycle %d:\n",0,kCycleCount) |
| 78 |
printks(" kStep (semitones) and kTrigMaxFreq (Hz) = %.3f\n number of harmonics = %.3f\n",0,kStep,int(kNumHarm)) |
| 79 |
endif |
| 80 |
endin |
| 81 |
schedule("Call",0,-1) |
| 82 |
|
| 83 |
instr Play |
| 84 |
iPitch = p4 |
| 85 |
iPan = p5 |
| 86 |
aOut = oscili:a(0.2,mtof:i(iPitch),giSound) |
| 87 |
aOut = linen:a(aOut,0,p3,p3/2) |
| 88 |
aL,aR pan2 aOut,iPan |
| 89 |
out(aL,aR) |
| 90 |
endin |
| 91 |
|
| 92 |
instr Terminate |
| 93 |
event("e",0,0) |
| 94 |
endin |
| 95 |
|
| 96 |
</CsInstruments> |
| 97 |
<CsScore> |
| 98 |
</CsScore> |
| 99 |
</CsoundSynthesizer> |