Struct Player

Source
pub struct Player<S: Sample> { /* private fields */ }
Expand description

Audio player that plays a DSP graph through a configurable backend.

Player wraps a DSP Graph and handles the conversion to an audio stream that can be played through the system’s audio output.

§Examples

Using the default rodio backend (requires rodio feature):

use bbx_player::Player;

let player = Player::new(graph)?;
let handle = player.play()?;

std::thread::sleep(Duration::from_secs(5));
handle.stop();

Using a custom backend:

use bbx_player::{Player, backends::CpalBackend};

let backend = CpalBackend::try_default()?;
let player = Player::with_backend(graph, backend);
let handle = player.play()?;

Implementations§

Source§

impl<S: Sample> Player<S>

Source

pub fn new(graph: Graph<S>) -> Result<Self>

Create a new player with the default rodio backend.

Source§

impl<S: Sample> Player<S>

Source

pub fn with_backend<B: Backend>(graph: Graph<S>, backend: B) -> Self

Create a new player with a custom backend.

Source

pub fn play(self) -> Result<PlayHandle>

Start non-blocking playback.

Returns a PlayHandle that can be used to stop playback. The player is consumed by this method.

Auto Trait Implementations§

§

impl<S> Freeze for Player<S>

§

impl<S> !RefUnwindSafe for Player<S>

§

impl<S> Send for Player<S>

§

impl<S> !Sync for Player<S>

§

impl<S> Unpin for Player<S>
where S: Unpin,

§

impl<S> !UnwindSafe for Player<S>

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.

§

impl<S> FromSample<S> for S

§

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.

§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

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

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,