Here is a csd I’ve had a lot of fun with. It loads a sample into a function table and plays back fragments (that I’ve called grains) by triggering a second instrument. The playback loops. Meanwhile I’ve set up the first instrument to take input from my Novation Launch Control MIDI knobs via ctrl7. With them I can control the grain density, duration, frequency, stereo, but crucially the amount of randomness. If I turn up the randomness, the grains start appearing out of order from the original timing. Of course these controller inputs could just as easily be widgets or envelopes or whatever, but there’s a tactile joy in playing with the knobs.
sr = 44100
kr = 2205
nchnls = 2
nchnls_i = 1
0dbfs = 1
gisamp ftgen 0,0,65536,1,”mysample.aif",0,0,0
;replace with your sound file name of course
;change table size or use deferred table size depending on your sound file
gislen filelen “mysample.aif”
gitlen tableng gisamp
gilplen = 2*sr
instr 1 ; repeats sample while MIDI controllers change playback
knextstart init 0
kcurtime timeinsts
kdur ctrl7 9,21,0,0.5 ; grain duration
koverlap ctrl7 9,22,1,8 ; grain overlap, hence density
kfreq ctrl7 9,23,0.2,5 ; change in sample frequency
krandamt ctrl7 9,42,0,0.1 ; amount of randomness in time passing thru sample
kpanctr ctrl7 9,24,0,0.5 ; change in stereo center
kpanspread ctrl7 9,44,0,0.5 ; change in grain stereo spread
if (kcurtime >= knextstart) then
khop = kdur/koverlap
khopoff gauss krandamt
ksoffamt = krandamt10gitlen
ksoff gauss ksoffamt
kpan gauss kpanspread
kpan = 0.5 + kpanctr + kpanspread
kspos = (abs(ksoff)+kcurtimesr)%(gislensr)
schedkwhen 1,0,9,2,0,kdur,kspos,kfreq,kpan
knextstart = knextstart + khop + khopoff
endif
endin
instr 2 ; play single grain; p4 = start time in table, p5 = freq ratio, p6 = pan
kenv expseg 0.0001,p3/2,0.73,p3/2,0.0001
asig oscil kenv,p5/gislen,gisamp,p4/gitlen
out sqrt(1-p6)*asig,sqrt(p6)*asig
endin
i1 0.1 999
Hi everyone.
I would like to create an algorithm (csd) for which from an audio file:
- can send running only short fragments of the file;
- the fragments of the audio file must have a variable duration each time (included between a minimum and a maximum value);
- the fragments will have to be alternated with pauses also from the variable duration;
- randomize the skiptime value, then at each call a different value (randomic).
Is there any experience on this yet? Is there any idea…?
Thanks for any help,
Enrico
Csound mailing list
Csound@listserv.heanet.ie
LISTSERV 16.5 - CSOUND List at LISTSERV.HEANET.IE
Send bugs reports to
Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here
Bill Alves
Professor of Music, The Claremont Colleges
Harvey Mudd College
301 Platt Blvd. Claremont CA 91711
http://pages.hmc.edu/alves/
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here