pub struct AudioSpec {
pub src: SoundId,
pub volume: f32,
pub looped: bool,
pub paused: bool,
pub finish: bool,
pub tag: Option<Value>,
}Expand description
What an audio node declares each frame (Core::audio_node).
Fields§
§src: SoundId§volume: f32Linear amplitude, 0..1; changes apply to the running playback.
looped: bool§paused: boolHolds the playback (resumes when cleared).
finish: boolWhat the node going away means: false stops the playback, true
releases it — it finishes on its own. See AudioSpec::finish.
tag: Option<Value>Carried back in the ended event; None = no event.
Implementations§
Source§impl AudioSpec
impl AudioSpec
pub fn new(src: SoundId) -> Self
pub fn volume(self, v: f32) -> Self
pub fn looped(self) -> Self
pub fn paused(self, paused: bool) -> Self
Sourcepub fn finish(self) -> Self
pub fn finish(self) -> Self
The node’s removal releases the playback instead of stopping it:
it plays to its end, and a tag still reports ended when it gets
there. Only removal changes — a looped playback still stops (it
has no end to reach), and a changed src still restarts, since that
is a replacement rather than a departure. A playback that is
paused when its node goes has nothing to finish and the driver
holds it forever, so a view that pauses should stop rather than
release. Without this, a one-shot the view wants heard whole has to
stay declared for the asset’s length, which the view does not know.
This is also what
truncated-playback asks for: a
one-shot removed mid-sound raises that warning, and the answer to
it is either this flag or a node kept declared until the ended
event. A node that means to cut the sound off says so by stopping
what it started (Core::stop), which is not reported.
A released playback is not free: it holds one of the device’s 128
voices until its file ends, and the 129th play is refused (reported
as crate::diag::PLAYBACK_REFUSED and, for a tagged node,
{kind:"sound", phase:"refused"}). A loop would hold a voice for
ever, which is why a loop is stopped rather than released.