granule

granule — A more complex granular synthesis texture generator.

Description

The granule unit generator is more complex than grain, but does add new possibilities.

granule is a Csound unit generator which employs a wavetable as input to produce granularly synthesized audio output. Wavetable data may be generated by any of the GEN subroutines such as GEN01 which reads an audio data file into a wavetable. This enable a sampled sound to be used as the source for the grains. Up to 128 voices are implemented internally. The maximum number of voices can be increased by redefining the variable MAXVOICE in the grain4.h file. granule has a build-in random number generator to handle all the random offset parameters. Thresholding is also implemented to scan the source function table at initialization stage. This facilitates features such as skipping silence passage between sentences.

The characteristics of the synthesis are controlled by 22 parameters. xamp is the amplitude of the output and it can be either audio rate or control rate variable.

Syntax

ares granule xamp, ivoice, iratio, imode, ithd, ifn, ipshift, igskip, \
      igskip_os, ilength, kgap, igap_os, kgsize, igsize_os, iatt, idec \
      [, iseed] [, ipitch1] [, ipitch2] [, ipitch3] [, ipitch4] [, ifnenv]

Initialization

ivoice -- number of voices.

iratio -- ratio of the speed of the gskip pointer relative to output audio sample rate. eg. 0.5 will be half speed.

imode -- +1 grain pointer move forward (same direction of the gskip pointer), -1 backward (oppose direction to the gskip pointer) or 0 for random.

ithd -- threshold, if the sampled signal in the wavetable is smaller then ithd, it will be skipped.

ifn -- function table number of sound source.

ipshift -- pitch shift control. If ipshift is 0, pitch will be set randomly up and down an octave. If ipshift is 1, 2, 3 or 4, up to four different pitches can be set amount the number of voices defined in ivoice. The optional parameters ipitch1, ipitch2, ipitch3 and ipitch4 are used to quantify the pitch shifts.

igskip -- initial skip from the beginning of the function table in sec.

igskip_os -- gskip pointer random offset in sec, 0 will be no offset.

ilength -- length of the table to be used starting from igskip in sec.

igap_os -- gap random offset in % of the gap size, 0 gives no offset.

igsize_os -- grain size random offset in % of grain size, 0 gives no offset.

iatt -- attack of the grain envelope in % of grain size.

idec -- decade of the grain envelope in % of grain size.

iseed (optional, default=0.5) -- seed for the random number generator.

ipitch1, ipitch2, ipitch3, ipitch4 (optional, default=1) -- pitch shift parameter, used when ipshift is set to 1, 2, 3 or 4. Time scaling technique is used in pitch shift with linear interpolation between data points. Default value is 1, the original pitch.

ifnenv (optional, default=0) -- function table number to be used to generate the shape of the envelope.

Performance

xamp -- amplitude.

kgap -- gap between grains in sec.

kgsize -- grain size in sec.

Examples

Here is an example of the granule opcode. It uses the file granule.csd, and mary.wav.

Example 361. Example of the granule 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    No messages
-odac           -iadc     -d     ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o granule.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
kr = 4410
ksmps = 10
nchnls = 2
instr 1
;
k1      linseg 0,0.5,1,(p3-p2-1),1,0.5,0
a1      granule p4*k1,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,\
        p16,p17,p18,p19,p20,p21,p22,p23,p24
a2      granule p4*k1,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,\
        p16,p17,p18,p19, p20+0.17,p21,p22,p23,p24
outs a1,a2
endin


</CsInstruments>
<CsScore>

; f statement read sound file mary.wav in the SFDIR 
; directory into f-table 1
f1      0 262144 1 "mary.wav" 0 0 0
i1      0 10 2000 64 0.5 0 0 1 4 0 0.005 5 0.01 50 0.02 50 30 30 0.39 \
        1 1.42 0.29 2
e


</CsScore>
</CsoundSynthesizer>


The above example reads a sound file called mary.wav into wavetable number 1 with 262,144 samples. It generates 10 seconds of stereo audio output using the wavetable. In the orchestra file, all parameters required to control the synthesis are passed from the score file. A linseg function generator is used to generate an envelope with 0.5 second of linear attack and decay. Stereo effect is generated by using different seeds for the two granule function calls. In the example, 0.17 is added to p20 before passing into the second granule call to ensure that all of the random offset events are different from the first one.

In the score file, the parameters are interpreted as:

Parameter Interpreted As
p5 (ivoice) the number of voices is set to 64
p6 (iratio) set to 0.5, it scans the wavetable at half of the speed of the audio output rate
p7 (imode) set to 0, the grain pointer only move forward
p8 (ithd) set to 0, skipping the thresholding process
p9 (ifn) set to 1, function table number 1 is used
p10 (ipshift) set to 4, four different pitches are going to be generated
p11 (igskip) set to 0 and p12 (igskip_os) is set to 0.005, no skipping into the wavetable and a 5 mSec random offset is used
p13 (ilength) set to 5, 5 seconds of the wavetable is to be used
p14 (kgap) set to 0.01 and p15 (igap_os) is set to 50, 10 mSec gap with 50% random offset is to be used
p16 (kgsize) set to 0.02 and p17 (igsize_os) is set to 50, 20 mSec grain with 50% random offset is used
p18 (iatt) and p19 (idec) set to 30, 30% of linear attack and decade is applied to the grain
p20 (iseed) seed for the random number generator is set to 0.39
p21 - p24 pitches set to 1 which is the original pitch, 1.42 which is a 5th up, 0.29 which is a 7th down and finally 2 which is an octave up.

Credits

Author: Allan Lee

Belfast

1996

New in version 3.35