Quantcast
Channel: KVR Audio
Viewing all articles
Browse latest Browse all 5976

DSP and Plugin Development • Atomic ring/dual buffer implementation?

$
0
0
Hi there,

I'm about to make a basic sampler, which should display the waveform on my own Plot class, processed in the GUI thread.

The samples can be loaded faster, selected by random/cv controller.

In these terms, I need a sort of buffer/structure which I can put in comunication DSP thread (when effectly the sample got the trigger to be loaded) and the GUI thread (which make and draw the waveform).

My idea is:
- load the sample on dsp thread, than create a dto object which contains only the path of the sample, and push to a ring buffer, flagging it as dirty
- on gui thread, check the latest dirty path (if any), load its samples (again) and elaborate the samples, drawing it on a cached panel
- on every gui run, just draw the prev cached panel

Is this a correct scenario?
If so, what I'm looking for is a sort of atomic ring/dual buffer implementation (2 slots should be enough I believe): when I write/read the last pushed element, it must guaranteed the atomicity of the operations (i.e. when I read the x element, I need to write to x+1 only; the same when I write, nobody must start to read the other slot until the writing is finished).

Any already-done implementation out there that I can easily use in c++? Maybe std already have it?

The main request and challenge here is (I bet):
- read only when there are some dirty flag
- ensure to write only on a non-read slot (so overwrite is plausible), and flag dirty at the end
- ensure to read only on a dirty flag, but the problem could be that when I start reading, nobody should write, so maybe 2 slots are not enough...
- all operations lock-free (which is quite mandatory for an audio app)

Thanks for any tips you can give to me :) As usual!!!

Statistics: Posted by Derozer — Mon Jul 08, 2024 7:47 pm — Replies 2 — Views 111



Viewing all articles
Browse latest Browse all 5976

Trending Articles