Play a stream of random grains from a sound file
This patch demonstrates a method for playing a stream of sound grains randomly chosen from a sound file.
This patch demonstrates a method for playing a stream of sound grains randomly chosen from a sound file.
To coordinate the tempo of the transport object with the length of a recorded audio loop, get the duration of the loop in milliseconds, divide it by the number of beats, and divide the result in 60,000 (ms per minute) to calculate the tempo of the transport in beats per minute.
This example shows how to retrieve the total duration in ms of a loaded file in a buffer~, using the info~ object. In fact, because the buffer~ object sends a bang out its right outlet whenever it loads in a sound file, you could use that bang to trigger info~, thus automatically obtaining the duration of any sound file you import.
Preloading sound into random-access memory (RAM)—as opposed to reading it off of a hard disk—allows you more easily to access any point in the sound file instantaneously, read backwards as well as forwards, access different points in the sound simultaneously, etc.
The fact that groove~ can leap to any point in the buffer~ makes it a suitable object for certain kinds of algorithmic fragmented sound playback. In this example it periodically plays a small chunk of sound chosen at random (and with a randomly chosen rate of playback).
The real value of phasor~ is that it provides a very accurate way to read through (or mathematically calculate) some nonlinear shape to use as a control signal (or even as an audio signal). Among other things, it might be used to create a "window" shape that can serve as an amplitude envelope for a sound. This patch demonstrates five different ways to create window or waveform shapes with phasor~. We'll discuss them (in good Max fashion) from right to left.
You can use the play~ object to play the contents of a buffer~, simply by sending it a start message. By default it starts from the beginning of the buffer~. You can specify a different starting time, in milliseconds, as an argument to the start message, or you can specify both a starting time and a stopping time (in ms) as two arguments to the start message. In the patch, you can see two examples of the use of ‘starttime’ and ‘stoptime’ arguments.
In signal processing, a "window" is a function (shape) that is nonzero for some period of time, and zero before and after that period. When multiplied by another signal, it produces an output of 0 except during the nonzero portion of the window, when it exposes the other signal. The simplest example is a rectangular window, which is 0, then briefly is 1, then reverts to 0. The windowed signal will be audible only when it is being multiplied by 1––i.e., during the time when the rectangular windowing occurs.
This example shows one way you might use phasor~ to make the length of an audio sample loop stay precisely synchronized with the beat of the transport.
When you read a sound file into a buffer~ with a read or replace message, the exact amount of time that that operation will take is unknowable, but the buffer~ will send a bang out of its right outlet when the file has been completely loaded into RAM. When you load a file, you should wait for that bang before proceeding.