Skip to main content

ApeInfo

Struct ApeInfo 

Source
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: SourceFormat

Implementations§

Source§

impl ApeInfo

Source

pub fn frame_samples(&self, frame_idx: u32) -> u32

Number of samples (blocks) in a given frame.

Source

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§

Source§

impl Clone for ApeInfo

Source§

fn clone(&self) -> ApeInfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ApeInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.