Sample and loop

Mar 22, 2012 at 7:13pm

Sample and loop

While working on something, I needed a way to capture a sample and then loop it, but have the loop length dependent on the length of the recording. I whipped up a solution in Gen~ and thought it might be useful for someone else.

– Pasted Max Patch, click to expand. –
Mar 22, 2012 at 7:57pm

Fantastic bit of code. I just added functionality for length of loop and a reverse button.

– Pasted Max Patch, click to expand. –
Mar 22, 2012 at 11:15pm

Also wouldn’t be hard to add in a rate control (just multiply the sample playback increment before %). fun stuff

Mar 22, 2012 at 11:52pm

Like this?

I seem to get either silence or white noise when speed isn’t 1.

– Pasted Max Patch, click to expand. –
Mar 23, 2012 at 2:02am

It looks very interesting but (I’m a total noob with gen) what is the advantage of doing it in gen~ rather than with the classic groove~ object ?

I’m currently building something for doing, more or less, the same thing and I didn’t think of using gen~

Thanks for any light.

Mar 23, 2012 at 5:58pm

Close, but the * should go before the + actually. You are multiplying the increment amount to change speed. With the speed control, I also switched to a higher-quality interpolation mode so I can buttery smooth slow-downs. Try this:

– Pasted Max Patch, click to expand. –

@Spip The advantage – for me at least – is the ability to have a fairly fine-grained control over how it works, and be able to expand and alter that at will. The groove~ object is a little bit of a black box that just works. Also, with my version, the phase of the loop is in sync with the recording. I could also expand this to do overdubbing with just a few more parts. Also, the @interp options in the Gen~ objects sound really good.

Mar 23, 2012 at 6:46pm

Ah I see where I was going wrong. Sounds great!

I just added a sync output like groove~ and an output for length of sample.

I’m trying to change the start point of the sample though without too much luck.

(it’s getting messy!)

– Pasted Max Patch, click to expand. –
Mar 23, 2012 at 7:12pm

I think this is what you want. This doesn’t protect you from reading past the end of the buffer though, so you might want to further complicate that calculation by scaling the range based on length, or passing through % or something.

– Pasted Max Patch, click to expand. –
Mar 23, 2012 at 7:25pm

Thanks for the explanation !

New homeworks to do :)

Mar 23, 2012 at 9:07pm

Thanks for posting this Andrew. Added a couple of simple things- stop, stutter, restart and overdub. I tried to use splat for the overdub and couldn’t make it work. Could you post an example using splat?


– Pasted Max Patch, click to expand. –

Mar 23, 2012 at 9:50pm

With splat you just divide the play position (in samples) by the buffer size, which you can get from the left outlet of the gen~ buffer object. Otherwise it’s basically the same as poke (from what I can tell), but with linear interpolation if you’re playing at different speeds.

– Pasted Max Patch, click to expand. –
Mar 24, 2012 at 12:12am

>I could also expand this to do overdubbing with just a few more parts

… well… if it isn’t too much bother… I’d sure like to get off and running with a looper like that… :) Pretty please?

Mar 24, 2012 at 1:07am

Here’s a patch with all the above contributions including overdub…

– Pasted Max Patch, click to expand. –
Mar 25, 2012 at 4:56pm


Mar 26, 2012 at 11:58pm

It’s such a privilege to be part of a community with so many smart, creative people. Not to mention generous. Thanks!!!

Mar 27, 2012 at 2:38am

I know how to do this outside of gen~, but is there a way to ramp the attack/release inside gen~ to minimize clicks?

Mar 27, 2012 at 5:32pm

There’s no rule that EVERYTHING has to happen inside the gen~ object. ;) That said, here is a simple way to do linear ramps between 0 and 1 for an A/R envelope. Hope that helps.

– Pasted Max Patch, click to expand. –
Mar 28, 2012 at 1:21am

Thank you, Andrew. :-) Just trying to keep learning all this wonderful new stuff.

Jul 19, 2012 at 6:59pm

Interpolation using [splat] seems to not work when referencing a buffer in reverse….am I doing something wrong, or is this not supported? If not, is there a possibility that it will be, or am I going to have to build something that does this myself? I’m trying to get rid of the need for ipoke~ in my tape looper patch.

Jul 21, 2012 at 7:56pm

Hi Guys, This is a really sweet patch.

I’m trying to fold it into a larger patch and i’m running into a couple noob roadblocks. First I’m trying to convert the gen looper to record in stereo (with the option of then controlling playback of each channel independently) so for example on play back the left channel could play forward and the right channel in reverse, or setting different start and end loop point. different speeds per channel etc…. I tried duplicating the inside of the gen~ changing the inputs on the copy but it’s not wanting to record to a two channel buffer.

The second question is, this will all live in a bpatcher of which i will load several instances of in a parent patcher and I’ve done this before by prefixing names in the bpatcher with #0. but when I try to use the #0 in the gen object to rename the buffer name i get a gen compile error saying that #0_lp is not a valid variable name. So I’m not sure how to get around that.

Thanks for the help and the inspiring code to start with!
Attached is a copy of my hacked version which is not working correctly.

Jul 25, 2012 at 3:58am

Hi there jacobgolden,

There’s a couple of problems with that genpatcher — first of all, the #0- prefixing doesn’t work in gen patchers (and probably never will…). Instead, create a named buffer object (e.g. [buffer mybuf]) and in the parent Max patcher send a message “mybuf #0_lp” to the gen~. Also, [splat] does not support different @interp modes at the moment.

I hope that helps. Here’s the gen~ with those changes made:

– Pasted Max Patch, click to expand. –
Jul 31, 2012 at 9:00pm

Thanks Graham i will check that out and report back. Best!

Jul 9, 2013 at 5:55pm

I tried to modify the patch (Rick’s version with overdub), so the loop will sync to the transport. After a few hilarious attempts, I realized I may need help from people wiser than myself.

Can anyone suggest a way to do this?

Dec 14, 2013 at 1:08pm


But never work overdub for me!!!

Mar 18, 2014 at 2:45pm

i would like to run 6 instances of this simultaneously but do not have gen!

would someone kindly post 6 versions of this that address buffers with different names?

ex. dummy, dummy1, dummy2, etc

thank you so much!


You must be logged in to reply to this topic.