Voice

Struct Voice 

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

Manages a single FMOD Channel for monophonic playback.

When a sound is played by FMOD, it is assigned to play on a virtual channel and a weak handle to the channel is returned.

This handle will be invalidated after the next call to system.update() if playback has reached the end of a non-looping sound, or otherwise if channel.stop() is called. The channel can also be stolen by the priority system if a new request to play a sound is made and there are no free channels.

This type will act as a strong reference for a single playing sound, controlling playback using a single channel and re-acquiring it in the case the channel is stolen or invalidated, and stopping the channel when the voice is dropped.

Implementations§

Source§

impl Voice

Source

pub fn new() -> Self

Source

pub const fn channel(&self) -> Option<&Channel>

Source

pub const fn channel_mut(&mut self) -> Option<&mut Channel>

Source

pub const fn channel_group(&self) -> Option<&ChannelGroup>

Source

pub const fn channel_group_mut(&mut self) -> Option<&mut ChannelGroup>

Source

pub fn is_playing(&self) -> Option<bool>

Source

pub fn play(&mut self, sound: &mut Sound, channel_group: Option<ChannelGroup>)

Play a 2D sound on a fresh channel.

Note that playing the same sound twice will re-acquire the channel. To restart playback at the beginning of the sound use trigger().

Source

pub fn loop_(&mut self, sound: &mut Sound, channel_group: Option<ChannelGroup>)

Loop a 2D sound on a fresh channel.

Note that playing the same sound twice will re-acquire the channel. To restart playback at the beginning of the sound use trigger().

Source

pub fn play_from( &mut self, sound: &mut Sound, channel_group: Option<ChannelGroup>, position: u32, )

Play a 2D sound on a fresh channel starting from the given position.

Note that playing the same sound twice will re-acquire the channel. To restart playback at the beginning of the sound use trigger().

Source

pub fn loop_from( &mut self, sound: &mut Sound, channel_group: Option<ChannelGroup>, position: u32, )

Play a 2D sound on a fresh channel starting from the given position.

Note that looping will loop back to the beginning of the sound when the end is reached.

Note that playing the same sound twice will re-acquire the channel. To restart playback at the beginning of the sound use trigger().

Source

pub fn cue(&mut self, sound: &mut Sound, channel_group: Option<ChannelGroup>)

“Play” a 2D sound on a fresh channel with ‘paused = true’.

Source

pub fn trigger(&mut self) -> Option<bool>

Set the position to the beginning of the sound in the un-paused state.

Returns Some(true) if the channel was playing and None if this voice is uninitialized.

Source

pub fn pause(&mut self) -> Option<bool>

Pauses playback.

Returns Some(true) if the channel was playing, and None if the voice was uninitialized.

Source

pub fn resume(&mut self) -> Option<bool>

Resumes playback.

Returns Some(true) if the channel was already playing, and None if the voice is uninitialized.

Source

pub fn position( &mut self, position: u32, timeunit: Option<Timeunit>, ) -> Option<bool>

Set playback position.

Default timeunit is Timeunit::PCM (samples).

Returns Some(true) if the channel was currently playing, and None if the voice was uninitialized.

Source

pub fn stop(&mut self) -> Option<bool>

Stops playback and releases the channel.

Returns Some(true) if the channel was playing. Returns None if the voice was uninitialized.

To instead pause playback and keep the channel reference, use pause().

Trait Implementations§

Source§

impl Debug for Voice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Voice

Source§

fn default() -> Voice

Returns the “default value” for a type. Read more
Source§

impl Drop for Voice

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for Voice

Source§

fn eq(&self, other: &Voice) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Voice

Auto Trait Implementations§

§

impl Freeze for Voice

§

impl RefUnwindSafe for Voice

§

impl !Send for Voice

§

impl !Sync for Voice

§

impl Unpin for Voice

§

impl UnwindSafe for Voice

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<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> 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.