The URL for this file is http://www.michael-edwards.org/software/mdegranular/mdegranular.html

mdeGranular~

A Max/MSP external object for multi-channel, multi-voice, multi-transposition granular synthesis

Michael Edwards
Reader in Music Technology
The University of Edinburgh
michael.edwards(at)ed.ac.uk
www.michael-edwards.org

background
Xenakis
object arguments
left inlet
other inlets
transposition algorithm
mdeGranular~ in action
bibliographic sources
downloads

overview

This Max/MSP object performs time granulation of sampled sound in real-time.

Input in the form of a fixed, pre-recorded sample buffer or an incoming signal of user-specified length is used to randomly select segments of sound (grains) whose durations (grain length) may be modified on-the-fly. These grains are (amplitude-) enveloped and reconfigured each time one comes to an end.

The granulation is performed in a user-specified number of streams (also known as (aka) voices or layers): the more streams, the denser and thicker but also the smoother the effect. An increase in streams also implies an increase in processing time and is the main factor affecting real-time performance.

The streams may be subject to transposition whereby a list of semitone values sent to the object forms the set from which a randomly-chosen value is selected for each grain of sound output by the object.

Finally, each grain is routed to a randomly-chosen outlet (the number of which is also user specified) allowing mapping onto an arbitrary number of output channels.

background

Interestingly, when it comes to granular synthesis a shift of focus is made from the wavelike properties of sound to the particulate properties, just as we can look at light in terms of waves or particles (photons).

The granular or quantum technique was first proposed by British physicist Dennis Gabor whose idea was that any sound could be represented by a granular description (Gabor), much in the same way that Fourier postulated earlier that all sound can be described in terms of its constituent sine waves.

Gabor's theory was mathematically proven by Bastiaans in the 1980s (Bastiaans).

In the 1940s, Gabor actually built a granulator based on an optical recording system from a film projector. With this he made experiments with time-stretching/compression and pitch shifting.

Curtis Roads (Roads 1996 and 1978) has done much theoretical, practical, and compositional work in this area; he developed the first computer-based implementation of granular synthesis in 1974 at the University of California.

Roads describes several types of granular synthesis (Roads 1996, pp 168-184) including the following:

Pitch Synchronous Granular Synthesis is a technique designed for the synthesis of tones with one or more formant areas, i.e. this technique is suitable for imitating natural instruments and voices. This is a pitch detection and resynthesis approach combined with filtering.

Quasi-synchronous Granular Synthesis is a stream-based approach with grains following each other after a variable delay. A periodic envelope function applied to sinusoidal grains creates sidebands in the output spectrum that are predictable and therefore useful for deterministic synthesis.

Asynchronous Granular Synthesis is a stochastic process where grains are scattered randomly over a user-determined duration and with user-determined density and frequency content (depending on the waveform used in the grains).

Time Granulation of Sampled Sounds is the technique used in mdeGranular~; it takes the form of a sound shredder, where a larger sampled sound is split into many smaller, enveloped grains and output with varying degrees of randomness (or not) as determined by the user.

Xenakis and Granular Synthesis

The Greek composer Iannis Xenakis (1922-2001) was the first person to postulate a compositional theory based on grains of sound:

"All sound is an integration of grains, of elementary sonic particles, of sonic quanta...All sound, even continuous musical variation, is conceived as an assemblage of a large number of elementary sounds adequately disposed in time." (Xenakis pp. 44-45)

Pithoprakta

Written 1955-56, this is Xenakis's second acknowledged work and an example of what might be called "instrumental granular synthesis."

It is dedicated to Hermann Scherchen who conducted the first performance in March 1957 at the Musica Viva concerts in Munich.

Pithoprakta is scored for 50 instruments: 46 strings, 2 trombones, 1 xylophone, 1 woodblock; each instrument has its own stave (i.e. the strings are not scored in groups or families but individually!).

In this piece Xenakis is interested in "creating mass events out of aggregates of pitches in a systematic way" (Matossian, p. 92), clouds of moving sound material, controlled by the laws of large numbers: Laplace-Gauss, Maxwell-Boltzmann, Poisson, Pearson, Fisher.

"We can control continuous transformations of large sets of granular and/or continuous sounds. In fact densities, durations, registers, speeds etc...can all be subjected to the law of large numbers with the necessary approximations. We can therefore with the aid of means and deviations shape these sets and make them evolve in different directions. The best known is that which moves from order to disorder, or vice versa., it is that which introduces the concept of entropy. We can conceive of other continuous transformations: for example a set of plucked sounds transforming continuously into a set of bowed sounds." (Xenakis, p. 16)

This last transformation type is heard at the very beginning of Pithoprakta where tapping of the bodies of string instruments is transformed into bowing.

[ Sound Example*: Pithoprakta, beginning ]

Concret PH

