Page  230 ï~~CSOUND Granular Synthesis Unit Generator Allan S C Lee Queen's University of Belfast Rm 6.8B Ashby Building, Belfast BT9 5AH Northern Ireland Tel: +44 (0)1232 33 5473 Fax: +44 (0)1232 667023 Email: ABSTRACT: Two CSOUND Granular Synthesis Unit Generators have been developed to provide an easy way to compose music with granular synthesised sound. The first unit generator provides low level control of every parameter such as the amplitude, grain size, gap size, pitch shift and envelope. All these parameters can be changed at control rate. The second unit generator provides a high level control. Multiple voices and random offset of parameters are built into the generator. A maximum of 128 voices in each generator is implemented but this can be increased by changing a parameter in the include file. Extremely high grain density can be produced. Stereo or quad output can be produced by using two or four unit generator statements with different seeds for the random number generator. Introduction As described in the paper "Introduction to Granular Synthesis" by Curtis Roads1, the theory of granular synthesis was initially suggested by Dennis Gabor2 back in 1947. Since 1971, many different techniques have been used to synthesize sounds using grains by many authors such as Lippe3, Roads4 and Truax5. These techniques range from dedicated software to custom built digital signal processing hardware. Granular synthesis using CSOUND can be achieved by using conditional statements or a combination of existing unit generators but it is very complicated and a very large orchestra / score file is needed to generate a short output. Two unit generators have been developed to provide different levels of control of synthesis. They are regular CSOUND unit generators which means they can be fully integrated into normal CSOUND compositions. A CSOUND function table is used as source, an unlimited type of sounds ranging from simple FM timbre to sampled sound can be used as the source for the grains. Implementation Granular synthesis can be classified as a form of additive synthesis. A high number of grains are added together to produce output. A grain is a signal with an amplitude envelope and the envelope can be any shape. For computation efficiency, linear attack and decay are implemented. An optional function table for generating different envelope shapes is also implemented. The first unit generator, grainv3, provides low level control of the synthesis. Every parameter such as the amplitude, grain size, gap size, pitch shift, attack and decay of the envelope can be changed at control rate. It produces a single stream of grains with gaps or overlap between successive grains. grainv3 xamp kpshift ifn koverlap kgskip kgsize katt kdec wave table size read in by gen01 in no. of bytes Ikgskip in seconds kgsize in seconds (kgskip + kgsize) * esr <= table size kgsize grain xamp {-katt kdec in% 100% n 0 O<= katt <= 100% 0 <= kdec <= 100% (katt + kdec) <= 100% 230 I C M C P RO C EE D I N G S 1995

Page  231 ï~~A single grainv3 statement will generate a stream of grains as shown below. Multiple grainv3 statements I/ grain\ grain /grainjgrain\grngrain\ gap overlap gap gap gap time can be used in an orchestra file to produce output and different streams can be assigned to different channels for stereo or quad output. The kpshift parameter controls the amount of pitch shift relative to the original sound sample using a time scaling technique with linear interpolation between data points. All k parameters can be modified by a random value generated by the randh unit generator. The second unit generator, grainv4, provides a high level control of the synthesis. Multiple voices and random offset of parameters are built into the generator. Extremely high grain density can be produced with a single grainv4 statement. grainv4 xamp ivoice iratio imode ithd ifn ipshift igskip igskipos ilength kgap igap os kgsize igsize_os iatt idec [iseed] [ipitchl] [ipitch2] [ipitch3] [ipitch4] [ifnenv] wave table size read in by genOl in no. of bytes - I -"" h _igsize_os- I "igskip inseconds kgsize in seconds -- - s digap-s --s p I ilengt/i kgap in seconds gs -ilengthlength of data to be used in seconds ivoice defines the number of voices (streams) to be generated. iratio defines the speed of the sampling pointer moving along the function table. A value of 0.1 will stretch the original sample 10 times. ithd defines the thresholding value; samples in the function table below this value will be skipped. 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 ipitchl, ipitch2, ipitch3 and ipitch4 are used to quantify the pitch shifts. The optional parameter ifnenv defines the shape of the envelope of the grains. The default value is 0 and linear attack and decay is used. A positive value will be interpreted as a function table number and the data stored in the function table is used to generate the attack curve of the envelope. The decay curve will be a mirrored image of the attack curve. iseed defines the seed to be used for the random number generator. For multichannel output, use different iseed values in each grainv4 statements. (Due to lack of space in this paper, full documentation will be available by anonymous ftp) Conclusions and future work The two unit generators have been compiled and tested on Sun, NeXT and SGI workstation. Unfortunately, the process is quite computational intensive, generating a high number of voices is quite time consuming but the results are very rewarding. Very rich harmonic and spatial depth can be achieved by using 20 voices or more per channel. For fast turnover, set ivoice to 20 or less to experiment with different sound sources and parameters; set ivoice to 64 or more for a production run. Different shapes of grain envelope are under test at the moment to study how envelope shapes will affect the output in terms of harmonics and other perceptual factors. Acknowledgements I would like to thank Dr Michael Alcorn and Dr Alan Marsden for their input in designing the generators. Also the Parallel Computer Centre at Queen's University of Belfast for the usage of the SGI Indy cluster. References [1] Roads, C. 1988. "Introduction to Granular Synsthesis." Computer Music Journal 12(2): 11-13 [2] Gabor, D. 1947. "Acoustical Quanta and the Theory of Hearing." Nature 159(1044):591-594 [3] Lippe, C. 1993. "A Musical Application of Real-time Granular Sampling Using the IRCAM Signal Processing Workstation." Proceedings of the 1993 International Computer Music Conference [4] Roads, C. 1978. "Automated Granular Synthesis of Sound." Computer Music Journal 2(2):61 -62 [5] Truax, B. 1988. "Real-time Granular Synthesis with a Digital Signal Processor" Computer Music Journal 12(2): 14-26 ICMC PROCEEDINGS 199523 231