(max) sample and hold goodness, and some more filter fun

It’s getting late in the semester, and I’m feeling a little punchy.

sample and hold

Sample and hold was/is a common unit generator on advanced analog synthesizers. When triggered, a sample and hold unit will read (sample) and output the value of an arbitrary signal input. If the input is a noise source, sample and hold will provide you with a discrete random value. If the input source is a repeating wave (typically at an LFO rate), sample and hold can give you a (semi) repeating set of values, like an analog sequencer.

Download SampleAndHoldSimple.maxpat.

The demo patch illustrates the two functions described above. In “Pure Bleep Bloop,” a noise source (multiplied by 8000) is connected to the sah~ input. The sah~ object has an argument of 0.01, which is the trigger value. When a control signal in the right inlet rises above 0.01 it will trigger sampling and outputting of a value by sah~. To trigger another value, the control signal must fall below 0.01 and then rise above it again. The sah~ value will be between +/- 8000, or whatever value you type in to the range of random frequency float object. A phasor~ with a frequency of 8 Hz is providing the trigger. The sampled output is going through an abs~ object, converting any negative number to positive. The number then is being fed into the frequency input of a saw~ object, giving you the classic Bleep Bloop sound of random electronic music.

The right hand side of the patch (“Odd Sequencer”) uses a sine tone (cycle~) as a source to be sampled, giving you a type of sequencer. If you type a phasor~ frequency, the corresponding period becomes the frequency of the cycle~. The result sounds like a stepped sine tone. If you adjust the cycle~ frequency to something that isn’t the period length of the trigger, you start to get a repetitive pattern of frequencies. If the frequency of cycle~ divides evenly into the trigger/phasor~ frequency, a single repeated pattern will be heard. If the cycle~ frequency doesn’t divide equally into the trigger frequency, a series of related patterns emerge. Each will be similar (the up/down motion of the wave), but the non-equal division will leave you with a remainder amount that will throw sampling off a bit for each pattern, until the two values sync after the appropriate times through.

applying sample and hold to filter control

Download filterSaH.maxpat. Sample and hold functions are being used to control gain and center frequency to a reson~ object (a resonant bandpass filter).  One set of controls links the slope change time between value changes to the period length of the trigger frequency. The other set of controls allows for independent control of the slope time, which can be set to short time values and create “popping” effects. The radio buttons control which set of control inputs pass to reson~.

A word of note. The radiogroup object is finicky when it comes to changing properties. To change the number of buttons displayed, open the inspector, change the number elements, then click on the items enabled value list so that it updates.

biquad~, filtergraph~, and taking the sharpest edge off the degrade~ object

Download WavePlayOffsetDistFiltered.maxpat. It contains a nice use of biquad~ and filtergraph~ as a means of filtering out some of the really high frequencies that result from bit degradation. The main body of the patch has been covered before (phase controlled looping playback, with frequency shifting and bit degradation).

biquad~ uses filter coefficients to control a flexible filter equation that can give all types of filtering, with resonant feedback. Since coefficients are not musically easy to use, we need an object that will provide it for us. filtergraph~ provides a graphic interface for setting the filter coefficients. The easiest way to use filtergraph~ and biquad~ is to open up the help patch for filtergraph~ and copy it into your patch (minus the audio input section). It gives you an attrui object to set the filter type, and float objects that can display the changes in the graph, or send changes to the graph.

A word of warning for all feedback filters, be sure to include a “clear” message in your patch. Although it isn’t ridiculously easy to “blow up” a filter, it can happen. Only a clear message will get it working again. And for those of you that might think that “blowing up” a filter could lead to interesting, glitchy sonic results — it doesn’t. When a filter blows up, it simply stops outputting signal.