Rust Audio

Announcement: Real-Time Ring Buffer (rtrb)

I’m sure many of you are aware of this PR that proposes to add a wait-free ring buffer to the crossbeam crate:

You might also have noticed that this PR is now nearly 2 years old and there is no sign of it ever being merged. However, the implementation in this PR is very good and several useful API extensions have been discussed in the PR comments.

In order to be able to use this work (together with the discussed additional API functions), I’ve decided to take the code (with the author’s permission), moved it to a separate repository and implemented the additional API:

I’ve also released it on crates.io (https://crates.io/crates/rtrb) and the API documentation is available at:

I hope this is useful!

If you are used to audio programming in C or C++, you might already have used a ring buffer, like the one from JACK or from PortAudio. My rtrb crate should provide at least the same functionality with similar performance characteristics. If you are missing something, please let me know!

If you find bugs or if you have suggestions for API or implementation improvements, please let me know as well!


And while I have your attention …

If you want to use a rtrb::RingBuffer<f32> with multi-channel (non-interleaved) audio blocks and want to access the channels of each block as slices of slices (i.e. as &[&[f32]] for reading and &mut [&mut [f32]] for writing), you might find another crate of mine useful:

See also https://crates.io/crates/rsor and https://docs.rs/rsor.

For this to work, you should use the rtrb::RingBuffer::with_chunks() constructor, which makes sure that you get each audio block in a single contiguous slice.

BTW, my rsor crate is similar to the vecstorage crate that has already been discussed in this forum, but it has a different API and different requirements on the types that can be used. For the multi-channel block example I mentioned above, the vecstorage crate can be used just as well.

4 Likes

rtrb is really nice since it’s an enabler for lots of things.

I’ll definitely have a look at rsor, it looks like it can be a good replacement of vecstorage for my own needs :slight_smile:

This is amazing, thank you so much for your work on this!!