gen~: The Garden of Earthly Delays

After doing a quick tutorial at the Cycling ’74 Expo, it became clear that lots of people out there were really surprised and happy to discover that they didn’t need to be a supergenius to have fun with the gen~ object. While the new Gen stuff is as elegant and powerful as the day is long, you can also have quite a lot of enjoyment with a very few objects. So here’s a sequence of little patches that I hope will give you a window into having some audio fun without scaring the bejeepers out of you. These patches are not impossibly complicated, or efficient or elegant – they’re the product of someone at play. I hope they encourage you to play, too. I even added some simple presets to spur your imagination.

Gen need not be Rocket Surgery (although the Rocket Surgeons will find much to enjoy, I’m sure), but there are a few simple things that it’ll help to know when looking at these patches.

  1. The flow of data inside the gen~ object is like MSP in that it’s synchronous, but instead of thinking of performing some action on a block of samples, we’re working with one sample at a time – which lets us do things with single-sample feedback that we could never do before.
  2. The flow of data inside the gen~ object is constant – there isn’t anything like a trigger, for example. It also means that gen~ operators are always sending something out – a signal sample value, a parameter value, or the result of a test of some kind. We need something special that lets us control our patch with messages from the “outside world.” In the Gen world, we have the param (parameter) operator to do that. You’ll see it in use here.
  3. Since data is always synchronous, a feedback loop isn’t really possible. Instead, we have an operator called history that acts like a single-sample delay that lets us create feedback loops for useful things like data smoothing and… well… feedback.
  4. One difference you may notice between Gen objects and their Max cousins has to do with the relationship between arguments to a Gen operator and the number of inlets the operator has. Unlike Max object, using arguments to specify an initial value for a Gen operator changes the number of inlets an object has – that’s because those initial values cannot be changed once specified. Here’s a simple example of that relationship using the mixer object, which we’ll be making good use of in just a minute. 

Ring Tones

Okay. Let’s get down to business!

This tutorial is going to be about manipulating delay lines. Since the gen~ object gives us access to audio on a per-sample basis – and thus lets us set feedback loops that are tighter than the signal-vector variety that MSP provides, there’s a lot of room for creating new sounds.

The first patch drive-by1a.maxpat, demonstrates a few simple features of working with delays (using the delay operator):

Like the MSP tapin~ object, the delay operator at the heart of this patch takes an argument that specifies the length of the maximum delay possible (remember that since we’re working with gen~, that amount is specified in samples). Although the delay operator can take a second argument to set multiple taps, we’ll only need one delay line each for the left and right channels of our stereo gen~ patch. You might want to investigate that for yourself later on.

The other crucial piece of our patch is the mix operator. It not only lets us mix the wet and dry signals for output, but it introduces a way of smoothing data that gen~ aficionados use everywhere. The mix operator takes two input values in the first two inputs, and then outputs an interpolated value based on a value between 0. and 1.0 received in the right inlet. And of course, it works on one sample at a time.

You’ll see the mix operator used in two places – to handle the wet/dry mix of the delayed and non-delayed signals (notice the clip -1 1 operator for waveform hygiene), and to create a mixable delay line. In both cases, we’ve added a param operator that allows us to send messages to the gen~ object to set values by means of messages to our gen~ object. Of course, we could have adding another in operator or two and used the MSP sig~ object to control our patch – you might find that technique more to your liking, in fact.

The wet-dry mix should be pretty straight ahead, but I want to take a minute to consider this generalized example of using the mix operator for feedback and data smoothing. Here’s a generalized example of how to add feedback effects:

The feedback portion of the patch also uses the mix operator along with a param operator to control the balance of the current and previous signal values. Since the Gen environment is synchronous, we can’t connect the output of the mix operator directly to one of its inputs to create a feedback loop. But don’t worry – the Gen history fb 0. operator functions as a single-sample delay line and will allow us to add the mixed signal back to itself (typing an argument into the history operator also lets us specify a starting value of zero for our feedback loop). If you have a specific kind of data smoothing in mind that doesn’t require modication of the amount of the previous signal being mixed in, you can add an argument to the mix object (e.g. mix 0.5) and skip the param object entirely. The clever trainspotter reading this tutorial is probably already thinking, “Hmm. Isn’t that a kind of lowpass filter?”

Yes, it is. And if you spend some quality time in the Gen examples folder, you’ll see some variation of it used quite often.

In the case of our example patch, we’re using this feedback loop twice in the patch – once for the left and right channels. In the case of our example patch, we send the averaged sample values on as output to the wet/dry mix, and also re-inject them into our delay operator. The result is the classic ringing delay line with a damping control. You can use this particular kind of patch for all kinds of useful tasks.

