pub struct WriteDiskStream<E: Encoder> { /* private fields */ }
Expand description

A realtime-safe disk-streaming writer of audio files.

Implementations§

source§

impl<E: Encoder> WriteDiskStream<E>

source

pub fn new<P: Into<PathBuf>>( file: P, num_channels: u16, sample_rate: u32, stream_opts: WriteStreamOptions<E> ) -> Result<WriteDiskStream<E>, E::OpenError>

Open a new realtime-safe disk-streaming writer.

  • file - The path to the file to open.
  • num_channels - The number of channels in the file.
  • sample_rate - The sample rate of the file.
  • stream_opts - Additional stream options.
Panics

This will panic if num_channels, sample_rate, stream_opts.block_size, stream_opts.num_write_blocks, or stream_opts.server_msg_channel_size is 0.

source

pub fn is_ready(&mut self) -> Result<bool, WriteError<E::FatalError>>

Returns true if the stream is ready for writing, false otherwise.

This is realtime-safe.

In theory this should never return false, but this function is here as a sanity-check.

source

pub fn block_until_ready(&mut self) -> Result<(), WriteError<E::FatalError>>

Blocks the current thread until the stream is ready to be written to.

NOTE: This is note realtime-safe.

In theory you shouldn’t need this, but this function is here as a sanity-check.

source

pub fn write( &mut self, buffer: &[&[E::T]] ) -> Result<(), WriteError<E::FatalError>>

Write the buffer of frames into the file.

This is realtime-safe.

Some codecs (like WAV) have a maximum size of 4GB. If more than 4GB of data is pushed to this stream, then a new file will automatically be created to hold more data. The name of this file will be the same name as the main file with “_XXX” appended to the end (i.e. “_001”, “_002”, etc.). WriteDiskStream::num_files() can be used to get the total numbers of files that have been created.

source

pub fn finish_and_close(&mut self) -> Result<(), WriteError<E::FatalError>>

Finish the file and close the stream. WriteDiskStream::write() cannot be used after calling this.

This is realtime-safe.

Because this method is realtime safe and doesn’t block, the file may still be in the process of finishing when this method returns. If you wish to make sure that the file has successfully finished, periodically call WriteDiskStream::poll() and then WriteDiskStream::finish_complete() for a response. (If WriteDiskStream::poll() returns an error, then it may mean that the file failed to save correctly.)

source

pub fn discard_and_close(&mut self) -> Result<(), WriteError<E::FatalError>>

Delete all files created by this stream and close the stream. WriteDiskStream::write() cannot be used after calling this.

This is realtime-safe.

Because this method is realtime safe and doesn’t block, the file may still be in the process of finishing when this method returns. If you wish to make sure that the file has successfully finished, periodically call WriteDiskStream::poll() and then WriteDiskStream::finish_complete() for a response. (If WriteDiskStream::poll() returns an error, then it may mean that the file failed to be discarded correctly.)

source

pub fn discard_and_restart(&mut self) -> Result<(), WriteError<E::FatalError>>

Delete all files created by this stream and start over. This stream can continue to be written to after calling this.

This is realtime-safe.

source

pub fn poll(&mut self) -> Result<(), WriteError<E::FatalError>>

Poll for messages from the server.

This is realtime-safe.

source

pub fn finish_complete(&self) -> bool

Returns true when the file has been successfully finished and closed, false otherwise.

Be sure to call WriteDiskStream::poll() first, or else this may not be accurate.

This is realtime-safe.

source

pub fn info(&self) -> &FileInfo<E::FileParams>

Return info about the file.

This is realtime-safe.

source

pub fn num_files(&self) -> u32

Returns the total number of files created by this stream. This can be more than one depending on the codec and the number of written frames.

This is realtime-safe.

Trait Implementations§

source§

impl<E: Encoder> Drop for WriteDiskStream<E>

source§

fn drop(&mut self)

Executes the destructor for this type. 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<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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.