Creating a 'running' buffer?

Frankdj's icon

The effect I want to create is that when somebody makes a loud noise, a 5 second clip of this sound will be looped for playback (for about a minute) and slowly fade out. This has to be a independent process, so not that I need to hit buttons to control it.

So the way I had this in mind, is that you need a running buffer (of let's say... 2 minutes) that records every sound that comes in, and once a loud sound is being detected, sends out the last -5000ms of the buffer, to a play~ or groove~ object to start looping it in some way.

The problem is that I can't seem to figure out is (1) how to create a running buffer, where it starts overwriting itself once it has reached the 2 minute mark, (2) and how to read out/send out the last 5000ms from this buffer to use it in another object, without stopping the buffer object.

Can somebody help me finding the right keywords, or finding alternate ways to achieve the same effect?

Tim Lloyd's icon

Search the forum for "circular buffer" and "endless resampling" and you'll find all you need to get the first part of the patch going.

Some objects you'll probably use:
count~
poke~
phasor~
thresh~
bonk~ (3rd party)
index~
...

:)

Frankdj's icon

Thanks, the 'circular buffer' problem was quite easy... I just searched the wrong keywords , but now that's fixed.

The 'endless resampling' is more difficult however, I can't find a lot of results (6 total) to help me. I took a look at the objects you describe, but it's hard to connect the individual parts when I don't see the bigger picture. Can you help me a little on getting me started, what is the key to sample the last X seconds from the buffer?

Roman Thilenius's icon

tapin~ tapout~

spectro's icon

Though it seems typically intended for shorter sample segments than what you need, Stutter~ could do something along these lines too. You'd still need to work out a threshold based triggering method though.

Frankdj's icon

@spectro: The patch that activates an action when a certain threshold is reached already works, so it's just about how to get the last X seconds of audio from the buffer once this action is triggered.

@Roman: Using tapin~/tapout~ you're just delaying the sound right? The problem when doing that, is that when somebody makes a loud sound which triggers a delay, you actually don't hear the loud sound itself, but just a delay of what comes after the loud noise. Therefore I want to be able to take the last X seconds of the buffer (lets say 5 seconds in this example) so that I actually can hear this loud sound that triggered it.

Roman Thilenius's icon

you could just use a short delay as "through" to get what you need, so
that you read from the buffer using delay times of 10, 1010, 2010 ms
for example.

it might be perfect like this, as you now also have 10 ms time to look
forward when waiting for the next peak. :)

Frankdj's icon

I guess that would work for the 'clap in your hands' example =) But my intention in the end, is to connect the intensity of the sound, to the duration of the playback of recorded audio.

That's a long way from where I am now, but at least I need a way to read the last XX seconds from the buffer, because the delay trick won't work when I want to read out the last 30 seconds of the buffer I guess? Or doesn't that influence it?

Roman Thilenius's icon

you might try this: make 4 tapin~ buffers and read them out with feddback delays of
different feedback seeetings, then blend between them to change the loop lenght.
(vertikal modulation)

Roman Thilenius's icon

btw, "seeetings" was a typo, but i leave it like it is, it seems to fit perfectly.

Frankdj's icon

Sounds interesting, are there any example projects using this? (since searching the forum and google for 'vertical modulation' doesn't give many results...) Thanks for thinking along so far! =)

Roman Thilenius's icon

vertikal modulation™

^^

means: if it seems difficult or impossible to make up a parameter for a desired
result (here: changing the feedback volume/lenght of a delay without cutting
off the signal currently in the buffer) then use 2 or more states with fixed values
- and fade between them.

the term is my invention™, but you can find this method in the one or other
DSP.
a HRTF FIR filter for a binaural effect would be one example:
there are many different filters lined up in a cirle, but because you cant
have 360 or an infinite number of possible postions, you use like 24
or so static filters and then interpolate between them panorama-style.

-110

Frankdj's icon

One last question then... how do I 'fade' between them? I now created buffers that record with a 0, 5, 30 and 60 second delay but how do I then achieve the effect you describe?

Frankdj's icon

Anyway... I consider this problem *solved* (at least this part of it). The software is still not completely how I want it, but for anyone else out there wanting to read out the last XX seconds of a buffer... here's a solution that will get you started.

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

I connected a line object to the input of a waveform~ object. This means that if you start your patch, the pointer running through the waveform object is always showing realtime the exact moment which the buffer is recording. I created 3 thresholds (low/medium/loud sound) which activate a trigger that extracts the current location of the pointer in the waveform/buffer. So let's say you shout out loud, which activates a trigger, and gives you number 20.000. If you then -for example- create some objects to subtract 5000ms from that number, and put it into the groove~ object, you can define the boundaries where it should playback your sound from the buffer.

Roman Thilenius's icon

can you say "crossfader" ? when one goes down, the other one goes up ...