| 1 |
<CsoundSynthesizer> |
| 2 |
|
| 3 |
<CsOptions> |
| 4 |
; Select audio/midi flags here according to platform |
| 5 |
; Audio out Audio in No display |
| 6 |
-odac -iadc -d ;;;RT audio I/O |
| 7 |
</CsOptions> |
| 8 |
|
| 9 |
<CsInstruments> |
| 10 |
|
| 11 |
sr = 44100 |
| 12 |
ksmps = 10 |
| 13 |
nchnls = 1 |
| 14 |
|
| 15 |
; Example by Jonathan Murphy 2007 |
| 16 |
|
| 17 |
;;; reset amplitude range |
| 18 |
0dbfs = 1 |
| 19 |
|
| 20 |
;;; set the base colour for the panel |
| 21 |
FLcolor 100, 0, 200 |
| 22 |
;;; define the panel |
| 23 |
FLpanel "FLexecButton", 250, 100, 0, 0 |
| 24 |
;;; sliders to control time stretch and pitch |
| 25 |
gkstr, gistretch FLslider "Time", 0.5, 1.5, 0, 6, -1, 10, 60, 150, 20 |
| 26 |
gkpch, gipitch FLslider "Pitch", 0.5, 1.5, 0, 6, -1, 10, 60, 200, 20 |
| 27 |
;;; set FLexecButton colour |
| 28 |
FLcolor 255, 255, 0 |
| 29 |
;;; when this button is pressed, fourier analysis is performed on the file |
| 30 |
;;; "drumsMlp.wav", producing the analysis file "beats.pvx" |
| 31 |
gipvoc FLexecButton "csound -U pvanal drumsMlp.wav beats.pvx", 60, 20, 20, 20 |
| 32 |
;;; set FLexecButton text |
| 33 |
FLsetText "PVOC", gipvoc |
| 34 |
;;; when this button is pressed, instr 10000 is called, exiting |
| 35 |
;;; Csound immediately |
| 36 |
|
| 37 |
;;; cancel previous colour |
| 38 |
FLcolor -1 |
| 39 |
;;; set colour for kill button |
| 40 |
FLcolor 255, 0, 0 |
| 41 |
gkkill, gikill FLbutton "X", 1, 1, 1, 20, 20, 100, 20, 0, 10000, 0, 0.1 |
| 42 |
;;; cancel previous colour |
| 43 |
FLcolor -1 |
| 44 |
;;; set colour for play/stop and pause buttons |
| 45 |
FLcolor 0, 200, 0 |
| 46 |
;;; pause and play/stop buttons |
| 47 |
gkpause, gipause FLbutton "@||", 1, 0, 2, 40, 20, 20, 60, -1 |
| 48 |
gkplay, giplay FLbutton "@|>", 1, 0, 2, 40, 20, 80, 60, -1 |
| 49 |
;;; end the panel |
| 50 |
FLpanelEnd |
| 51 |
;;; set initial values for time stretch and pitch |
| 52 |
FLsetVal_i 1, gistretch |
| 53 |
FLsetVal_i 1, gipitch |
| 54 |
;;; run the panel |
| 55 |
FLrun |
| 56 |
|
| 57 |
|
| 58 |
instr 1 ; trigger play/stop |
| 59 |
;;; is the play/stop button on or off? |
| 60 |
;;; either way we need to trigger something, |
| 61 |
;;; so we can't just use the value of gkplay |
| 62 |
kon trigger gkplay, 0, 0 |
| 63 |
koff trigger gkplay, 1, 1 |
| 64 |
;;; if on, start instr 2 |
| 65 |
schedkwhen kon, -1, -1, 2, 0, -1 |
| 66 |
;;; if off, stop instr 2 |
| 67 |
schedkwhen koff, -1, -1, -2, 0, -1 |
| 68 |
|
| 69 |
endin |
| 70 |
|
| 71 |
instr 2 |
| 72 |
|
| 73 |
;;; paused or playing? |
| 74 |
if (gkpause == 1) kgoto pause |
| 75 |
kgoto start |
| 76 |
pause: |
| 77 |
;;; if the pause button is on, skip sound production |
| 78 |
kgoto end |
| 79 |
start: |
| 80 |
;;; get the length of the analysis file in seconds |
| 81 |
ilen filelen "beats.pvx" |
| 82 |
;;; determine base frequency of playback |
| 83 |
icps = 1/ilen |
| 84 |
;;; create a table over the length of the file |
| 85 |
itpt ftgen 0, 0, 513, -7, 0, 512, ilen |
| 86 |
;;; phasor for time control |
| 87 |
kphs phasor icps * gkstr |
| 88 |
;;; use phasor as index into table |
| 89 |
kndx = kphs * 512 |
| 90 |
;;; read table |
| 91 |
ktpt tablei kndx, itpt |
| 92 |
;;; use value from table as time pointer into file |
| 93 |
fsig1 pvsfread ktpt, "beats.pvx" |
| 94 |
;;; change playback pitch |
| 95 |
fsig2 pvscale fsig1, gkpch |
| 96 |
;;; resynthesize |
| 97 |
aout pvsynth fsig2 |
| 98 |
;;; envelope to avoid clicks and clipping |
| 99 |
aenv linsegr 0, 0.3, 0.75, 0.1, 0 |
| 100 |
aout = aout * aenv |
| 101 |
out aout |
| 102 |
end: |
| 103 |
|
| 104 |
endin |
| 105 |
|
| 106 |
|
| 107 |
instr 10000 ; kill |
| 108 |
|
| 109 |
exitnow |
| 110 |
|
| 111 |
endin |
| 112 |
|
| 113 |
</CsInstruments> |
| 114 |
|
| 115 |
<CsScore> |
| 116 |
i1 0 10000 |
| 117 |
e |
| 118 |
</CsScore> |
| 119 |
|
| 120 |
</CsoundSynthesizer> |