Skip to main content

PreloadedFileSource

Struct PreloadedFileSource 

Source
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

Source

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.

Source

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.

Source

pub fn from_shared_buffer( file_buffer: Arc<AudioFileBuffer>, file_path: &str, options: FilePlaybackOptions, output_sample_rate: u32, ) -> Result<Self, Error>

Create a new preloaded file source from the given shared, decoded file buffer.

Source

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.

Source

pub fn file_buffer(&self) -> Arc<AudioFileBuffer>

Access to the shared file buffer.

Source

pub fn seek(&mut self, position: Duration)

Set a new playback position for this source.

Source

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.

Source

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.

Source

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.

Source

pub fn set_speed(&mut self, speed: f64, glide: Option<f32>)

Set the playback speed (pitch) for this source.

Source

pub fn stop(&mut self)

Stop the file source, starting to fade-out, when a fadeout is set, stop immediately.

Source

pub fn reset(&mut self)

Reset the file to start playback from the beginning.

Source

pub fn kill(&mut self)

Abruptly stop the source without applying fade-outs

Trait Implementations§

Source§

impl FileSource for PreloadedFileSource

Source§

fn file_name(&self) -> String

Name or path of the file for display or debugging purposes.
Source§

fn playback_id(&self) -> PlaybackId

A unique ID, which can be used to identify sources in PlaybackStatusEvents.
Source§

fn playback_options(&self) -> &FilePlaybackOptions

The file source’s playback options
Source§

fn playback_message_queue(&self) -> Arc<ArrayQueue<FilePlaybackMessage>>

Message queue to control file playback.
Source§

fn playback_status_sender(&self) -> Option<SyncSender<PlaybackStatusEvent>>

Channel to receive playback status from the file.
Source§

fn set_playback_status_sender( &mut self, sender: Option<SyncSender<PlaybackStatusEvent>>, )

Source§

fn playback_status_context(&self) -> Option<PlaybackStatusContext>

Optional context passed along with the playback status.
Source§

fn set_playback_status_context( &mut self, context: Option<PlaybackStatusContext>, )

Source§

fn total_frames(&self) -> Option<u64>

Total number of sample frames in the decoded file: may not be known before playback finished.
Source§

fn current_frame_position(&self) -> u64

Current playback pos in frames
Source§

fn end_of_track(&self) -> bool

True when the source played through the entire file, else false.
Source§

impl Source for PreloadedFileSource

Source§

fn channel_count(&self) -> usize

The source’s output channel count.
Source§

fn sample_rate(&self) -> u32

The source’s output sample rate.
Source§

fn is_exhausted(&self) -> bool

Returns whether the source finished playback. Exhausted sources should only return 0 on write and may be removed from a source render graph.
Source§

fn weight(&self) -> usize

Return a rough estimate of the processing costs for this source in range ~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

Write at most 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).
Source§

fn into_box(self) -> Box<dyn Source>
where Self: Sized,

Convert the Source impl into a boxed dyn Source. Read more

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V