pub struct Audio { /* private fields */ }Implementations§
Source§impl Audio
impl Audio
pub fn new() -> Self
Sourcepub fn warm(&mut self)
pub fn warm(&mut self)
Starts opening the device if nothing has yet. Cheap to call every frame; the driver calls it once the session holds a sound, so the device is open by the time a click asks for one.
Sourcepub fn apply(
&mut self,
cmds: Vec<AudioCommand>,
resources: &SharedResources,
) -> Answered
pub fn apply( &mut self, cmds: Vec<AudioCommand>, resources: &SharedResources, ) -> Answered
Applies queued commands to the device. While it is still
opening they wait, in order, behind whatever waited before.
Returns what the device answered back: the stops that landed on
a sound still playing and the plays it would not take, the way
Self::poll_ended returns the ones that finished. Both are
buffered rather than produced inline, because either can happen
inside flush_pending, which runs from the poll as well as from
here — so a command that waited for the device reports on the
apply that flushes it, a later one than the apply that queued it.
Sourcepub fn poll_ended(&mut self) -> Vec<PlaybackId>
pub fn poll_ended(&mut self) -> Vec<PlaybackId>
Playbacks that finished on their own since the last poll
(stopped ones were already forgotten by Stop). Also where a
command that waited for the device starts, since the driver
polls while anything is active.
Sourcepub fn holds_device(&self) -> bool
pub fn holds_device(&self) -> bool
Whether the device is open (or opening) and so costing something. A CoreAudio/WASAPI/ALSA output stream is a real-time thread that runs whether or not anything is playing — 94 buffer callbacks a second at the usual 512-frame period — which is the whole of an idle kui app’s CPU once a session holds a sound. The driver asks so it knows whether there is anything to close.
Sourcepub fn close(&mut self)
pub fn close(&mut self)
Lets the output device go. The decoded-sound cache stays — it is
the ~90 ms open that has to be paid again, not the decode — so a
re-warm costs nothing a cold start does not. Refuses while
anything is playing or waiting, since that is the device’s whole
job; the driver only asks after active() has been false for a
while.
Asks opening() first, and that is not a detail: a device the
app warmed but never commanded stays in Opening forever —
nothing else on this type calls opening() unless a command
flows — with the opened manager sitting live in the channel and
its stream running. That is precisely the case worth closing, so
the state has to be settled before it can be read. Still opening
means not yet closable; the driver asks again.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Audio
impl !Send for Audio
impl !Sync for Audio
impl !UnwindSafe for Audio
impl Freeze for Audio
impl Unpin for Audio
impl UnsafeUnpin for Audio
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.