[PD] ring buffer with an array
czhenry at gmail.com
Sun Jan 8 21:14:50 CET 2012
On 1/8/12, Alexandre Torres Porres <porres at gmail.com> wrote:
> Hi folks, I'm trying to implement a ring buffer with a table for a sampler
> patch based on an array.
> But I'm having the hardest time cause it always "clicks" when I start
> writing back on the beginning of the array.
> I made this simple test attached below using metro. But I'm figuring the
> flaw is because is not trivial at all to keep control data in sync with
> audio blocks
> any hints or ideas?
I think you might be better able to keep the data in sync with a
vline~/metro/tabread4~ construction, because it preserves the timing
information in the messages. Instead of vline~/metro, you could also
use phasor~ which makes the looping implicit.
To work around clicks, crossfading is what I hear about the most on
list. I'm not sure how it's implemented.
When I think about coding in C, I always want to have N contiguous
samples to avoid having to check against the end of the array. To do
that, you make the buffer 2*N-1 in length. Then, on each write, you
write to two locations (0,N), (1,N+1), (2,N+2)... That ensures there
is always N samples in a row to read from, and you just move the read
pointer by 1 each time you get a vector of N samples long. (my
personal method...nothing more).
More information about the Pd-list