Skip to main content

SamplerNodeResource

Enum SamplerNodeResource 

Source
pub enum SamplerNodeResource {
    InMemory(ArcGc<dyn SampleResource + Send + Sync + 'static>),
    Streamed(OwnedGcUnsized<dyn StreamedSample>),
}
Expand description

A source of audio samples for a SamplerNode.

Variants§

§

InMemory(ArcGc<dyn SampleResource + Send + Sync + 'static>)

A resource of audio samples where the entire contents of the sample are already loaded into memory.

Prefer this for resources which are less than 20 or so seconds long (i.e. sound effects).

§

Streamed(OwnedGcUnsized<dyn StreamedSample>)

NOT IMPLEMENTED YET! Will lead to a panic if used.

A resource of audio samples that are streamed from disk or over a network.

Prefer this for resources which are greater than 20 or so seconds long (i.e. music tracks and ambience).

This uses considerably less memory, but requires a more complicated setup. It also has the potential to run into cache misses if the playhead is moved to a region that hasn’t been loaded yet, or if the stream fails to send enough samples in time.

Implementations§

Source§

impl SamplerNodeResource

Source

pub fn from_sample<T: SampleResource + Send + Sync + 'static>(sample: T) -> Self

Source

pub fn from_streamed<T: StreamedSample>(sample: T) -> Self

Source

pub fn num_channels(&self) -> NonZeroUsize

The number of channels in this resource.

Source

pub fn len_frames(&self) -> u64

The length of this resource in samples (of a single channel of audio).

Not to be confused with video frames.

Source

pub fn sample_rate(&self) -> Option<NonZeroU32>

The sample rate of this resource.

Returns None if the sample rate is unknown.

Source

pub fn fill_buffers( &mut self, out_buffer: &mut [&mut [f32]], out_buffer_range: Range<usize>, start_frame: u64, speed: f64, is_playing_backwards: bool, ) -> usize

Fill the given buffers with audio data starting from the given starting frame in the resource.

  • out_buffer - The buffers to fill with data. If the length of buffers is greater than the number of channels in this resource, then ignore the extra buffers.
  • out_buffer_range - The range inside each buffer slice in which to fill with data. Do not fill any data outside of this range.
  • start_frame - The sample (of a single channel of audio) in the resource at which to start copying from. Not to be confused with video frames.
  • speed - The speed at which playback is occurring, where 1.0 is playing at the sample rate of this resource, 0.5 is playing at half the sample rate, and 2.0 is playing at twice the sample rate.

Returns the number of frames that were successfully filled. This may be less than the length of out_buffer_range if the range is all or partly out of bounds of the resource, or if a cache miss occurred. Any frames that were not successfully filled will be left untouched.

Source

pub fn range_is_ready(&mut self, range: Range<u64>) -> bool

Returns true if the given range of frames is loaded into memory and ready to be read.

Source

pub fn cache_new_starting_frame( &mut self, frame: u64, speed: f64, will_play_backwards: bool, )

Request to cache a new region at the given starting frame.

Trait Implementations§

Source§

impl From<ArcGc<dyn SampleResource + Sync + Send>> for SamplerNodeResource

Source§

fn from(value: ArcGc<dyn SampleResource + Send + Sync + 'static>) -> Self

Converts to this type from the input type.
Source§

impl From<OwnedGcUnsized<dyn StreamedSample>> for SamplerNodeResource

Source§

fn from(value: OwnedGcUnsized<dyn StreamedSample>) -> Self

Converts to this type from the input type.

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> ConditionalSend for T
where T: Send,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.