Just include used stuff.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
3998101bb0
commit
aa66c35ed4
|
@ -1,5 +1,6 @@
|
|||
use nom::bytes::streaming::tag;
|
||||
use nom::number;
|
||||
use nom::bytes::streaming::{tag, take};
|
||||
use nom::number::streaming::{le_u16, le_u24, le_u32, le_u8};
|
||||
use nom::IResult;
|
||||
|
||||
#[derive(Eq, Debug, PartialEq)]
|
||||
pub enum Codec {
|
||||
|
@ -133,10 +134,10 @@ pub struct Voc {
|
|||
pub blocks: Vec<BlockType>,
|
||||
}
|
||||
|
||||
fn parse_sound_data(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
||||
let (input, block_size) = number::streaming::le_u24(input)?;
|
||||
let (input, frequency_divisor) = number::streaming::le_u8(input)?;
|
||||
let (input, codec_id) = number::streaming::le_u8(input)?;
|
||||
fn parse_sound_data(input: &[u8]) -> IResult<&[u8], BlockType> {
|
||||
let (input, block_size) = le_u24(input)?;
|
||||
let (input, frequency_divisor) = le_u8(input)?;
|
||||
let (input, codec_id) = le_u8(input)?;
|
||||
let sample_rate: u32 = 1000000_u32 / (256_u32 - frequency_divisor as u32);
|
||||
let codec = match codec_id {
|
||||
0 => Codec::Pcm8BitUnsigned,
|
||||
|
@ -148,7 +149,7 @@ fn parse_sound_data(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
|||
6 => Codec::Ulaw,
|
||||
_ => panic!("Invalid sound format"),
|
||||
};
|
||||
let (input, data) = nom::bytes::complete::take(block_size - 2)(input)?;
|
||||
let (input, data) = take(block_size - 2)(input)?;
|
||||
Ok((
|
||||
input,
|
||||
BlockType::SoundData {
|
||||
|
@ -159,9 +160,9 @@ fn parse_sound_data(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
|||
))
|
||||
}
|
||||
|
||||
fn parse_sound_data_continuation(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
||||
let (input, block_size) = number::streaming::le_u24(input)?;
|
||||
let (input, data) = nom::bytes::complete::take(block_size)(input)?;
|
||||
fn parse_sound_data_continuation(input: &[u8]) -> IResult<&[u8], BlockType> {
|
||||
let (input, block_size) = le_u24(input)?;
|
||||
let (input, data) = take(block_size)(input)?;
|
||||
Ok((
|
||||
input,
|
||||
BlockType::SoundDataContinuation {
|
||||
|
@ -170,10 +171,10 @@ fn parse_sound_data_continuation(input: &[u8]) -> nom::IResult<&[u8], BlockType>
|
|||
))
|
||||
}
|
||||
|
||||
fn parse_silence(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
||||
let (input, _) = number::streaming::le_u16(input)?;
|
||||
let (input, length) = number::streaming::le_u16(input)?;
|
||||
let (input, frequency_divisor) = number::streaming::le_u8(input)?;
|
||||
fn parse_silence(input: &[u8]) -> IResult<&[u8], BlockType> {
|
||||
let (input, _) = le_u16(input)?;
|
||||
let (input, length) = le_u16(input)?;
|
||||
let (input, frequency_divisor) = le_u8(input)?;
|
||||
let sample_rate: u32 = 1000000_u32 / (256_u32 - frequency_divisor as u32);
|
||||
Ok((
|
||||
input,
|
||||
|
@ -184,15 +185,15 @@ fn parse_silence(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
|||
))
|
||||
}
|
||||
|
||||
fn parse_marker(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
||||
let (input, _) = number::streaming::le_u16(input)?;
|
||||
let (input, value) = number::streaming::le_u16(input)?;
|
||||
fn parse_marker(input: &[u8]) -> IResult<&[u8], BlockType> {
|
||||
let (input, _) = le_u16(input)?;
|
||||
let (input, value) = le_u16(input)?;
|
||||
Ok((input, BlockType::Marker { value }))
|
||||
}
|
||||
|
||||
fn parse_text(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
||||
let (input, block_size) = number::streaming::le_u24(input)?;
|
||||
let (input, data) = nom::bytes::complete::take(block_size)(input)?;
|
||||
fn parse_text(input: &[u8]) -> IResult<&[u8], BlockType> {
|
||||
let (input, block_size) = le_u24(input)?;
|
||||
let (input, data) = take(block_size)(input)?;
|
||||
Ok((
|
||||
input,
|
||||
BlockType::Text {
|
||||
|
@ -201,17 +202,17 @@ fn parse_text(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
|||
))
|
||||
}
|
||||
|
||||
fn parse_repeat_start(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
||||
let (input, _) = number::streaming::le_u24(input)?;
|
||||
let (input, count) = number::streaming::le_u16(input)?;
|
||||
fn parse_repeat_start(input: &[u8]) -> IResult<&[u8], BlockType> {
|
||||
let (input, _) = le_u24(input)?;
|
||||
let (input, count) = le_u16(input)?;
|
||||
Ok((input, BlockType::RepeatStart { count }))
|
||||
}
|
||||
|
||||
fn parse_extra_information(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
||||
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)?;
|
||||
fn parse_extra_information(input: &[u8]) -> IResult<&[u8], BlockType> {
|
||||
let (input, _) = le_u24(input)?;
|
||||
let (input, frequency_divisor) = le_u16(input)?;
|
||||
let (input, codec_id) = le_u8(input)?;
|
||||
let (input, channels) = le_u8(input)?;
|
||||
let codec = match codec_id {
|
||||
0 => Codec::Pcm8BitUnsigned,
|
||||
1 => Codec::Adpcm4to8,
|
||||
|
@ -234,14 +235,14 @@ fn parse_extra_information(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
|||
))
|
||||
}
|
||||
|
||||
fn parse_sound_data_new(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
||||
let (input, block_size) = number::streaming::le_u24(input)?;
|
||||
let (input, sample_rate) = number::streaming::le_u32(input)?;
|
||||
let (input, bits) = number::streaming::le_u8(input)?;
|
||||
let (input, channels) = number::streaming::le_u8(input)?;
|
||||
let (input, codec_id) = number::streaming::le_u16(input)?;
|
||||
let (input, reserved) = number::streaming::le_u32(input)?;
|
||||
let (input, data) = nom::bytes::complete::take(block_size - 12)(input)?;
|
||||
fn parse_sound_data_new(input: &[u8]) -> IResult<&[u8], BlockType> {
|
||||
let (input, block_size) = le_u24(input)?;
|
||||
let (input, sample_rate) = le_u32(input)?;
|
||||
let (input, bits) = le_u8(input)?;
|
||||
let (input, channels) = le_u8(input)?;
|
||||
let (input, codec_id) = le_u16(input)?;
|
||||
let (input, reserved) = le_u32(input)?;
|
||||
let (input, data) = take(block_size - 12)(input)?;
|
||||
let codec = match codec_id {
|
||||
0 => Codec::Pcm8BitUnsigned,
|
||||
1 => Codec::Adpcm4to8,
|
||||
|
@ -266,8 +267,8 @@ fn parse_sound_data_new(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
|||
))
|
||||
}
|
||||
|
||||
pub fn parse_block(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
||||
let (input, block_type) = number::streaming::le_u8(input)?;
|
||||
pub fn parse_block(input: &[u8]) -> IResult<&[u8], BlockType> {
|
||||
let (input, block_type) = le_u8(input)?;
|
||||
match block_type {
|
||||
0 => Ok((input, BlockType::Terminator)),
|
||||
1 => parse_sound_data(input),
|
||||
|
@ -283,12 +284,12 @@ pub fn parse_block(input: &[u8]) -> nom::IResult<&[u8], BlockType> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_voc(input: &[u8]) -> nom::IResult<&[u8], Voc> {
|
||||
pub fn parse_voc(input: &[u8]) -> IResult<&[u8], Voc> {
|
||||
let (input, _) = tag("Creative Voice File")(input)?;
|
||||
let (input, _) = tag(&[0x1a, 0x1a, 0])(input)?;
|
||||
let (input, version_minor) = number::streaming::le_u8(input)?;
|
||||
let (input, version_major) = number::streaming::le_u8(input)?;
|
||||
let (input, checksum) = number::streaming::le_u16(input)?;
|
||||
let (input, version_minor) = le_u8(input)?;
|
||||
let (input, version_major) = le_u8(input)?;
|
||||
let (input, checksum) = le_u16(input)?;
|
||||
|
||||
// Calculate checksum from version
|
||||
let checksum2 = (!i16::from_le_bytes([version_minor, version_major]) + 0x1234) as u16;
|
||||
|
|
Loading…
Reference in New Issue