In order to enable and disable portions of an audio program easily, and to be able to reuse them multiple times, you will probably want to encapsulate an entire audio-generating or audio-processing procedure inside a single patch with inlets and outlets so that it can be used as a subpatch object in some other patch. This patch shows an example of a simple 2-oscillator frequency modulation tone generator that could easily be used as a subpatch in some other patch.
This example shows my preferred method for changing between different fixed delay times. It's an abstraction that I regularly use when I want a simple delay, and want the ability to change the delay time with no clicks or pitch changes. It's designed as an abstraction so that it can be used as an object (a subpatch) within any other patch.
Any given MSP patch cord represents a single channel of audio. If you want to generate or process multiple sounds or channels, you need to treat each sound or channel separately. For example, each sfplay~ object can have multiple loaded sound cues so that it's ready to play any one of several files, but it can only play one sound file at any given instant. And if it's a stereo file you need to treat each channel separately for mixing, processing, etc. This patch demonstrates that.
The rampsmooth~ object is useful for smoothing MSP signals, a sort of lowpass filter, especially appropriate for smoothing out overly sudden changes in control signals. The left part of this patch demonstrates the fact that internally rampsmooth~ is just doing linear interpolation. Whenever the input signal changes, rampsmooth~ heads toward that value from wherever it currently is, using the specified number of samples (depending on whether it has to increase or decrease) to get there.
The live,gain~ object is terrific for volume control of audio signals. It allows you to attenuate the volume down to -70 dB (by default), at which point it turns the volume completely to 0. In addition to the user-interface fader that live,gain~ provides, you can set the volume with a float message, in decibels, and it will quickly interpolate (in 10 ms by default) to the new volume to avoid clicks due to sudden changes.
In analog electronics, a sample-and-hold device does what its name implies, it takes a sample of the voltage coming into it at a precise instant, and holds that voltage as a constant output signal. The sampling is commonly done at regular intervals, controlled by a clock, but the it can be done in response to any triggering control signal. In MSP, the sah~ object works this way.
The Fast Fourier Transform (FFT) is a mathematical procedure for converting a time-domain signal (such as a sound wave) into an equivalent frequency-domain representation (the sound’s spectrum). The inverse transform (IFFT) reverses that process. The Max object pfft~ allows you to encapsulate an FFT and IFFT (with the objects fftin~ and fftout~ respectively) and program some sort of frequency-domain processing (alteration of the spectrum) between the two.
This patch is an abstraction for panning a sound source among four speakers arranged in a row—or more precisely, in an equidistant arc—in front of the listener. The sound’s virtual location in the stereo field, from extreme left to extreme right, is specified as a control signal value from 0 to 1. The four speakers define the boundaries of the three regions between them, each of which constitutes one third of the total stereo field.
This patch uses a random number generator to choose a mix of 12 sine tones, play them, and display them as white pixels in a black and white matrix. The 12 sine tones are played with a single object called ioscbank~, which is a bank of interpolating sinusoidal oscillators.
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.