mirror of
https://github.com/iluvcapra/bwavfile.git
synced 2025-12-31 08:50:44 +00:00
Merge pull request #11 from EaterLabs/misc-fixes
implement basic f32le support and some other misc fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::io;
|
||||
use std::{fmt::{Debug,Display}, io};
|
||||
use std::error::Error as StdError;
|
||||
use super::fourcc::FourCC;
|
||||
|
||||
use uuid;
|
||||
@@ -43,6 +44,14 @@ pub enum Error {
|
||||
|
||||
}
|
||||
|
||||
impl StdError for Error {}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(error: io::Error) -> Error {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -50,7 +50,7 @@ impl<R: Read + Seek> AudioFrameReader<R> {
|
||||
"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))?;
|
||||
@@ -122,7 +122,26 @@ impl<R: Read + Seek> AudioFrameReader<R> {
|
||||
}
|
||||
|
||||
pub fn read_float_frame(&mut self, buffer: &mut [f32]) -> Result<u64, Error> {
|
||||
todo!()
|
||||
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::<LittleEndian>()?,
|
||||
(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 )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user