How to save audio when buffer cycles over end point

Stew Day's icon

Hi all,

I've been working on a patch that will become part of a personal Max For Live plugin. Basically it's a circular buffer that I can use to "grab" any interesting ideas that come up while noodling on guitar.

I'm using poke in gen to write to the buffer and then groove~ to playback the buffer once captured/stopped.

I then want to be able to use groove's loop points to tidy up my capture - I may only want the last few seconds of a 2 minute buffer for example. I crop the buffer to the loop start/end points and save it to disk.

This is all working well, except when the piece I'm wanting to save overlaps the end point of the buffer. In that scenario I can't set the loop start and end points because the start is at a later time than the end.

Hoping someone can guide me toward a solution.

I have searched on this without much success - there was a post from a few years back that is definitely describing the same issue, where the solution offered used a phasor~. But the level of discussion on that post was WAY over my head!

I should mention that I'm pretty new to Max and have no DSP background so I may need things explained in childlike detail!

Hopefully I've attached the patch correctly (looks like it).

Much appreciate any thoughts you can offer.

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

you use circular buffer ...

why not stutter~ ?

it keeps last length of set size and can copy a portion

to edit buffer when wanted.

I think it shoud serve better for what you want

then gen & circular buffer.

If you don't want that, then you could rotate or copy 2 buffer~ portions

to another buffer to have recording as you want.

Roman Thilenius's icon

the circular (and or scrolling-) buffer in max is called tapin~, it is just not so obvious how to control it and cannot write to disk itself.

Source Audio's icon

tapin - out is useless for anything else than just delay effect

Stew Day's icon

@Source Audio ... thanks, I had a quick look at stutter~ in Max docs. So it's more like a snapshot of n number of samples? That sounds like a cleaner solution than a circular buffer. I'll have a look at the example in Max and see what I can come up with.

@Roman ... thanks for your thoughts too. I can/have seen how tapin~ works as a circular delay line, but how would I define the in/out points for the audio I want to save?

With my current solution I can see what's in the buffer and adjust loop points - the only problem being when the audio runs over the buffer end point).

Happy to try both stutter and tapin/out just to get more experience, but I might need some more direction please Roman :)

Wil's icon
"grab" any interesting ideas that come up while noodling on guitar.

You don't need precision here -

What Roman said is easy way

you can capture any portion of looping groove~

Max Patch
Copy patch and select New From Clipboard in Max.

after that - if you want to save - send your looped portion to record~

Source Audio's icon

Help file of stutter~ is not really helpfull.

Don't bother with tap stuff, it is useless for your usage.

circular only means that buffer gets overwritten in a loop,

which any object like record~ can do ...

or count~ / poke~ , etc.

Stutter should get assigned max samples

just like your current buffer size,

you can start/ stop capturing of audio any time, and also export last number of samples

you want (or whole size) into set buffer.

You could resize it before copying, but maybe you

rather want to precisely select and crop it.

in case you need a help getting stutter to work, just post...

Stew Day's icon

Thanks all ... plenty to dig into here. Going to try both options and see what I can make sense of.

Jeez Wil, is that from the docs or something, or did you just knock that up? The commenting is super helpful - really appreciated.

Wil's icon

The groove~ part is from help file-

tapin~ / tapout~ is as you say “knocked up”

Regardless of what you do, it’s good to comment things here on forums

//

Source Audio will give you rock solid solutions every time :)

//

I use RNBO these days in lieu of tapin~ / tapout~

delay~ / feedback~ -> export external-> mc.***.feedback.delay @chans ** - (sample accurate)

//

Uhm yeah there’s some sh*t under the hood in Max that will blow your mind

//

Nothing beats noodling though! Nothing. Ever ;)

Stew Day's icon

I think stutter~ is going to be best suited for what I'm wanting.

I had a look through the forums for stutter~ because, as you said Source Audio, the max help example is not very helpful :)

I ended up finding a patch you did a few years back on the One Button Sampler thread. After playing around with it for a bit I can see that this already does more than what I was looking for!

After triggering the patch, the samples saved with stutter~ are sent to a buffer and then poke~ continues to record into that buffer from that point onwards (the example was 5 secs). Then when the trigger is deactivated it writes the whole buffer, pre & post trigger to disk. Very clever.

I'm in two minds now whether I need that option (to keep recording) or whether I just want the pre-record samples. I think I'll just add an extra trigger that just sends stutter~ to the buffer and ignores the continue recording with poke~ part, then I can try both. Once I've had a play with it for a while it'll be more clear which one I need (or maybe both!).

Thanks again everyone for your input.

Source Audio's icon

Glad if that old example helped you.

but it was for a bit different scenario.

You can just keep stutter going, while exporting current

captured audio, and then crop-write etc if needed.

In the background stutter~ keeps going ...

in fact I don't know how to stop it, unless one

puts it into subpatch and disable dsp for it.

one can play with setbuf message to switch between buffers

if that can help with te logic of the patch.

Stew Day's icon

It helped a lot :)

I’ve learned so much from this conversation and just exploring examples.

I’ve got a better sense of what stutter can do now and will play around to find out what I like

So many possibilities