Note: the fold -1 1 operator makes sure that the feedback values never increase above a value of 1.0 or below a value of -1.0 – if they do, they’ll be folded back for the next iteration. It’s a simple way of producing self-regulated output.

Try the patch with a variety of different kinds of input audio files – some things will sound interesting, some won’t (that’s because an algorithm is never an automatic guarantee of interesting output unless you’re a hard-core formalist).

gen~: The Garden of Earthly Delays

Nov 7, 2011 at 11:46pm

ha! nice one.
looking forward to how this is used for visuals.

#260632
Nov 8, 2011 at 3:56am

Fantastic stuff.

#260633
Nov 10, 2011 at 5:43pm

I was hoping for a Gen~ tutorial but the patches are a real bonus – thanks!

#260634
Nov 11, 2011 at 8:38am

There is a gen~ tutorial in the works. Tutorials take a lot longer to do than my having a nice time and trying to briefly explain the whys and wherefores. It is definitely in the works, and we appreciate your patience, as ever.

#260635
Nov 15, 2011 at 11:17am

gen~ is a really huge world itself.
I cannot wait for grabbing output source code :p

#260636
Nov 29, 2011 at 5:50am

Thanks for sharing this, truly wonderful. PS: In the fourth patch, the gate outlet 4 (“other side”) goes to the same inlet twice for the last gate.

#260637
Mar 7, 2012 at 1:01pm

Gregory your writing has always been amazing.

#260638
Jul 24, 2012 at 10:18pm

Humm. When I open the patches downloaded for this tutorial they do not look anything like the ones given in the above example.

#260639
Jul 25, 2012 at 4:14pm

Ah! Never mind that last message. I’m new to MaxMspJitterGen world and I’m still stumbling around.

#260640
Nov 23, 2012 at 6:49pm

Within a few minutes I was making big nasty phasor patches that sounded awesome. Loving it!

#260641
Mar 8, 2013 at 9:50pm

I’ve tried downloading these patches a couple times now and they don’t seem to open for me. Even if Max is already running, when I try to open the patches, Max just shuts down. Is there a way to fix this?

#260642
Mar 9, 2013 at 12:38pm

Platform? OS version? Max Version? I just downloaded the package and everything runs perfectly well on a 10.7.5 Mac running Version 6.1.0 (ee85fad) at 32-bit. Everything in the patch is vanilla gen~ So I can’t reproduce your difficulties. What’s your system like?

#260643
May 20, 2013 at 6:54am

simple question: why connecting the feedback directly from mix causes delay explosion (like as having feedback=1), I can’t understand the difference with the choice of connecting from the history operator.
thanks

matteo

#260644
Aug 13, 2013 at 4:04am

This is explained : gen works in a synchronous way, that’s why you have to use history.p

#260645
Feb 4, 2014 at 8:55pm

When you say “lowpass filter”, are you talking in terms of EQ? If so, I don’t get it. If not, what are you talking about?

#280119
Feb 5, 2014 at 5:27am

When you say “lowpass filter”, are you talking in terms of EQ? If so, I don’t get it. If not, what are you talking about?

Yes he is. I mean what does “in terms of EQ” mean? It’s just a lowpass filter, feed audio throught it and you’ll see. It is, to be more specific a simple IIR onepole lowpass of the form
y[n]=x[n]*a + y[n-1]*b
where a=1-b
and b= the param weighted_average

#280142
Feb 8, 2014 at 9:31pm

I’ll take your word for it. The math is beyond me. I did try the example on this page and I did hear the result. So I got that going for me.

#280442
Feb 9, 2014 at 4:19am

no, common, the math is not beyond you, sorry for stating this a bit short.
take the simplest FIR filter, a moving average:
take the input sample,
the last input sample,
add them, multiply by 0.5.
moving average right?
that would be: y[n]=(x[n]+x[n-1])*0.5
This is exactly the same, but kind of infinite :)

#280465
Feb 9, 2014 at 7:06am

hm. fir is frequency impulse response right ? so what’s the link with a moving average ?

#280472
Feb 9, 2014 at 2:57pm

no, a fir filter is a Finite imulse response filter, so a filter whose response to a finite signal is always finite. == no feedback.

I’m not entirely sure about the definition and don’t want to talk too sophisticated blabla but I think this is mostly correct:
(discrete)
FIR filter has a finite response to the unit impulse function (=[click~]) always,
A IIR Filter(infinite impulse response) can have an infinte response given the coefficients are set that way. there is feedback.
Analog filters are always IIRs, digital filters can be FIRs. A fir filter would for example be the above. Also buffir~ is a FIR filter. A FIRs impulse response is always equal to it’s coefficients, if you look that up, that’s pretty logical.

IIRs in max are for example the [biquad], [onepole], [slide] etc..

edit: wanted to be correct here..

#280520

You must be logged in to reply to this topic.