Implement ExtraInformation block - untested.

This commit is contained in:
Pedro de Oliveira 2023-04-28 12:27:37 +01:00
parent c7a6001b8b
commit 80d578e3ca
1 changed files with 38 additions and 3 deletions

View File

@ -38,7 +38,11 @@ pub enum BlockType {
count: u16,
},
RepeatEnd,
//8 ExtraInformation
ExtraInformation {
sample_rate: u32,
codec: Codec,
channels: u8,
},
SoundDataNew {
sample_rate: u32,
bits: u8,
@ -89,6 +93,12 @@ impl BlockType {
BlockType::RepeatEnd => {
println!("End repeat")
}
BlockType::ExtraInformation {sample_rate,codec, channels} => println!(
"Extra information: sample rate = {}, channels = {}, codec = {:?}",
sample_rate,
channels,
codec,
),
BlockType::SoundDataNew {
sample_rate, bits, channels, codec, reserved, data
} => println!(
@ -170,7 +180,7 @@ pub fn parse_block(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
Ok((
input,
BlockType::Silence {
length,
length: length - 1,
sample_rate,
},
))
@ -196,7 +206,32 @@ pub fn parse_block(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
Ok((input, BlockType::RepeatStart { count }))
}
7 => Ok((input, BlockType::RepeatEnd)),
8 => panic!("ExtraInformation - Not Implemented"),
8 => {
let (input, _) = number::streaming::le_u24(input)?;
let (input, frequency_divisor) = number::streaming::le_u16(input)?;
let (input, codec_id) = number::streaming::le_u8(input)?;
let (input, channels) = number::streaming::le_u8(input)?;
let codec = match codec_id {
0 => Codec::Pcm8BitUnsigned,
1 => Codec::Adpcm4to8,
2 => Codec::Adpcm3to8,
3 => Codec::Adpcm2to8,
4 => Codec::Pcm16BitSigned,
5 => Codec::Alaw,
6 => Codec::Ulaw,
_ => panic!("Invalid sound format"),
};
let sample_rate: u32 =
256000000_u32 / ((channels as u32 + 1) * (65536 - frequency_divisor as u32));
Ok((
input,
BlockType::ExtraInformation {
sample_rate,
codec,
channels,
},
))
}
9 => {
let (input, block_size) = number::streaming::le_u24(input)?;
let (input, sample_rate) = number::streaming::le_u32(input)?;