pub struct ApeInfo {Show 20 fields
pub version: u16,
pub compression_level: u16,
pub sample_rate: u32,
pub channels: u16,
pub bits_per_sample: u16,
pub total_samples: u64,
pub total_frames: u32,
pub blocks_per_frame: u32,
pub final_frame_blocks: u32,
pub duration_ms: u64,
pub block_align: u16,
pub format_flags: u16,
pub bytes_per_sample: u16,
pub average_bitrate_kbps: u32,
pub decompressed_bitrate_kbps: u32,
pub file_size_bytes: u64,
pub is_big_endian: bool,
pub is_floating_point: bool,
pub is_signed_8bit: bool,
pub source_format: SourceFormat,
}Expand description
File metadata accessible without decoding.
Fields§
§version: u16§compression_level: u16§sample_rate: u32§channels: u16§bits_per_sample: u16§total_samples: u64§total_frames: u32§blocks_per_frame: u32§final_frame_blocks: u32§duration_ms: u64§block_align: u16§format_flags: u16§bytes_per_sample: u16§average_bitrate_kbps: u32§decompressed_bitrate_kbps: u32§file_size_bytes: u64§is_big_endian: bool§is_floating_point: bool§is_signed_8bit: bool§source_format: SourceFormatImplementations§
Source§impl ApeInfo
impl ApeInfo
Sourcepub fn frame_samples(&self, frame_idx: u32) -> u32
pub fn frame_samples(&self, frame_idx: u32) -> u32
Number of samples (blocks) in a given frame.
Sourcepub fn generate_wav_header(&self) -> Vec<u8> ⓘ
pub fn generate_wav_header(&self) -> Vec<u8> ⓘ
Generate a standard 44-byte RIFF/WAVE header for the decoded audio.
Use this when ApeDecoder::wav_header_data() returns None (the
CREATE_WAV_HEADER flag was set, meaning the original header was not
stored). Combine with decoded PCM to produce a valid WAV file:
ⓘ
let header = decoder.info().generate_wav_header();
let pcm = decoder.decode_all()?;
output.write_all(&header)?;
output.write_all(&pcm)?;Examples found in repository?
examples/decode_to_file.rs (line 47)
9fn main() {
10 let args: Vec<String> = std::env::args().collect();
11
12 let (raw_mode, input, output) = if args.len() == 4 && args[1] == "--raw" {
13 (true, &args[2], &args[3])
14 } else if args.len() == 3 {
15 (false, &args[1], &args[2])
16 } else {
17 eprintln!("Usage: decode_to_file [--raw] <input.ape> <output>");
18 std::process::exit(1);
19 };
20
21 let file = File::open(input).expect("failed to open input file");
22 let mut decoder =
23 ape_decoder::ApeDecoder::new(BufReader::new(file)).expect("failed to parse APE");
24
25 {
26 let info = decoder.info();
27 eprintln!(
28 "{}Hz, {} ch, {}-bit, {} samples ({} ms)",
29 info.sample_rate,
30 info.channels,
31 info.bits_per_sample,
32 info.total_samples,
33 info.duration_ms,
34 );
35 }
36
37 let pcm = decoder.decode_all().expect("failed to decode");
38 eprintln!("Decoded {} bytes of PCM", pcm.len());
39
40 let mut out = File::create(output).expect("failed to create output file");
41
42 if !raw_mode {
43 // Write WAV header: prefer stored header from the APE file, fall back to generated
44 let header = decoder
45 .wav_header_data()
46 .map(|h| h.to_vec())
47 .unwrap_or_else(|| decoder.info().generate_wav_header());
48 out.write_all(&header).expect("failed to write WAV header");
49 }
50
51 out.write_all(&pcm).expect("failed to write PCM data");
52 eprintln!("Wrote {}", output);
53}Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApeInfo
impl RefUnwindSafe for ApeInfo
impl Send for ApeInfo
impl Sync for ApeInfo
impl Unpin for ApeInfo
impl UnsafeUnpin for ApeInfo
impl UnwindSafe for ApeInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more