diskgrain — Synchronous granular synthesis, using a soundfile as source.
diskgrain implements synchronous granular synthesis. The source sound for the grains is obtained by reading a soundfile containing the samples of the source waveform.
asig diskgrain Sfname, kamp, kfreq, kpitch, kgrsize, kprate, \
ifun, iolaps[, ioffset, imaxgrsize]
Sfilename -- source soundfile.
ifun -- grain envelope function table.
iolaps -- maximum number of overlaps, max(kfreq)*max(kgrsize). Estimating a large value should not affect performance, but exceeding this value will probably have disastrous consequences.
ioffset -- start offset in secs from beginning of file (default: 0).
imaxgrsize -- max grain size in secs (default 1.0).
kamp -- amplitude scaling
kfreq -- frequency of grain generation, or density, in grains/sec.
kpitch -- grain pitch scaling (1=normal pitch, < 1 lower, > 1 higher; negative, backwards)
kgrsize -- grain size in secs.
kprate -- readout pointer rate, in grains. The value of 1 will advance the reading pointer 1 grain ahead in the source table. Larger values will time-compress and smaller values will time-expand the source signal. Negative values will cause the pointer to run backwards and zero will freeze it.
The grain generator has full control of frequency (grains/sec), overall amplitude, grain pitch (a sampling increment) and grain size (in secs), both as fixed or time-varying (signal) parameters. An extra parameter is the grain pointer speed (or rate), which controls which position the generator will start reading samples in the file for each successive grain. It is measured in fractions of grain size, so a value of 1 (the default) will make each successive grain read from where the previous grain should finish. A value of 0.5 will make the next grain start at the midway position from the previous grain start and finish, etc.. A value of 0 will make the generator read always from a fixed position (wherever the pointer was last at). A negative value will decrement pointer positions. This control gives extra flexibility for creating timescale modifications in the resynthesis.
Diskgrain will generate any number of parallel grain streams (which will depend on grain density/frequency), up to the olaps value (default 100). The number of streams (overlapped grains) is determined by grainsize*grain_freq. More grain overlaps will demand more calculations and the synthesis might not run in realtime (depending on processor power).
Diskgrain can simulate FOF-like formant synthesis, provided that a suitable shape is used as grain envelope and a sinewave as the grain wave. For this use, grain sizes of around 0.04 secs can be used. The formant centre frequency is determined by the grain pitch. Since this is a sampling increment, in order to use a frequency in Hz, that value has to be scaled by tablesize/sr. Grain frequency will determine the fundamental.
This opcode is a variation on the syncgrain opcode.
Here is an example of the diskgrain opcode. It uses the file diskgrain.csd.
Example 115. Example of the diskgrain opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform ; Audio out Audio in -odac -iadc ;;;RT audio I/O </CsOptions> <CsInstruments> sr = 48000 ksmps = 128 instr 1 iolaps = 2 igrsize = 0.04 ifreq = iolaps/igrsize ips = 1/iolaps istr = p4 /* timescale */ ipitch = p5 /* pitchscale */ a1 diskgrain "mary.wav", 32000, ifreq, ipitch, igrsize, ips*istr, 1, iolaps out a1 endin </CsInstruments> <CsScore> f 1 0 8192 20 1 1 ;Hamming function ; timescale pitchscale i 1 0 5 1 1 i 1 + 5 2 1 i 1 + 5 1 0.75 i 1 + 5 1.5 1.5 i 1 + 5 0.5 1.5 e </CsScore> </CsoundSynthesizer>