pile-audio refactor
Some checks failed
CI / Typos (push) Successful in 17s
CI / Clippy (push) Has been cancelled
CI / Build and test (push) Has been cancelled

This commit is contained in:
2026-02-21 19:14:52 -08:00
parent 5aab61bd1b
commit 4b41467cc2
35 changed files with 1968 additions and 3366 deletions

View File

@@ -0,0 +1,42 @@
use crate::{FlacDecodeError, FlacEncodeError};
use std::fmt::Debug;
/// An audio frame in a flac file
pub struct FlacAudioFrame {
/// The audio frame
pub data: Vec<u8>,
}
impl Debug for FlacAudioFrame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("FlacAudioFrame")
.field("data_len", &self.data.len())
.finish()
}
}
impl FlacAudioFrame {
/// Decode the given data as a flac audio frame.
/// This should start with a sync sequence.
pub fn decode(data: &[u8]) -> Result<Self, FlacDecodeError> {
if data.len() <= 2 {
return Err(FlacDecodeError::MalformedBlock);
}
if !(data[0] == 0b1111_1111 && data[1] & 0b1111_1100 == 0b1111_1000) {
return Err(FlacDecodeError::BadSyncBytes);
}
Ok(Self {
data: Vec::from(data),
})
}
}
impl FlacAudioFrame {
/// Encode this audio frame.
pub fn encode(&self, target: &mut impl std::io::Write) -> Result<(), FlacEncodeError> {
target.write_all(&self.data)?;
return Ok(());
}
}