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

Does ringbuf.js support infinite input stream? #6

Closed guest271314 closed 3 years ago

guest271314 commented 3 years ago

Contribute Please do (just open an issue or send a PR).

I am currently beginning with 3 seconds storage in a WebAssembly.Memory instance and calling grow() when data arrives in a ReadableStream the form of Uint8Array from WebTransport.incomingUnidirectionalStreams.getReader() (Uint8Array(512) => Uint16Array(Uint8Array.buffer) => Float32Array(128)) for AudioWorklet process().

Ideally I want to begin with the same 3 seconds of memory allocation https://github.com/guest271314/webtransport/blob/4de2842fed22b98cc8c7fd813b27219aa5f1b666/webTransportAudioWorkletWebAssemblyMemoryGrow.js#L8 (if necessary N seconds or N minutes of storage can be allocated) and overwrite the same 3 seconds when the last frame of initial 3 seconds is set at outputs to implement an infinite stream without the current approach of writing to maximum of WebAssembly.Memory (SharedArrayBuffer), for an infinite stream, a proof-of-concept radio station.

Does ringbuf.js provide the means for the above use case?

If yes, can an example be published in this repository?

padenot commented 3 years ago

It's a ring buffer, so yes. The existing example is essentially that, writing a sine wave continuously to the buffer from the main thread and reading from the worklet thread.