Implement writer for the missing block types.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Yet to be tested.
This commit is contained in:
parent
544e26676c
commit
4b0e58bb2c
|
@ -48,6 +48,34 @@ fn write_sound_data_continuation(block: &BlockType) -> Vec<u8> {
|
|||
bytes
|
||||
}
|
||||
|
||||
fn write_silence(block: &BlockType) -> Vec<u8> {
|
||||
let mut bytes: Vec<u8> = Vec::new();
|
||||
bytes.extend_from_slice(&[3]);
|
||||
if let BlockType::Silence {
|
||||
length,
|
||||
sample_rate,
|
||||
} = block
|
||||
{
|
||||
let header_size = 3;
|
||||
bytes.extend_from_slice(&get_size(header_size));
|
||||
bytes.extend_from_slice(&(length + 1).to_le_bytes());
|
||||
let frequency_divisor: u8 = (256_u32 - 1000000_u32 / sample_rate) as u8;
|
||||
bytes.extend_from_slice(&[frequency_divisor]);
|
||||
}
|
||||
bytes
|
||||
}
|
||||
|
||||
fn write_marker(block: &BlockType) -> Vec<u8> {
|
||||
let mut bytes: Vec<u8> = Vec::new();
|
||||
bytes.extend_from_slice(&[4]);
|
||||
if let BlockType::Marker { value } = block {
|
||||
let header_size = 2;
|
||||
bytes.extend_from_slice(&get_size(header_size));
|
||||
bytes.extend_from_slice(&value.to_le_bytes());
|
||||
}
|
||||
bytes
|
||||
}
|
||||
|
||||
fn write_text(block: &BlockType) -> Vec<u8> {
|
||||
let mut bytes: Vec<u8> = Vec::new();
|
||||
bytes.extend_from_slice(&[5]);
|
||||
|
@ -142,14 +170,13 @@ fn write_block(block: &BlockType) -> Vec<u8> {
|
|||
BlockType::Terminator => write_terminator(),
|
||||
BlockType::SoundData { .. } => write_sound_data(block),
|
||||
BlockType::SoundDataContinuation { .. } => write_sound_data_continuation(block),
|
||||
//3 => parse_silence(input),
|
||||
//4 => parse_marker(input),
|
||||
BlockType::Silence { .. } => write_silence(block),
|
||||
BlockType::Marker { .. } => write_marker(block),
|
||||
BlockType::Text { .. } => write_text(block),
|
||||
BlockType::RepeatStart { .. } => write_repeat_start(block),
|
||||
BlockType::RepeatEnd => write_repeat_end(),
|
||||
BlockType::ExtraInformation { .. } => write_extra_information(block),
|
||||
BlockType::SoundDataNew { .. } => write_sound_data_new(block),
|
||||
_ => panic!("not implemented {:?}", block),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue