pub trait StreamedSample:
SampleResourceInfo
+ Send
+ Sync
+ 'static {
// Required methods
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;
fn range_is_ready(&mut self, range: Range<u64>) -> bool;
fn cache_new_starting_frame(
&mut self,
frame: u64,
speed: f64,
will_play_backwards: bool,
);
}Expand description
A resource of audio samples that are streamed from disk or over a network.
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.
Required Methods§
Sourcefn fill_buffers(
&mut self,
out_buffer: &mut [&mut [f32]],
out_buffer_range: Range<usize>,
start_frame: u64,
speed: f64,
is_playing_backwards: bool,
) -> usize
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.
Sourcefn range_is_ready(&mut self, range: Range<u64>) -> bool
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.
Sourcefn cache_new_starting_frame(
&mut self,
frame: u64,
speed: f64,
will_play_backwards: bool,
)
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".