Trait hound::Sample

source ·
pub trait Sample: Sized {
    // Required methods
    fn write<W: Write>(self, writer: &mut W, bits: u16) -> Result<()>;
    fn write_padded<W: Write>(
        self,
        writer: &mut W,
        bits: u16,
        byte_width: u16
    ) -> Result<()>;
    fn read<R: Read>(
        reader: &mut R,
        _: SampleFormat,
        bytes: u16,
        bits: u16
    ) -> Result<Self>;
    fn as_i16(self) -> i16;
}
Expand description

A type that can be used to represent audio samples.

Via this trait, decoding can be generic over i8, i16, i32 and f32.

All integer formats with bit depths up to 32 bits per sample can be decoded into i32, but it takes up more memory. If you know beforehand that you will be reading a file with 16 bits per sample, then decoding into an i16 will be sufficient.

Required Methods§

source

fn write<W: Write>(self, writer: &mut W, bits: u16) -> Result<()>

Writes the audio sample to the WAVE data chunk.

source

fn write_padded<W: Write>( self, writer: &mut W, bits: u16, byte_width: u16 ) -> Result<()>

Writes the audio sample to the WAVE data chunk, zero padding the size of the written sample out to byte_width.

source

fn read<R: Read>( reader: &mut R, _: SampleFormat, bytes: u16, bits: u16 ) -> Result<Self>

Reads the audio sample from the WAVE data chunk.

source

fn as_i16(self) -> i16

Cast the sample to a 16-bit sample.

This does not change the value of the sample, it only casts it. The value is assumed to fit within the range. This is not verified, truncation may occur.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Sample for f32

source§

fn write<W: Write>(self, writer: &mut W, bits: u16) -> Result<()>

source§

fn write_padded<W: Write>( self, writer: &mut W, bits: u16, byte_width: u16 ) -> Result<()>

source§

fn as_i16(self) -> i16

source§

fn read<R: Read>( reader: &mut R, fmt: SampleFormat, bytes: u16, bits: u16 ) -> Result<Self>

source§

impl Sample for i8

source§

fn write<W: Write>(self, writer: &mut W, bits: u16) -> Result<()>

source§

fn write_padded<W: Write>( self, writer: &mut W, bits: u16, byte_width: u16 ) -> Result<()>

source§

fn as_i16(self) -> i16

source§

fn read<R: Read>( reader: &mut R, fmt: SampleFormat, bytes: u16, bits: u16 ) -> Result<i8>

source§

impl Sample for i16

source§

fn write<W: Write>(self, writer: &mut W, bits: u16) -> Result<()>

source§

fn write_padded<W: Write>( self, writer: &mut W, bits: u16, byte_width: u16 ) -> Result<()>

source§

fn as_i16(self) -> i16

source§

fn read<R: Read>( reader: &mut R, fmt: SampleFormat, bytes: u16, bits: u16 ) -> Result<i16>

source§

impl Sample for i32

source§

fn write<W: Write>(self, writer: &mut W, bits: u16) -> Result<()>

source§

fn write_padded<W: Write>( self, writer: &mut W, bits: u16, byte_width: u16 ) -> Result<()>

source§

fn as_i16(self) -> i16

source§

fn read<R: Read>( reader: &mut R, fmt: SampleFormat, bytes: u16, bits: u16 ) -> Result<i32>

Implementors§