Skip to main content

AudioNodePool

Struct AudioNodePool 

Source
pub struct AudioNodePool<N: PoolableNode, FX: FxChain> { /* private fields */ }
Expand description

A pool of audio node chains that can dynamically be assigned work.

Implementations§

Source§

impl<N: PoolableNode, FX: FxChain> AudioNodePool<N, FX>

Source

pub fn new<B: AudioBackend>( num_workers: usize, first_node: N::AudioNode, first_node_config: Option<<N::AudioNode as AudioNode>::Configuration>, dst_node_id: NodeID, dst_num_channels: NonZeroChannelCount, cx: &mut FirewheelCtx<B>, ) -> Self

Construct a new sampler pool.

  • num_workers - The total number of workers that can work in parallel. More workers will allow more samples to be played concurrently, but will also increase processing overhead. A value of 16 is a good place to start.
  • first_node - The state of the first node in each FX chain instance.
  • first_node_config - The configuration of the first node in each FX chain instance.
  • first_node_num_out_channels - The number of output channels in the first node.
  • dst_node_id - The ID of the node that the last effect in each fx chain instance will connect to.
  • dst_num_channels - The number of input channels in dst_node_id.
  • cx - The firewheel context.
Source

pub fn num_workers(&self) -> usize

Source

pub fn new_worker<B: AudioBackend>( &mut self, params: &N::AudioNode, time: Option<EventInstant>, steal: bool, cx: &mut FirewheelCtx<B>, fx_chain: impl FnOnce(&mut FxChainState<FX>, &mut FirewheelCtx<B>), ) -> Result<NewWorkerResult, NewWorkerError>

Queue a new work to play a sequence.

  • params - The parameters of the sequence to play.
  • time - The instant these new parameters should take effect. If this is None, then the parameters will take effect as soon as the node receives the event.
  • steal - If this is true, then if there are no more workers left in in the pool, the oldest one will be stopped and replaced with this new one. If this is false, then an error will be returned if no more workers are left.
  • cx - The Firewheel context.
  • fx_chain - A closure to add additional nodes to this worker instance.

This will return an error if params.playback == PlaybackState::Stop.

Source

pub fn sync_worker_params<B: AudioBackend>( &mut self, worker_id: WorkerID, params: &N::AudioNode, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, ) -> bool

Sync the parameters for the given worker.

  • worker_id - The ID of the worker
  • params - The new parameter state to sync
  • time - The instant these new parameters should take effect. If this is None, then the parameters will take effect as soon as the node receives the event.
  • cx - The Firewheel context

If the parameters signify that the seuquence is stopped, then this worker will be removed and the worker_id will be invalidated.

Returns true if a worker with the given ID exists, false otherwise.

Source

pub fn pause<B: AudioBackend>( &mut self, worker_id: WorkerID, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, ) -> bool

Pause the given worker.

  • worker_id - The ID of the worker
  • time - The instant that the pause should take effect. If this is None, then the parameters will take effect as soon as the node receives the event.
  • cx - The Firewheel context

Returns true if a worker with the given ID exists, false otherwise.

Source

pub fn resume<B: AudioBackend>( &mut self, worker_id: WorkerID, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, ) -> bool

Resume the given worker.

  • worker_id - The ID of the worker
  • time - The instant that the resume should take effect. If this is None, then the parameters will take effect as soon as the node receives the event.
  • cx - The Firewheel context

Returns true if a worker with the given ID exists, false otherwise.

Source

pub fn stop<B: AudioBackend>( &mut self, worker_id: WorkerID, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, ) -> bool

Stop the given worker.

  • worker_id - The ID of the worker
  • time - The instant that the stop should take effect. If this is None, then the parameters will take effect as soon as the node receives the event.
  • cx - The Firewheel context

This will remove the worker and invalidate the given worker_id.

Returns true if a worker with the given ID exists and was stopped.

Source

pub fn pause_all<B: AudioBackend>( &mut self, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, )

Pause all workers.

  • time - The instant that the stop should take effect. If this is None, then the parameters will take effect as soon as the node receives the event.
Source

pub fn resume_all<B: AudioBackend>( &mut self, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, )

Resume all workers.

  • time - The instant that the stop should take effect. If this is None, then the parameters will take effect as soon as the node receives the event.
Source

pub fn stop_all<B: AudioBackend>( &mut self, time: Option<EventInstant>, cx: &mut FirewheelCtx<B>, )

Stop all workers.

  • time - The instant that the stop should take effect. If this is None, then the parameters will take effect as soon as the node receives the event.
Source

pub fn first_node(&self, worker_id: WorkerID) -> Option<&N::AudioNode>

Get the first node parameters of the given worker.

Source

pub fn first_node_state<'a, T: 'static, B: AudioBackend>( &self, worker_id: WorkerID, cx: &'a FirewheelCtx<B>, ) -> Option<&'a T>

Get an immutable reference to the state of the first node of the given worker.

Source

pub fn first_node_state_mut<'a, T: 'static, B: AudioBackend>( &self, worker_id: WorkerID, cx: &'a mut FirewheelCtx<B>, ) -> Option<&'a mut T>

Get a mutable reference to the state of the first node of the given worker.

Source

pub fn fx_chain(&self, worker_id: WorkerID) -> Option<&FxChainState<FX>>

Source

pub fn fx_chain_mut( &mut self, worker_id: WorkerID, ) -> Option<&mut FxChainState<FX>>

Source

pub fn has_stopped<B: AudioBackend>( &self, worker_id: WorkerID, cx: &FirewheelCtx<B>, ) -> bool

Returns true if the sequence has either not started playing yet or has finished playing.

Source

pub fn poll<B: AudioBackend>(&mut self, cx: &FirewheelCtx<B>) -> PollResult

Poll for the current number of active workers, and return a list of workers which have finished playing.

Calling this method is optional.

Source

pub fn num_active_workers(&self) -> usize

The total number of active workers.

Auto Trait Implementations§

§

impl<N, FX> Freeze for AudioNodePool<N, FX>

§

impl<N, FX> RefUnwindSafe for AudioNodePool<N, FX>

§

impl<N, FX> Send for AudioNodePool<N, FX>
where <N as PoolableNode>::AudioNode: Send, FX: Send,

§

impl<N, FX> Sync for AudioNodePool<N, FX>
where <N as PoolableNode>::AudioNode: Sync, FX: Sync,

§

impl<N, FX> Unpin for AudioNodePool<N, FX>
where <N as PoolableNode>::AudioNode: Unpin, FX: Unpin,

§

impl<N, FX> UnwindSafe for AudioNodePool<N, FX>

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.