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
impl SamplerNodeResource
pub fn from_sample<T: SampleResource + Send + Sync + 'static>(sample: T) -> Self
pub fn from_streamed<T: StreamedSample>(sample: T) -> Self
Sourcepub fn num_channels(&self) -> NonZeroUsize
pub fn num_channels(&self) -> NonZeroUsize
The number of channels in this resource.
Sourcepub fn len_frames(&self) -> u64
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.
Sourcepub fn sample_rate(&self) -> Option<NonZeroU32>
pub fn sample_rate(&self) -> Option<NonZeroU32>
The sample rate of this resource.
Returns None if the sample rate is unknown.
Sourcepub 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
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 ofbuffersis 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, where1.0is playing at the sample rate of this resource,0.5is playing at half the sample rate, and2.0is 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.
Sourcepub fn range_is_ready(&mut self, range: Range<u64>) -> bool
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.
Sourcepub fn cache_new_starting_frame(
&mut self,
frame: u64,
speed: f64,
will_play_backwards: bool,
)
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
impl From<ArcGc<dyn SampleResource + Sync + Send>> for SamplerNodeResource
Source§impl From<OwnedGcUnsized<dyn StreamedSample>> for SamplerNodeResource
impl From<OwnedGcUnsized<dyn StreamedSample>> for SamplerNodeResource
Source§fn from(value: OwnedGcUnsized<dyn StreamedSample>) -> Self
fn from(value: OwnedGcUnsized<dyn StreamedSample>) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for SamplerNodeResource
impl !Sync for SamplerNodeResource
impl !UnwindSafe for SamplerNodeResource
impl Freeze for SamplerNodeResource
impl Send for SamplerNodeResource
impl Unpin for SamplerNodeResource
impl UnsafeUnpin for SamplerNodeResource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.