[−][src]Struct miniaudio_sys::ma_rb
Ring Buffer
Features
- Lock free (assuming single producer, single consumer)
- Support for interleaved and deinterleaved streams
- Allows the caller to allocate their own block of memory
Usage
-
Call ma_rb_init() to initialize a simple buffer, with an optional pre-allocated buffer. If you pass in NULL for the pre-allocated buffer, it will be allocated for you and free()'d in ma_rb_uninit(). If you pass in your own pre-allocated buffer, free()-ing is left to you.
-
Call ma_rb_init_ex() if you need a deinterleaved buffer. The data for each sub-buffer is offset from each other based on the stride. Use ma_rb_get_subbuffer_stride(), ma_rb_get_subbuffer_offset() and ma_rb_get_subbuffer_ptr() to manage your sub-buffers.
-
Use ma_rb_acquire_read() and ma_rb_acquire_write() to retrieve a pointer to a section of the ring buffer. You specify the number of bytes you need, and on output it will set to what was actually acquired. If the read or write pointer is positioned such that the number of bytes requested will require a loop, it will be clamped to the end of the buffer. Therefore, the number of bytes you're given may be less than the number you requested.
-
After calling ma_rb_acquire_read/write(), you do your work on the buffer and then "commit" it with ma_rb_commit_read/write(). This is where the read/write pointers are updated. When you commit you need to pass in the buffer that was returned by the earlier call to ma_rb_acquire_read/write() and is only used for validation. The number of bytes passed to ma_rb_commit_read/write() is what's used to increment the pointers.
-
If you want to correct for drift between the write pointer and the read pointer you can use a combination of ma_rb_pointer_distance(), ma_rb_seek_read() and ma_rb_seek_write(). Note that you can only move the pointers forward, and you should only move the read pointer forward via the consumer thread, and the write pointer forward by the producer thread. If there is too much space between the pointers, move the read pointer forward. If there is too little space between the pointers, move the write pointer forward.
Notes
- Thread safety depends on a single producer, single consumer model. Only one thread is allowed to write, and only one thread is allowed to read. The producer is the only one allowed to move the write pointer, and the consumer is the only one allowed to move the read pointer.
- Operates on bytes. Use ma_pcm_rb to operate in terms of PCM frames.
- Maximum buffer size in bytes is 0x7FFFFFFF-(MA_SIMD_ALIGNMENT-1) because of reasons.
PCM Ring Buffer
This is the same as the regular ring buffer, except that it works on PCM frames instead of bytes.
Fields
pBuffer: *mut c_void
subbufferSizeInBytes: ma_uint32
subbufferCount: ma_uint32
subbufferStrideInBytes: ma_uint32
encodedReadOffset: ma_uint32
encodedWriteOffset: ma_uint32
_bitfield_1: __BindgenBitfieldUnit<[u8; 1], u8>
__bindgen_padding_0: [u8; 3]
Methods
impl ma_rb
[src]
pub fn ownsBuffer(&self) -> ma_bool32
[src]
pub fn set_ownsBuffer(&mut self, val: ma_bool32)
[src]
pub fn clearOnWriteAcquire(&self) -> ma_bool32
[src]
pub fn set_clearOnWriteAcquire(&mut self, val: ma_bool32)
[src]
pub fn new_bitfield_1(
ownsBuffer: ma_bool32,
clearOnWriteAcquire: ma_bool32
) -> __BindgenBitfieldUnit<[u8; 1], u8>
[src]
ownsBuffer: ma_bool32,
clearOnWriteAcquire: ma_bool32
) -> __BindgenBitfieldUnit<[u8; 1], u8>
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ma_rb
impl !Send for ma_rb
impl !Sync for ma_rb
impl Unpin for ma_rb
impl UnwindSafe for ma_rb
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,