AudioManager

Struct AudioManager 

Source
pub struct AudioManager { /* private fields */ }
Expand description

You will need to write your own spin loops. For that you can and maybe should use AudioManager::buffer_time.

The Stream API is not “Rusty” and not ergonimic to use, but Stream are often not Send, while the Manager is suited well for being in a Global Mutex. This is why the Stream can’t live inside the Manager. If you can think of a better API i would love to replace this.

Implementations§

Source§

impl AudioManager

Source

pub fn new(song: Song) -> Self

Source

pub fn try_edit_song(&mut self) -> Option<SongEdit<'_>>

If this returns None, waiting buffer_time should (weird threading issues aside) always be enough time and it should return Some after that.

Source

pub fn get_song(&self) -> &Song

Source

pub fn collect_garbage(&mut self)

Source

pub fn try_msg_worker(&mut self, msg: ToWorkerMsg) -> SendResult

Source

pub fn playback_status(&mut self) -> Option<&Option<PlaybackStatus>>

last playback status sent by the audio worker

Source

pub fn buffer_time(&self) -> Option<Duration>

Some if a stream is active. Returns the approximate time it takes to process an audio buffer based on the used settings.

Useful for implementing spin_loops on collect_garbage or for locking a SongEdit as every time a buffer is finished garbage could be releases and a lock could be made available

Source

pub fn get_callback<Sample: Sample + FromSample<f32>>( &mut self, config: OutputConfig, ) -> impl FnMut(&mut [Sample])

If the config specifies more than two channels only the first two will be filled with audio. The rest gets silence.

The callback in for example Cpal provides an additional arguement, where a timestamp is give. That should ba handled by wrapping this function in another callback, where this argument could then be ignored or send somewhere for processing. This Sending needs to happen wait-free!! There are a couple of libaries that can do this, i would recommend triple_buffer.

The OutputConfig has to match the config of the AudioStream that will call this. If for example the buffer size is different Panics will occur.

In my testing i noticed that when using Cpal with non-standard buffer sizes Cpal would just give another buffer size. This will also lead to panics.

The stream has to closed before dropping the Manager and the manager has to be notified by calling stream_closed.

Source

pub fn stream_closed(&mut self)

When closing the Stream this method should be called.

Trait Implementations§

Source§

impl Drop for AudioManager

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,