QUICK-REF - CsoundManual - Top of this section - Previous - Contents - Index - Next 

granule

asig    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]

DESCRIPTION

The granule unit generator (Allan Lee) is more complex than grain (above), but does add new possibilities. This is a shorten manual, without the pictures,

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. All parameters with prefix i must be valid at Init time, parameters with prefix k can be either control or Init values.

PERFORMANCE

xamp - amplitude.

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

kgap - gap between grains in sec.

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

kgsize - grain size in sec.

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, seed for the random number generator, default is 0.5.

[ipitch1], [ipitch2], [ipitch3], [ipitch4]- optional, 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.
 

EXAMPLE:

Orchestra file:
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
Score file:
; f statement read sound file sine.aiff in the SFDIR 
; directory into f-table 1
f1      0 524288 1 "sine.aiff" 1 0
i1      0 10 2000 64 0.5 0 0 1 4 0 0.005 10 0.01 50 0.02 50 30 30 0.39 \
        1 1.42 0.29 2
e
The above example reads a sound file called sine.aiff into wavetable number 1 with 524,288 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 decade. 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:

p5  (ivoice) the number of voices is set to 64
p6  (iratio) is set to 0.5, it scan the wavetable at half of the speed
      of the audio output rate
p7  (imode) is set to 0, the grain pointer only move forward
p8  (ithd) is set to 0, skipping the thresholding process
p9  (ifn) is set to 1, function table number 1 is used
p10 (ipshift) is set to 4, four different pitches are going to be
      generated
p11 (igskip) is 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) is set to 10, 10 seconds of the wavetable is to be used 
p14 (kgap) is 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) is 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) are 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 - p 24 are 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.
AUTHOR:

Allan Lee
Belfast
1996 


QUICK-REF - CsoundManual - Top of this section - Previous - Contents - Index - Next 
HTML Csound Manual - © Jean Piché & Peter J. Nix, 1994-97