Trait creek_core::write::Encoder

source ·
pub trait Encoder: Sized + 'static {
    type T: Copy + Clone + Default + Send;
    type AdditionalOpts: Send + Default + Debug;
    type FileParams: Clone + Send;
    type OpenError: Error + Send;
    type FatalError: Error + Send;

    const DEFAULT_BLOCK_SIZE: usize;
    const DEFAULT_NUM_WRITE_BLOCKS: usize;

    // Required methods
    fn new(
        file: PathBuf,
        num_channels: u16,
        sample_rate: u32,
        block_size: usize,
        num_write_blocks: usize,
        additional_opts: Self::AdditionalOpts
    ) -> Result<(Self, FileInfo<Self::FileParams>), Self::OpenError>;
    fn encode(
        &mut self,
        write_block: &WriteBlock<Self::T>
    ) -> Result<WriteStatus, Self::FatalError>;
    fn finish_file(&mut self) -> Result<(), Self::FatalError>;
    fn discard_file(&mut self) -> Result<(), Self::FatalError>;
    fn discard_and_restart(&mut self) -> Result<(), Self::FatalError>;
}
Expand description

A type that encodes a file in a write stream.

Required Associated Types§

source

type T: Copy + Clone + Default + Send

The data type of a single sample. (i.e. f32)

source

type AdditionalOpts: Send + Default + Debug

Any additional options for creating a file with this encoder.

source

type FileParams: Clone + Send

Any additional information on the file.

source

type OpenError: Error + Send

The error type while opening the file.

source

type FatalError: Error + Send

The error type when a fatal error occurs.

Required Associated Constants§

source

const DEFAULT_BLOCK_SIZE: usize

The default number of frames in a write block.

source

const DEFAULT_NUM_WRITE_BLOCKS: usize

The default number of write blocks. This must be sufficiently large to ensure there are enough write blocks for the client in the worst case write latency scenerio.

Required Methods§

source

fn new( file: PathBuf, num_channels: u16, sample_rate: u32, block_size: usize, num_write_blocks: usize, additional_opts: Self::AdditionalOpts ) -> Result<(Self, FileInfo<Self::FileParams>), Self::OpenError>

Open the file for writing.

  • file - The path of the file to open.
  • num_channels - The number of audio channels in the file.
  • sample_rate - The sample rate of the audio data.
  • block_size - The block size to use.
  • max_num_write_blocks - The number of write blocks this stream is using.
  • additional_opts - Any additional encoder-specific options.
source

fn encode( &mut self, write_block: &WriteBlock<Self::T> ) -> Result<WriteStatus, Self::FatalError>

Write a block of data to the file.

If the write was successful, return WriteStatus::Ok.

If the codec has a maximum file size (i.e. 4GB for WAV), then keep track of how many bytes were written. Once the file is full (or about full), finish the file, close it, and create a new file with the characters “_XXX” appended to the file name (i.e. “_001” for the first file, “_002” for the second, etc.) This helper function num_files_to_file_name_extension() can be used to find this extension.

source

fn finish_file(&mut self) -> Result<(), Self::FatalError>

Finish up the file and then close it.

source

fn discard_file(&mut self) -> Result<(), Self::FatalError>

Delete all created files. Do not start over.

source

fn discard_and_restart(&mut self) -> Result<(), Self::FatalError>

Delete all created files and start over from the beginning.

Object Safety§

This trait is not object safe.

Implementors§