Struct rodio::SpatialSink

source ·
pub struct SpatialSink { /* private fields */ }
Expand description

A sink that allows changing the position of the source and the listeners ears while playing. The sources played are then transformed to give a simple spatial effect. See Spatial for details.

Implementations§

source§

impl SpatialSink

source

pub fn try_new( stream: &OutputStreamHandle, emitter_position: [f32; 3], left_ear: [f32; 3], right_ear: [f32; 3], ) -> Result<SpatialSink, PlayError>

Builds a new SpatialSink.

source

pub fn set_emitter_position(&self, pos: [f32; 3])

Sets the position of the sound emitter in 3 dimensional space.

source

pub fn set_left_ear_position(&self, pos: [f32; 3])

Sets the position of the left ear in 3 dimensional space.

source

pub fn set_right_ear_position(&self, pos: [f32; 3])

Sets the position of the right ear in 3 dimensional space.

source

pub fn append<S>(&self, source: S)
where S: Source + Send + 'static, f32: FromSample<S::Item>, S::Item: Sample + Send,

Appends a sound to the queue of sounds to play.

source

pub fn volume(&self) -> f32

The value 1.0 is the “normal” volume (unfiltered input). Any value other than 1.0 will multiply each sample by this value.

source

pub fn set_volume(&self, value: f32)

Changes the volume of the sound.

The value 1.0 is the “normal” volume (unfiltered input). Any value other than 1.0 will multiply each sample by this value.

source

pub fn speed(&self) -> f32

Changes the play speed of the sound. Does not adjust the samples, only the playback speed.

§Note:
  1. Increasing the speed will increase the pitch by the same factor
  • If you set the speed to 0.5 this will halve the frequency of the sound lowering its pitch.
  • If you set the speed to 2 the frequency will double raising the pitch of the sound.
  1. Change in the speed affect the total duration inversely
  • If you set the speed to 0.5, the total duration will be twice as long.
  • If you set the speed to 2 the total duration will be halve of what it was.

See [Speed] for details

source

pub fn set_speed(&self, value: f32)

Changes the speed of the sound.

The value 1.0 is the “normal” speed (unfiltered input). Any value other than 1.0 will change the play speed of the sound.

source

pub fn play(&self)

Resumes playback of a paused sound.

No effect if not paused.

source

pub fn pause(&self)

Pauses playback of this sink.

No effect if already paused.

A paused sound can be resumed with play().

source

pub fn is_paused(&self) -> bool

Gets if a sound is paused

Sounds can be paused and resumed using pause() and play(). This gets if a sound is paused.

source

pub fn clear(&self)

Removes all currently loaded Sources from the SpatialSink and pauses it.

See pause() for information about pausing a Sink.

source

pub fn stop(&self)

Stops the sink by emptying the queue.

source

pub fn detach(self)

Destroys the sink without stopping the sounds that are still playing.

source

pub fn sleep_until_end(&self)

Sleeps the current thread until the sound ends.

source

pub fn empty(&self) -> bool

Returns true if this sink has no more sounds to play.

source

pub fn len(&self) -> usize

Returns the number of sounds currently in the queue.

source

pub fn try_seek(&self, pos: Duration) -> Result<(), SeekError>

Attempts to seek to a given position in the current source.

This blocks between 0 and ~5 milliseconds.

As long as the duration of the source is known seek is guaranteed to saturate at the end of the source. For example given a source that reports a total duration of 42 seconds calling try_seek() with 60 seconds as argument will seek to 42 seconds.

§Errors

This function will return SeekError::NotSupported if one of the underlying sources does not support seeking.

It will return an error if an implementation ran into one during the seek.

When seeking beyond the end of a source this function might return an error if the duration of the source is not known.

source

pub fn get_pos(&self) -> Duration

Returns the position of the sound that’s being played.

This takes into account any speedup or delay applied.

Example: if you apply a speedup of 2 to an mp3 decoder source and get_pos() returns 5s then the position in the mp3 recording is 10s from its start.

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

source§

fn into_sample(self) -> T

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