Enum wavv::Samples[][src]

pub enum Samples {
    BitDepth8(Vec<u8>),
    BitDepth16(Vec<i16>),
    BitDepth24(Vec<i32>),
}
Expand description

Enum to hold samples for different bit depth

Variants

BitDepth8

8 bit audio

Tuple Fields of BitDepth8

0: Vec<u8>
BitDepth16

16 bit audio

Tuple Fields of BitDepth16

0: Vec<i16>
BitDepth24

24 bit audio

Tuple Fields of BitDepth24

0: Vec<i32>

Implementations

Create new Samples instance from a slice of bytes this requires a Header instance to be passed to determine the sample size and channel data etc.

Examples

use wavv::{Header, Samples};

fn main() {
    let bytes = [
        0x01, 0x00, // audio format
        0x01, 0x00, // num channels
        0x44, 0xac, 0x00, 0x00, // sample rate
        0x88, 0x58, 0x01, 0x00, // byte rate
        0x04, 0x00, // block align
        0x18, 0x00, // bits per sample
    ];

    let header = Header::from_bytes(&bytes).unwrap();

    assert_eq!(header.num_channels, 1);
    assert_eq!(header.bit_depth, 24);
    assert_eq!(header.sample_rate, 44_100);

    let bytes = [
        0x00, 0x00, 0x00, // sample 1
        0x00, 0x24, 0x17, // sample 2
        0x1e, 0xf3, 0x3c, // sample 3
        0x13, 0x3c, 0x14, // sample 4
    ];

    let samples = Samples::from_bytes(&header, &bytes).unwrap();

    assert_eq!(
        samples,
        Samples::BitDepth24(vec![
    	    0x00000000, // sample 1
    	    0x17240000, // sample 2
    	    0x3cf31e00, // sample 3
    	    0x143c1300, // sample 4
        ])
    )
}

Trait Implementations

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.