This was written for performance between two presentations of Varèse's Poème Electronique at the Philips Pavilion (which Xenakis had designed for Le Corbusier) during the Brussels World Fair in 1958.

It was diffused over 400 loudspeakers.

The "PH" of the title refers to the Hyperbolic Paraboloids used in the design of the pavilion and this piece.

A hyperbolic paraboloids are defined in the Merriam-Webster dictionary as "a saddle-shaped quadric surface whose sections by planes parallel to one coordinate plane are hyperbolas while those sections by planes parallel to the other two are parabolas if proper orientation of the coordinate axes is assumed."

An example of Hyperbolic Paraboloids in architectural design can be found at http://www.presidentsmedals.com/Projectdetails.aspx?student_id=0&proj_id=1240&year=2003 a detail of which is presented below:

Another example is here in Edinburgh at George Watson's College Music School (Michael Laird & Partners, 1964)

Using amplified burning charcoal as its source (brief segments of no more than one second duration), Concret PH utilises an early form of granular synthesis, amassing huge quantities of material into "clouds of sound" in similar fashion to the techniques of his instrumental compositions from this period.

Significantly though, it must be noted that the granular effect here is created by tape splicing/mixing techniques: an enormously complex and labourious process.

[ Sound Example*: Concret PH ]

mdeGranular~ object usage

object arguments

The object takes the following arguments:

  1. The number of simultaneous streams (aka voices, layers) of grains (default 1); this is limited only by your computer's CPU power.
  2. The number of output channels (default 1 but unlimited); this will determine the number of signal outlets the object has, i.e. there will be one for each channel you request.

object inlets

left inlet

As with most Max/MSP objects, various data can be sent to the left-most inlet:

other inlets

The rest of the inlets, numbered from left to right, are as follows. The messages which can be sent to the leftmost inlet to accomplish the same thing are in square brackets and are case sensitive.

  1. Transposition offset in semitones (default none): This may be fractional; it is added to the list of transpositions sent to the left inlet (see above), or simply transposes all the grains if no transposition list is given.
    [TranspositionOffsetST]
  2. Grain length in milliseconds (default 50).
    [GrainLengthMS]
  3. Grain length deviation (as a percentage) of the grain length (plus or minus, default 10%); i.e. if anything other than 0, the grain length is randomised by an amount between plus or minus the deviation percentage.
    [GrainLengthDeviation]
  4. The minimum start point in the input buffer (fixed or live) in milliseconds (default 0). The actual start point is a function of the grain length, and the start and end points (see below) and is randomly chosen to fit anywhere within these points.
    [SamplesStartMS]
  5. The maximum end point in the buffer in millisecs (the default is the end of the buffer). N.B if end < start then the buffer will be granulated backwards. If the difference between these two is too small for the ramp up and ramp down to be accomplished, no grains will be output.
    [SamplesEndMS]
  6. The "density" of the grains (as a percentage). 100% means a grain will start immediately every time the previous one ends, 50% means one in two grains (determined randomly) will produce no output. (Default 100%).
    [ Density]
  7. Grain amplitude (>=0 and <= 100, default 0.5). This is a straight amplitude scaler for each gain, i.e. no account is taken of how many voices there are. N.B. when using MIDI faders, the 7-bit step between values is often large enough to create a slight but audible click in output. This is corrected in mdeGranular~ with a step increment between the last and new amplitudes. The side-effect is that new amplitudes will not be accepted for an "audio tick's worth" of samples.
    [GrainAmp]

transposition algorithm

Transposition of digital audio signals in the time domain involves the horizontal stretching (down-sampling) or compression (up-sampling) of sampled waveforms to effectively change the length of the waveform and thus the frequency or pitch (frequency = cycles per second).

This is similar to slowing down or speeding up an analogue tape machine.

The digital technique is usually called sampling-rate conversion (src) because it is the same technique used to change the sampling rate of an audio file whilst keeping the frequency content static.

It involves interpolating samples between those already stored in the audio file, e.g. if a downward transposition of one octave is required, one new sample will have to be interpolated for every stored sample.

There are various methods for finding the best sample, the simplest and fastest of which is linear interpolation. This involves a simple straight-line interpolation from one sample to the next.

Linear interpolation creates various, usually unwanted artefacts in the signal and is not suitable for high quality applications.

mdeGranular~ uses a four-point interpolating table-lookup routine (borrowed from PD) similar but superior to linear interpolation and, presumably, the groove~ object in MSP.

This technique is fast and simple, like linear interpolation (which is of course two-point and therefore faster), but because four neighbouring samples are used in the calculation a more acceptable and "fitting" new sample is created.

Code examples in Common Lisp and C are given for the technique below:


