[][src]Struct miniaudio_sys::ma_rb

#[repr(C)]
pub struct ma_rb {
    pub pBuffer: *mut c_void,
    pub subbufferSizeInBytes: ma_uint32,
    pub subbufferCount: ma_uint32,
    pub subbufferStrideInBytes: ma_uint32,
    pub encodedReadOffset: ma_uint32,
    pub encodedWriteOffset: ma_uint32,
    pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1], u8>,
    pub __bindgen_padding_0: [u8; 3],
}

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_voidsubbufferSizeInBytes: ma_uint32subbufferCount: ma_uint32subbufferStrideInBytes: ma_uint32encodedReadOffset: ma_uint32encodedWriteOffset: 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]

Trait Implementations

impl Clone for ma_rb[src]

impl Copy for ma_rb[src]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.