-odac
/*
LIVE GRANULAR SYNTHESIS
*/
;example for CsoundQt
;written by joachim heintz
;jan 2010 / june 2011
;please send bug reports and suggestions
;to jh at joachimheintz.de
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1
giWin1 ftgen 1, 0, 4096, 20, 1, 1 ; Hamming
giWin2 ftgen 2, 0, 4096, 20, 2, 1 ; von Hann
giWin3 ftgen 3, 0, 4096, 20, 3, 1 ; Triangle (Bartlett)
giWin4 ftgen 4, 0, 4096, 20, 4, 1 ; Blackman (3-term)
giWin5 ftgen 5, 0, 4096, 20, 5, 1 ; Blackman-Harris (4-term)
giWin6 ftgen 6, 0, 4096, 20, 6, 1 ; Gauss
giWin7 ftgen 7, 0, 4096, 20, 7, 1, 6 ; Kaiser
giWin8 ftgen 8, 0, 4096, 20, 8, 1 ; Rectangle
giWin9 ftgen 9, 0, 4096, 20, 9, 1 ; Sync
giLiveBuf ftgen 0, 0, 16384, 2, 0 ; buffer for writing and reading live input
giDisttab ftgen 0, 0, 32768, 7, 0, 32768, 1 ; for kdistribution
giCosine ftgen 0, 0, 8193, 9, 1, 1, 90 ; cosine
giMaxGrLen = 0.1 ; maximaum grain length in seconds
opcode PartikkelSimpB, a, iakkkkkkkiii
/* Simplified Version of the partikkel opcode, with a time pointer input.
ifiltab: function table to read
apnter: pointer in the function table (0-1)
kgrainamp: multiplier of the grain amplitude (the overall amplitude depends also on grainrate and grainsize)
kgrainrate: number of grains per seconds
kgrainsize: grain duration in ms
kdist: 0 = periodic (synchronous), 1 = scattered (asynchronous)
kcent: transposition in cent
kposrand: random deviation (offset) of the pointer in ms
kcentrand: random transposition in cents (up and down)
icosintab: function table with cosine (e.g. giCosine ftgen 0, 0, 8193, 9, 1, 1, 90)
idisttab: function table with distribution (e.g. giDisttab ftgen 0, 0, 32768, 7, 0, 32768, 1)
iwin: function table with window shape (e.g. giWin ftgen 0, 0, 4096, 20, 9, 1)
*/
ifiltab, apnter, kgrainamp, kgrainrate, kgrainsize, kdist, kcent, kposrand, kcentrand, icosintab, idisttab, iwin xin
/*amplitude*/
kamp = kgrainamp * 0dbfs
/*transposition*/
kcentrand rand kcentrand; random transposition
iorig = 1 / (ftlen(ifiltab)/sr); original pitch
kwavfreq = iorig * cent(kcent + kcentrand)
/*pointer*/
kposrand = (kposrand/1000) * (sr/ftlen(ifiltab)); random offset converted from ms to phase (0-1)
arndpos linrand kposrand; random offset in phase values
asamplepos = apnter + arndpos
/* other parameters */
imax_grains = 1000; maximum number of grains per k-period
async = 0; no sync input
awavfm = 0; no audio input for fm
aout partikkel kgrainrate, kdist, idisttab, async, 1, iwin, \
-1, -1, 0, 0, kgrainsize, kamp, -1, \
kwavfreq, 0, -1, -1, awavfm, \
-1, -1, icosintab, kgrainrate, 1, \
1, -1, 0, ifiltab, ifiltab, ifiltab, ifiltab, \
-1, asamplepos, asamplepos, asamplepos, asamplepos, \
1, 1, 1, 1, imax_grains
xout aout
endop
opcode ShowLED_a, 0, Sakkk
;shows an audiosignal in an outvalue channel, in dB or raw amplitudes
;Soutchan: string as name of the outvalue channel
;asig: audio signal to be shown
;kdispfreq: refresh frequency of the display (Hz)
;kdb: 1 = show as db, 0 = show as raw amplitudes (both in the range 0-1)
;kdbrange: if idb=1: which dB range is shown
Soutchan, asig, ktrig, kdb, kdbrange xin
kdispval max_k asig, ktrig, 1
if kdb != 0 then
kdb = dbfsamp(kdispval)
kval = (kdbrange + kdb) / kdbrange
else
kval = kdispval
endif
if ktrig == 1 then
outvalue Soutchan, kval
endif
endop
opcode ShowOver_a, 0, Sakk
;shows if asig has been larger than 1 and stays khold seconds
;Soutchan: string as name of the outvalue channel
;kdispfreq: refresh frequency of the display (Hz)
Soutchan, asig, ktrig, khold xin
kon init 0
ktim times
kstart init 0
kend init 0
khold = (khold < .01 ? .01 : khold); avoiding too short hold times
kmax max_k asig, ktrig, 1
if kon == 0 && kmax > 1 && ktrig == 1 then
kstart = ktim
kend = kstart + khold
outvalue Soutchan, kmax
kon = 1
endif
if kon == 1 && ktim > kend && ktrig == 1 then
outvalue Soutchan, 0
kon = 0
endif
endop
instr 1; master instrument
;;get live input and write to buffer (ftable) giLiveBuf
aLiveInPre inch 1
kingaindb invalue "ingaindb"
kLiveInGain = ampdb(kingaindb)
aLiveInPost = aLiveInPre * kLiveInGain
iphasfreq = 1 / (ftlen(giLiveBuf) / sr); phasor frequency
kfreeze invalue "freeze"; if checked, freeze writing (and reading) of the buffer
kphasfreq = (kfreeze == 1 ? 0 : iphasfreq)
awritpnt phasor kphasfreq
tablew aLiveInPost, awritpnt, giLiveBuf, 1, 0, 1
;;create an instrument for a readpointer which is giMaxGrLen seconds later than the writepointer
event_i "i", 2, giMaxGrLen, -1, iphasfreq
;;show live input
gkTrigDisp metro 10
gkshowdb invalue "showdb"
gkdbrange invalue "dbrange"
ShowLED_a "LiveInPre", aLiveInPre, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "LiveInPreOver", aLiveInPre, gkTrigDisp, 2
ShowLED_a "LiveInPost", aLiveInPost, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "LiveInPostOver", aLiveInPost, gkTrigDisp, 2
;;select shape of the grain envelope and show it
kwinshape invalue "winshape"; 0=Hamming, 1=von Hann, 2=Bartlett, 3=Triangle, 4=Blackman-Harris,
;5=Gauss, 6=Kaiser, 7=Rectangle, 8=Sync
event_i "i", 10, 0, -1, i(kwinshape)+1
outvalue "ftab", -(kwinshape+1); graph widget shows selected window shape
;;triggers i 10 at the beginning and whenever the grain envelope has changed
kchanged changed kwinshape; sends 1 if the windowshape has changed
if kchanged == 1 then
event "i", -10, 0, -1; turn off previous instance of i10
event "i", 10, 0, -1, kwinshape+1; turn on new instance
endif
endin
instr 2; creates the pointer for reading the buffer giLiveBuf
iphasfreq = p4; usual phasor frequency (calculated and sent by instr 1)
kfreeze invalue "freeze"; if checked, freeze reading of the buffer
kphasfreq = (kfreeze == 1 ? 0 : iphasfreq); otherwise use kphasfreq
areadpnt phasor kphasfreq
chnset areadpnt, "readpnt"; sends areadpnt to the channel 'readpnt'
endin
instr 10; performs granular synthesis
;;parameters for the partikkel opcode
iwin = p4; shape of the grain window
ifiltab = giLiveBuf; buffer to read
apnt init 0; initializing the read pointer
kgrainrate invalue "grainrate"; grains per second
kgrainsize invalue "grainsize"; length of the grains in ms
kcent invalue "transp"; pitch transposition in cent
kgraindb invalue "outgaindb"; volume
kgrainamp = ampdb(kgraindb)
kdist invalue "dist"; distribution (0=periodic, 1=scattered)
kposrand invalue "posrand"; time position randomness (offset) of the read pointer in ms
kcentrand invalue "centrand"; transposition randomness in cents (up and down)
icosintab = giCosine; ftable with a cosine waveform
idisttab = giDisttab; ftable with values for scattered distribution
apnt chnget "readpnt"; pointer generated
;;granular synthesis
agrain PartikkelSimpB ifiltab, apnt, kgrainamp, kgrainrate, kgrainsize,\
kdist, kcent, kposrand, kcentrand, icosintab, idisttab, iwin
out agrain
;;show output
ShowLED_a "out", agrain, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "outover", agrain, gkTrigDisp, 2
endin
i 1 0 3600
e
14665903657true2362362369988644{2a56f609-3f3a-49a2-8ef2-04e1041ed49f}true0-3centertop
Lucida Grande
263000255255255noborder10105888666{49b99e1e-2b4b-4aef-b413-95171c64b350}true0-3lefttop
Lucida Grande
143000255255255noborder1011132484148{e39c91d6-a0bd-4681-8dbc-e384493e578c}true0-3lefttop
Lucida Grande
183000255255255border11LiveInPre12016433622{7286a833-c0b0-4f55-8ecc-837453106e15}true0-3out1_post0.000000001.000000000.000000001.000000000.263028320.73076900fill10.00000000jumpnoborder#00FF0002340false000trueLiveInPreOver4541642722{42e31476-6cb3-42b4-a1fd-8f48e76892ac}true0-3outLover0.000000001.000000000.000000001.000000000.000000000.00000000fill10.00000000jumpnoborder#00FF001961412false000trueLiveInPost11624033622{77fcb44e-b9a2-423d-9764-52f01754d96d}true0-3out2_post0.000000001.000000000.000000001.000000000.113489840.59090900fill10.00000000jumpnoborder#00FF0002340false000trueLiveInPostOver4502402722{3e4c2001-fd4f-4b10-bd75-1766b5d1bbde}true0-3outRover0.000000001.000000000.000000001.000000000.000000000.00000000fill10.00000000jumpnoborder#00FF001961412false000true211649328{9dd7688d-d7d4-4863-bbe8-44c1e622f2bd}true0-3lefttop
Lucida Grande
143000255255255noborder10192409729{a6c9d0da-7821-4528-b193-9ee9af3d441f}true0-3lefttop
Lucida Grande
143000255255255noborder10202029331{bdebe2b5-07c1-4f1f-b7cb-d2f29a26a5f8}true0-3lefttop
Lucida Grande
143000255255255noborder10ingaindb12019926026{64de8264-0345-4faf-b16c-4af284a95268}true00-12.0000000012.00000000-7.47692308lincontinuous-1.00000000false518131380215{e748e0c8-197c-4d4d-b893-9501e50ae02b}true0-3lefttop
Lucida Grande
183000255255255border11out52819733824{133bd5e9-655f-4ba7-895d-45c9c8e54eb3}true0-3out0.000000001.000000000.000000001.000000000.683018800.68301880fill10.00000000jumpnoborder#00FF0002340false000trueoutover8631972624{dc5f0c73-a680-4e93-9855-6706fbd5180d}true0-3outRover0.000000001.000000000.000000001.000000000.000000000.00000000fill10.00000000jumpnoborder#00FF001961412false000true525228368105{c385ef49-3efa-4ec3-806a-ff883343cb9c}true0-3-255.00000000scope2.000000001.000000001.000000001.000000000.00000000NoTrigger11354882281{f470cb16-0510-44e6-b6e0-c532a68e3409}true0-3lefttop
Lucida Grande
183000255255255border115291649527{dcc76929-4dec-4912-b228-fcab4a27e75f}true0-3lefttop
Lucida Grande
143000255255255noborder10outgaindb62516415524{2735c656-a8f6-429d-acc3-2fe0db7e078a}true00-12.0000000012.00000000-2.55483871lincontinuous-1.00000000false4439014327{d7297eb9-b0d9-43c7-a5cb-5c71793c04d0}true0-3centertop
Lucida Grande
143000255255255noborder101756214725{ad4914bd-492d-45c0-bb8c-86e98247e37e}true0-3centertop
Lucida Grande
143000255255255noborder10transp1858622232{2a0c5abd-8f05-4f19-8c6e-5ceb8d4572dc}true0-3-1200.000000001200.000000000.00000000lincontinuous-1.00000000false3448110125{078aa6dc-ef57-4db7-949b-c11e729c837a}true0-3centertop
Lucida Grande
143000255255255noborder10grainsize3150617726{8b59f109-6fc3-4138-bb2e-93113fe13a40}true0-31.00000000100.000000001.00000000lincontinuous-1.00000000falsegrainrate2141825225{5df30f9c-f3dd-4ac9-8088-9cf169cd31f5}true001.00000000200.000000001.00000000lincontinuous-1.00000000false37439414327{cc73b249-baad-47fd-9842-b921037d1a6a}true0-3centertop
Lucida Grande
143000255255255noborder10dist36942015225{a142fe2c-da20-4aa8-a13b-0432a4cb6352}true0-30.000000001.000000001.00000000lincontinuous-1.00000000false23848119127{175842e1-79f7-4518-882a-4555834acf3a}true0-3centertop
Lucida Grande
143000255255255noborder10posrand23950926529{bd0a56e7-6873-484a-be88-67c57c0a66f4}true0-30.00000000100.000000001.88679245lincontinuous-1.00000000falsecentrand27558930628{d2da0179-913a-4308-8b92-65f69293814b}true0-30.00000000100.000000000.00000000lincontinuous-1.00000000false27556223425{558f5942-1622-49a1-aeac-5faede2c8d51}true0-3centertop
Lucida Grande
143000255255255noborder102984197129{ac7d4a98-e00c-4c47-9bb6-9bf8591999ce}true00righttop
DejaVu Sans
143000255255255noborder105204189028{f41b248e-80fb-4cb5-a210-eded60c8c325}true00lefttop
DejaVu Sans
143000255255255noborder1069436311528{5d0f4113-a2a8-4f15-872d-d10b174dcf71}true0-3centertop
Lucida Grande
143000255255255noborder10winshape68241414026{35980021-56da-4027-841b-abf660393ab2}true00Hamming0von Hann1Triangle2Blackman3Blackman-Harris4Gauss5Kaiser6Rectangle7Sync88falseftab620476256145{dcb84ff3-5289-475e-813f-db94e34bc296}true0-301.000000001.000000001.000000001.00000000autoautotruetruetruetruetruetruetrue66745116827{2d0fa256-93bd-4690-911d-437222bc7428}true0-3centertop
Lucida Grande
143000255255255noborder1065238918527{fbbd39e2-e473-4455-8e7c-a57724ae5010}true0-3centertop
Lucida Grande
143000255255255noborder104581983031{eecbf48f-983f-4ce5-bdcc-e6b1ae657b20}true00righttop
DejaVu Sans
143000255255255noborder10ingaindb3802007627{a44b45c8-8c22-4c53-9442-75339608f708}true00left
Liberation Sans
140002552552550.00100000-1e+121e+12false08611623031{a5947f34-1e11-490f-bd5d-c543d6e4494e}true00righttop
DejaVu Sans
143000255255255noborder10outgaindb7811637627{52bb78bb-8e63-44a1-a86a-5def867d5311}true00left
Liberation Sans
140002552552550.00100000-1e+121e+12false0grainrate1863907627{c8857f63-c4d2-456d-92df-cf078b7c6525}true00left
Liberation Sans
140002552552551.0000000011000false152freeze5134808759{209e708e-b0c9-4794-b610-fec1096126c8}true00value1.00000000Freeze!/i1 0 10truefalsefalse10grainsize1314817627{9047dd54-fb61-4009-9867-802809da63cd}true00left
Liberation Sans
140002552552551.0000000011000false100posrand4294807627{d9780cbd-e79a-4741-b575-2a2a49790067}true00left
Liberation Sans
140002552552550.0010000001000false0transp1645627627{20a7f015-fe29-40d1-ac20-589371f9685d}true00left
Liberation Sans
140002552552551.00000000-1000010000false0centrand5065617627{0cc8b907-1cb3-425d-b6f5-994a39abb647}true00left
Liberation Sans
140002552552551.0000000001000false0dbrange4212897927{81528aba-64e8-4dc7-b127-daa1434195a2}true00left
Noto Sans
140002552552550.1000000011e+12false03342889029{cc0e0187-e5c9-4b44-b8c0-28d00d45cb89}true00righttop
Nimbus Sans L
143000255255255noborder1014528911027{df57c2f7-4a74-460f-9f7f-b3efb8106306}true00righttop
Nimbus Sans L
143000255255255noborder10showdb2542898028{d09ab184-f4b1-4340-8730-e73b870bcf9a}true00raw amps0dB11falseinchnl1052904727{2fce6993-35f8-4dd7-bedd-f809c0803989}true00right
DejaVu Sans
140002552552551.0000000011e+12false1528910229{df02308f-b978-4275-817e-1ad38c5b30d5}true00righttop
Nimbus Sans L
143000255255255noborder10