Enum wavv::Samples [−][src]
Expand description
Enum to hold samples for different bit depth
Variants
8 bit audio
Tuple Fields of BitDepth8
0: Vec<u8>
16 bit audio
Tuple Fields of BitDepth16
0: Vec<i16>
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 ]) ) }