syncgrain — Synchronous granular synthesis.


syncgrain implements synchronous granular synthesis. The source sound for the grains is obtained by reading a function table containing the samples of the source waveform. For sampled-sound sources, GEN01 is used. syncgrain will accept deferred allocation tables.

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 table 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 of the table (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.

syncgrain will generate any number of parallel grain streams (which will depend on grain density/frequency), up to the iolaps 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).

syncgrain 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.

syncgrain uses floating-point indexing, so its precision is not affected by large-size tables. This opcode is based on the SndObj library SyncGrain class.


asig syncgrain kamp, kfreq, kpitch, kgrsize, kprate, ifun1, \
      ifun2, iolaps


ifun1 -- source signal function table. Deferred-allocation tables (see GEN01) are accepted, but the opcode expects a mono source.

ifun2 -- 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.


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.


Example 443. Example

iolaps  = 2
igrsize = 0.04
ifreq   = iolaps/igrsize
ips     = 1/iolaps

istr    = .5  /* timescale  */
ipitch  = 1   /* pitchscale */

a1 syncgrain 16000, ifreq, ipitch, igrsize, ips*istr, 1, 2, iolaps
   out       a1


Author: Victor Lazzarini;
January 2005

New plugin in version 5

January 2005.