MSP

Customize oscillator behavior

The canonical way to get cyclic "oscillator" behavior is, for every sample number (n), take a step of a certain size (increment) at a certain rate of speed (sample rate) wrapping around to stay within a specific range (length) such that you complete a certain number of cycles (frequency). What you get is an index (x) that you can use to look up values in a table, or as input to an equation, to get a result (y). What should the step size (the increment) be? It’s determined by the formula “increment = n * frequency * length/sample rate”.

Using A Loop to Set Master Tempo

The groove~ object can be used to record a loop on the fly and use the loop length to set a master tempo which can send MIDI clock messages to other machines. The groove~ object sends out its right outlet a signal that goes from 0. to 1. as the current playback location of groove~ goes from its ‘loopstart’ point to its ‘loopend’ point. By default, groove~’s ‘loopstart’ point is 0 and its ‘loopend’ point is the end of the associated buffer~.

Trapezoidal envelope

The trapezoid~ object allows you to make a control signal that rises to a certain level, stays there, then falls back to its initial level. That shape can be ueseful as an amplitude envelope or a filter envelope, for example. At its input trapezoid~ needs to be driven by a signal, usually a control signal that progresses from 0 to 1 in a straight line, such as phasor~ or line~.

Cycle~ phase demo

This patch allows you to see how the phase relationship between two sine waves will affect the shape of the waveform when the two are mixed together. Initially, it shows a 4-Hz sinusoid and an 8-Hz sinusoid that are one-half cycle out of phase with each other. If you change the phase offset of one of the oscillators, you can see that the waves interfere differently, thus changing the shape of the waveform. However, as listeners we're not very sensitive to such changes in phase relationships, except in certain cases where waves cancel each other in extreme ways.

Enable/disable subpatches

The most direct and usually the best way to "turn off" a signal in MSP is to multiply it by 0. However, even if a signal is multiplied by 0, MSP still works to compute that signal. So, if you need to conserve CPU usage, it's best to disable the computation of that signal once it has been silenced, then re-enable it when you want to turn it up again.

Make a buffer larger than the sample it contains

To load a sample into a buffer~ when the sample is shorter than the desired length of the buffer~, use the clear, size, and read messages. You empty and resize the buffer to the size you want, then read in the sound file. For example, you would use this procedure if you wanted to load a three-second sample into a five-second buffer~. The sample will be placed in the first three seconds of buffer space, followed by two seconds of silence.  

MIDI to Frequency

Incoming MIDI control values (0 to 127) from a ctlin object can be scaled with the scale object to cover any desired pitch range (in terms of MIDI pitch number), and that pitch range can then be converted to frequency in Hertz with the mtof MIDI to frequency object.