pub struct PreloadedFileSource { /* private fields */ }Expand description
A buffered, clonable FileSource, which decodes the entire file into a buffer before its
played back.
Buffers of preloaded file sources are shared (wrapped in an Arc), so cloning a source is very cheap as this only copies a buffer reference and not the buffer itself. This way a file can be pre-loaded once and can then be cloned and reused as often as necessary.
Implementations§
Source§impl PreloadedFileSource
impl PreloadedFileSource
Sourcepub fn from_file<P: AsRef<Path>>(
path: P,
options: FilePlaybackOptions,
output_sample_rate: u32,
) -> Result<Self, Error>
pub fn from_file<P: AsRef<Path>>( path: P, options: FilePlaybackOptions, output_sample_rate: u32, ) -> Result<Self, Error>
Create a new preloaded file source with the given audio file path.
Sourcepub fn from_file_buffer(
file_buffer: Vec<u8>,
file_path: &str,
options: FilePlaybackOptions,
output_sample_rate: u32,
) -> Result<Self, Error>
pub fn from_file_buffer( file_buffer: Vec<u8>, file_path: &str, options: FilePlaybackOptions, output_sample_rate: u32, ) -> Result<Self, Error>
Create a new preloaded file source with the given raw encoded file stream buffer.
Create a new preloaded file source from the given shared, decoded file buffer.
Sourcepub fn clone(
&self,
options: FilePlaybackOptions,
output_sample_rate: u32,
) -> Result<Self, Error>
pub fn clone( &self, options: FilePlaybackOptions, output_sample_rate: u32, ) -> Result<Self, Error>
Create a copy of this preloaded source with the given playback options.
Sourcepub fn file_buffer(&self) -> Arc<AudioFileBuffer> ⓘ
pub fn file_buffer(&self) -> Arc<AudioFileBuffer> ⓘ
Access to the shared file buffer.
Sourcepub fn loop_range(&self) -> Option<Range<u64>>
pub fn loop_range(&self) -> Option<Range<u64>>
Returns the active loop range in sample frames: the override if set, else the file’s
embedded loop range. Returns None when neither is set.
Sourcepub fn set_loop_range(&mut self, range: Option<Range<u64>>)
pub fn set_loop_range(&mut self, range: Option<Range<u64>>)
Override the file’s embedded loop range with a custom one.
Pass None to revert to the file’s embedded loop range.
Sourcepub fn set_repeat(&mut self, repeat_count: usize)
pub fn set_repeat(&mut self, repeat_count: usize)
Override the file’s playback option repeat settings with the given ones. Set to 0 to disable looping, usize::MAX to repeat forever.
Sourcepub fn set_speed(&mut self, speed: f64, glide: Option<f32>)
pub fn set_speed(&mut self, speed: f64, glide: Option<f32>)
Set the playback speed (pitch) for this source.
Trait Implementations§
Source§impl FileSource for PreloadedFileSource
impl FileSource for PreloadedFileSource
Source§fn playback_id(&self) -> PlaybackId
fn playback_id(&self) -> PlaybackId
PlaybackStatusEvents.Source§fn playback_options(&self) -> &FilePlaybackOptions
fn playback_options(&self) -> &FilePlaybackOptions
Source§fn playback_message_queue(&self) -> Arc<ArrayQueue<FilePlaybackMessage>> ⓘ
fn playback_message_queue(&self) -> Arc<ArrayQueue<FilePlaybackMessage>> ⓘ
Source§fn playback_status_sender(&self) -> Option<SyncSender<PlaybackStatusEvent>>
fn playback_status_sender(&self) -> Option<SyncSender<PlaybackStatusEvent>>
fn set_playback_status_sender( &mut self, sender: Option<SyncSender<PlaybackStatusEvent>>, )
Source§fn playback_status_context(&self) -> Option<PlaybackStatusContext>
fn playback_status_context(&self) -> Option<PlaybackStatusContext>
fn set_playback_status_context( &mut self, context: Option<PlaybackStatusContext>, )
Source§fn total_frames(&self) -> Option<u64>
fn total_frames(&self) -> Option<u64>
Source§fn current_frame_position(&self) -> u64
fn current_frame_position(&self) -> u64
Source§fn end_of_track(&self) -> bool
fn end_of_track(&self) -> bool
Source§impl Source for PreloadedFileSource
impl Source for PreloadedFileSource
Source§fn channel_count(&self) -> usize
fn channel_count(&self) -> usize
Source§fn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
Source§fn is_exhausted(&self) -> bool
fn is_exhausted(&self) -> bool
write and may be removed from a source render graph.Source§fn weight(&self) -> usize
fn weight(&self) -> usize
~1..10,
where 1 means pretty lightweight and 10 very CPU intensive. This is used in parallel
processing to distribute work loads evenly before or without actual CPU measurements.Source§fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize
fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize
output.len() samples into the interleaved output
The given SourceTime parameter specifies which absolute time this buffer in the
final output stream refers to. It can be used to schedule and apply real-time events.
Returns the number of written samples (not frames).