Waveform~ update from right to left in GRM Tools Freeze style

ADwellingOx's icon

Hi,
Does anyone know how I could get waveform~ to stream the contents of a constantly updating buffer backwards?

This is essentially to mimic the GRM Tools Freeze waveform movement.

So the first sample should enter on the right-hand side of waveform~ and then keep shifting toward the left as new samples continue to enter from the right.

Any help would be great.

Roald Baudoux's icon

You should have a second buffer~ just for displaying purposes and fill it backwards. You should use count~ to change the recording position within the buffer. However I think count~ cannot count downwards (I can't check now). You can insert a !-~ object between count~ and poke~ to reverse counting direction.

ADwellingOx's icon

Hi Roald, thanks for the answer.

I tried doing that but that just reverses the buffer which isn't actually what i'm trying to do.

I am trying to get the waveform to enter from the right-hand side and then shift across to the left so that the first sample eventually ends up on the left-hand side. So every new sample that enters will begin on the right side of waveform~ and continually shift across as new samples enter.

Do you know how I could achieve this?
Thanks.

AlexHarker's icon

Try writing working with a double circular buffer (to do this write twice at a constant interval apart in samples into a buffer in a cyclical manner - see patch below), and then, instead of moving things within the buffer, move your read point (or using waveform~ the display points). This will be more efficient than moving stuff around in memory all the time, and more inline with the way one would expect to see it done in a text-based language.

The reason to write twice is that you can then read the maximum circular buffer length (half the length of your actual buffer) contiguously at any time (otherwise it wraps around in the middle).

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

Here's a circular buffer patch that might get you started
The patch is only good up to 2^23 samples (as far as I recall) because a 32 bit float can't exactly represent integers above twice this, and you need to write in two places (halving your maximum size). Whatever size I've used in the patch should work. If you need a longer buffer then you would need to look at the high res (hr) objects by jkc.

HTH

A.

ADwellingOx's icon

Great thanks a lot! Have it working nicely now.