diff --git a/src/fmt.rs b/src/fmt.rs index 9dc6d76..dae4793 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -18,6 +18,7 @@ use byteorder::{WriteBytesExt, ReadBytesExt}; /// `AudioProgramme`. /// /// See BS.2088-1 ยง 8, also BS.2094, also blahblahblah... +#[derive(Debug)] pub struct ADMAudioID { pub track_uid: [char; 12], pub channel_format_ref: [char; 14], @@ -28,6 +29,7 @@ pub struct ADMAudioID { /// /// This information is correlated from the Wave format ChannelMap field and /// the `chna` chunk, if present. +#[derive(Debug)] pub struct ChannelDescriptor { /// Index, the offset of this channel's samples in one frame. pub index: u16, diff --git a/src/wavereader.rs b/src/wavereader.rs index a3d9780..5fa7b2e 100644 --- a/src/wavereader.rs +++ b/src/wavereader.rs @@ -50,7 +50,7 @@ impl AudioFrameReader { "Unable to read audio frames from packed formats: block alignment is {}, should be {}", format.block_alignment, (format.bits_per_sample / 8 ) * format.channel_count); - assert!(format.common_format() == CommonFormat::IntegerPCM , + assert!(format.common_format() == CommonFormat::IntegerPCM || format.common_format() == CommonFormat::IeeeFloatPCM, "Unsupported format tag {:?}", format.tag); inner.seek(Start(start))?; @@ -121,8 +121,27 @@ impl AudioFrameReader { } } - pub fn read_float_frame(&mut self, buffer:&mut [f32]) -> Result { - todo!() + pub fn read_float_frame(&mut self, buffer: &mut [f32]) -> Result { + assert!(buffer.len() as u16 == self.format.channel_count, + "read_float_frame was called with a mis-sized buffer, expected {}, was {}", + self.format.channel_count, buffer.len()); + + let framed_bits_per_sample = self.format.block_alignment * 8 / self.format.channel_count; + + let tell = self.inner.seek(Current(0))?; + + if (tell - self.start) < self.length { + for n in 0..(self.format.channel_count as usize) { + buffer[n] = match (self.format.bits_per_sample, framed_bits_per_sample) { + (25..=32,32) => self.inner.read_f32::()?, + (b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}", + b, self.format.channel_count, self.format.block_alignment) + } + } + Ok( 1 ) + } else { + Ok( 0 ) + } } }