Struct creek_core::write::WriteDiskStream
source · 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>
impl<E: Encoder> WriteDiskStream<E>
sourcepub fn new<P: Into<PathBuf>>(
file: P,
num_channels: u16,
sample_rate: u32,
stream_opts: WriteStreamOptions<E>
) -> Result<WriteDiskStream<E>, E::OpenError>
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
.
sourcepub fn is_ready(&mut self) -> Result<bool, WriteError<E::FatalError>>
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.
sourcepub fn block_until_ready(&mut self) -> Result<(), WriteError<E::FatalError>>
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.
sourcepub fn write(
&mut self,
buffer: &[&[E::T]]
) -> Result<(), WriteError<E::FatalError>>
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.
sourcepub fn finish_and_close(&mut self) -> Result<(), WriteError<E::FatalError>>
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.)
sourcepub fn discard_and_close(&mut self) -> Result<(), WriteError<E::FatalError>>
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.)
sourcepub fn discard_and_restart(&mut self) -> Result<(), WriteError<E::FatalError>>
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.
sourcepub fn poll(&mut self) -> Result<(), WriteError<E::FatalError>>
pub fn poll(&mut self) -> Result<(), WriteError<E::FatalError>>
Poll for messages from the server.
This is realtime-safe.
sourcepub fn finish_complete(&self) -> bool
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.
sourcepub fn info(&self) -> &FileInfo<E::FileParams>
pub fn info(&self) -> &FileInfo<E::FileParams>
Return info about the file.
This is realtime-safe.