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
impl AudioManager
pub fn new(song: Song) -> Self
Sourcepub fn try_edit_song(&mut self) -> Option<SongEdit<'_>>
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.
pub fn get_song(&self) -> &Song
pub fn collect_garbage(&mut self)
pub fn try_msg_worker(&mut self, msg: ToWorkerMsg) -> SendResult
Sourcepub fn playback_status(&mut self) -> Option<&Option<PlaybackStatus>>
pub fn playback_status(&mut self) -> Option<&Option<PlaybackStatus>>
last playback status sent by the audio worker
Sourcepub fn buffer_time(&self) -> Option<Duration>
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
Sourcepub fn get_callback<Sample: Sample + FromSample<f32>>(
&mut self,
config: OutputConfig,
) -> impl FnMut(&mut [Sample])
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.
Sourcepub fn stream_closed(&mut self)
pub fn stream_closed(&mut self)
When closing the Stream this method should be called.