;;; findex is the floating point index from which we want the interpolated ;;; value; samples is a list (or array in C) of the samples. (defun 4pt-interp (findex samples) (let ((index-trunc (floor findex)) fraction a b c d cminusb fp) (if (< index-trunc 1) (progn (setf index-trunc 1 fraction 0)) (setf fraction (- findex index-trunc))) (setf fp index-trunc a (nth (1- fp) samples) b (nth fp samples) c (nth (1+ fp) samples) d (nth (+ 2 fp) samples) cminusb (- c b)) (unless (and a b c d) (error "not enough samples!")) (+ b (* fraction (- cminusb (* (* 0.5 (- fraction 1.0)) (+ (* (+ (- a d) (* 3.0 cminusb)) fraction) (- (- b a) cminusb)))))))) float interpolate4pt(float findex, float* samples) { int indexTrunc = (int)findex; float fraction; float a; float b; float c; float d; float cminusb; float* fp; if (!samples) return 0.0f; if (indexTrunc < 1) { indexTrunc = 1; fraction = 0.0f; } else fraction = findex - (float)indexTrunc; fp = samples + indexTrunc; a = fp[-1]; b = fp[0]; c = fp[1]; d = fp[2]; cminusb = c - b; return (float)(b + fraction * (cminusb - 0.5f * (fraction - 1.0f) * ((a - d + 3.0f * cminusb) * fraction + (b - a - cminusb)))); }

As an example, take the following portion of a cosine wave. In order to transpose it down one octave we want to insert a sample between the second and third points on the curve. The results of linear and four-point interpolation are shown. Clearly the latter technique better approximates the true cosine curve.

Another example is given below, with the cosine wave in a different part of its cycle.

other transposition techniques

Common Lisp Music or CLM (http://ccrma.stanford.edu/software/clm/) uses a custom src algorithm developed by Julius Smith and Perry cook. It involves a user-defined number of neighbouring samples to convolve with a sine function in order to find the best fit for the new sample. This produces a very high-quality transposition but due to the number of calculations needed to produce one sample is not generally suitable for real-time applications.

The MPEX algorithm found in Steinberg's Cubase and Nuendo is a sophisticated and high-quality time-stretching/transposition combination that (apparently) uses psychoacoustic techniques to de-couple these two related processes. This is also not available in real time at present.

FFT-based (frequency domain) transpositions are also possible in a process of analysis/resynthesis (e.g. the phase vocoder). This is generally possible in real time but in the author's experience not as successful as the CLM src unit generator.

mdeGranular~ in action

When performing with mdeGranular~ I usually use several instances of the external in one patch and step through a pre-programmed list of parameter changes for each of the objects.

To date (24.1.05) I have written four pieces using mdeGranular~ for live sound processing.

I will present examples from two of these:

tramontana

tramontana for for scordatura viola and computer was written between 2002 and 2004.

The beginning of tramontana makes use of mdeGranular~ for quiet blurring effects, spreading bowed body noise around an octophonic sound system. It is also used for sample and hold effects and rhythmic interest through the use of three simultaneous loops of different lengths.

[ Sound Example*: live recording of tramontana from 1:13, loops begin c. 2:44 ]

[ Sound Example*: From c. 6:13 there are glissandi, transpositions, loops, and sample and hold techniques in play; from c. 9:40 large live buffers are also combined with long grains for imitative effects ]

skin

skin for 7-string viola da gamba and computer was written between 2003 and 2004.

mdeGranular~ is used in many different ways in this piece, e.g. to create small grain explosions only perceivable as clicks, clouds of highly-transposed longer but still short grains, simple loops, and reverberation effects.

In particular I use three instances of the object in order to create transitions from one gamba playing technique to another by sampling and holding (and mixing) each of them in a granulator.

[ Sound Example*: studio recording of skin from 12:15 ]

downloads

mdeGranular~ archive (external and help file) for Max/MSP on OS X (Universal Binary)
N.B. This ZIP file needs to be unzipped with /System/Library/CoreServices/BOMArchiveHelper in order for resource forks to be preserved. If you get the error "mdeGranular~: no such object" when you open the help file in Max/MSP, unzip the downloaded archive again using the above application.

mdeGranular~ external for Windows Max/MSP
mdeGranular~ help file

bibliographic sources

M. Bastiaans, Gabor's expansion of a signal into Gaussian elementary signals. Proceedings of the IEEE 68: pp 538-539, 1980.

Dennis Gabor, Theory of communication. Journal of the Institute of Electrical Engineers Part III, 93: pp 429-457, 1946.

Nouritza Matossian, Xenakis (New York: Kahn & Averill, 1986).

Curtis Roads, Granular Synthesis of Sound. The Computer Music Journal 2(2): pp 61-72, 1978.

Curtis Roads, the computer music tutorial (Boston: Massachusetts Institute of Technology, 1996).

Iannis Xenakis, Formalized Music (Bloomington, Indiana: Indiana University Press, 1971).

* Please note that this web page was created to accompany a lecture at the University of Edinburgh and that for copyright reasons not all sound examples are available online.

A recording of Michael Edwards' skin is available for download from http://www.sumtone.com/work.php?workid=130