padenot / ringbuf.js

Wait-free thread-safe single-consumer single-producer ring buffer using SharedArrayBuffer
https://ringbuf-js.netlify.app/
Mozilla Public License 2.0
201 stars 18 forks source link

What's the purpose of the index in ParameterWriter/ParameterReader? #25

Closed chrisguttandin closed 9 months ago

chrisguttandin commented 9 months ago

I noticed that there is an index associated with each value inside ParameterWriter and ParameterReader. I was wondering what it should be used for.

ParameterWriter.enqueue_change() takes an index as the first argument and ParameterReader.dequeue_change() populates the given object with that index.

The ParameterWriter and ParameterReader are used in the main-thread-to-audioworklet example. But the index is always set to 0 on the main thead.

https://github.com/padenot/ringbuf.js/blob/016d963826a63aa715ae0e2d6ccd34f44c093c11/public/example/main-thread-to-audioworklet/app.js#L51

And it's initialized to 0 in the processor, too.

https://github.com/padenot/ringbuf.js/blob/016d963826a63aa715ae0e2d6ccd34f44c093c11/public/example/main-thread-to-audioworklet/processor.js#L12

It seems to be ignored when it reads the new value.

https://github.com/padenot/ringbuf.js/blob/016d963826a63aa715ae0e2d6ccd34f44c093c11/public/example/main-thread-to-audioworklet/processor.js#L24-L26

I can't figure out what it is used for.

padenot commented 9 months ago

It's ignored because there's a single parameter. It's a VST-SDK-style parameter change: each parameter change is a float, and then an index that tells you which parameter has changed. In a real audio effect, you could have a few params, and that would then be useful.

chrisguttandin commented 9 months ago

Ah, I see. That makes sense. Thanks a lot for your answer.