/ Examples / Instruments / GrainBuf


Projects .. AudioIO .. Control
NoteStreams .. Instruments
Filters .. Effects .. LiCK Effects
Plot .. Utility .. Pure ChucK


Wherein we delve into the murky details of Fiddle's GrainBuf node

Right-click to copy examples to your workspace

GrainBuf

Wikipedia sez: Granular Synthesis is based on the same principle as sampling. However, the samples are split into small pieces of around 1 to 100 ms in duration. These small pieces are called grains. Multiple grains may be layered on top of each other, and may play at different speeds, phases, volume, and frequency, among other parameters.

The Big Picture

Examples

Example 1

Here's the graph for grainbuf.chg. As it typical with Instrument nodes, the core graph is composed of NoteStream, Player, Instrument and Channel. Here, the CCGenerator Node is used to generate parameter variations. This is quite useful to get a feel for what role individual parameters play.

But at the heart of things is the GrainBuf node and you'll first notice the frightening number of parameters. The best way to confront fear is head-on, so let us dig in.

SoundFile the name of a sound file (.wav or .aif). Click on the viewfile icon to audition the soundfile in Sound Player.

FreqMode determines the interpretation of incoming note frequency:

If you set this to a value other than Ignore you should connect a Remapper Node to cause input MIDI notes (between 0 and 127) to produce a useful range for the targeted parameter.

In this example, Grain Rate with no remapper produces values between approximately .4 and 1.8 for incoming notes between 40 and 80.

GrainSize sets the duration of a grain. Grains are created at the trigger rate and file offset controlled by other params.

Larger grains live longer and therefore increase the likelihood of grain overlap that can cause volume increases (or worse). When the grain size and the trigger size match, only a single grain is alive at a time.

GrainRate combines with TriggerRate to convey the perceived frequency of the sound. You can achieve pitch shifting by increasing the grain rate while holding the phasor rate at one.

GrainRand adds a random amount of grain duration as a percent of the base grain size.

GrainRandFreq represents the frequency (Hz) at which to compute a new grain size. A value of 10 means that we'll compute a new grain size 10 times per second.

GrainPan represents the stereo position of a grain when it's spawned.

GrainPanRange controls the randomness of a grain's stereo position when spawned. Final position combines a random value in this range with the GrainPan value, then constrains it within [-1, 1].

TriggerFreq controls the frequency (Hz) that new grains are spawned. At the moment of creation we 'sample' the current file position (the Phasor) and grain size.

TriggerRange causes randomness (dust) in trigger events. A larger range produces more signal noise.

PhasorStart represents the file position (as pct of file size) to start 'phasing' for grain creation. This couples with Phasor Stop to enable the use of a portion of a sound file as the source for grains.

PhasorStop repesents the file position to stop 'phasing' for grain creation.

PhasorRate is the speed of the file position sampling. At 1, the phasor's "play-head" moves at the natural speed of the file.

Example 2, Pitch Shifter

grainbuf2.chg is just a minor variation on Example 1. It produces more oddball interesting results. We leave it as an exercise to the reader to figure it out.

Example 3, Drone

grainbuf3.chg is a more "musical" example that is built entirely atop the trivial plink.wav soundfile. It also serves as a platform to discover tradeoffs and techniques for processing a stereo signal.

Final Thoughts and a Warning

GrainBuf is really fun to play with. Since its output is fundamentally stereo (ie each grain can be randomly placed in the stereo field) you need to take care to preserve the stereo-ness when sending it through monophonic filters or effects. grainbuf3.chg can be fiddled-with to gain an understanding of the tradeoffs. Headphones are encouraged!

One issue with GrainBuf is that it's relatively easy to overload the system with too-many live grains. This can cause two kinds of problems.

If you don't enjoy the glitchy sounds, your best remedy is to produce fewer live grains by some combination of:

See Also

Wikipedia

Eli Fieldsteel's SuperCollider YouTube vids:

home .. topics .. interface .. reference .. examples .. tipjar