This patch shows the use of sfplay~ to play pre-recorded sound files, the use of gain~ to control their loudness, and a few other features of controlling soundfile playback in MSP.
This patch demonstrates how to use gain~ to smoothly scale a signal.
In the I/O Mappings window within the Audio Status… window you can map the outputs numbered 3-16 to play through outputs 1 or 2 of your available stereo output device (say, Built-In Audio, for example). This allows for testing patches on hardware that has less than the desired number of channels.
This example shows different ways to interpolate between values, for the purpose of automating volume control.
To sync an LFO to the onset of a note, drive it with a phasor~ object. Send a phase value of "0" into the right inlet of phasor~ when the note starts, as seen in this example.
The way we commonly avoid clicks when changing the amplitude of a sound is to interpolate smoothly sample-by-sample from one gain factor to another, using an object such as line~. Does that same technique work well for making a smooth change from one delay time to another? As it turns out, that's not the best way to get a seamless unnoticeable change from one delay time to another, because changing the delay time gradually will actually cause a pitch shift in the sound.
For this example to work properly, you must first download "Abstraction for mixing or crossfading two audio signals" and save it with the name xfade~.maxpat. Then you must ensure that your xfade~.maxpat file is in the Max search path, or you must save this example patch in the same folder as the xfade~.maxpat file and reopen it, so that this patch can find the xfade~ object.
This shows how to prepare multiple sound cues for playback, and how to detect specific keystrokes in order to trigger the sound cues. It also shows how to initialize a program by triggering certain messages as soon as the patch is opened. The sound signal is sent through a multiplier to adjust the gain (volume).
This example consists of a .zip archive of files. Together they demonstrate the idea of organizing one’s sound files in a specific folder, and then using the full path to that folder to ensure finding the sound files when you want to play them.
Synthesizing a sinusoid in MSP is a fairly trivial matter, because the cycle~ object does most of the work for you. It produces a full-amplitude waveform at the requested frequency ƒ and with the requested phase offset φ.