symphonium 0.9.1

An unofficial easy-to-use wrapper around Symphonia for loading audio files
Documentation
#[cfg(all(feature = "log", not(feature = "tracing")))]
use log::warn;
#[cfg(feature = "tracing")]
use tracing::warn;

use super::LoadError;

const SHRINK_THRESHOLD: usize = 4096;

mod decode_f32;
mod decode_native;

#[cfg(feature = "resampler")]
mod decode_resampled_f32;
#[cfg(feature = "resampler")]
pub(crate) use decode_resampled_f32::*;

pub(crate) use decode_f32::*;
pub(crate) use decode_native::*;

fn check_total_frames(
    total_frames: &mut usize,
    max_frames: usize,
    packet_len: usize,
    max_bytes: usize,
) -> Result<(), LoadError> {
    *total_frames += packet_len;
    if *total_frames > max_frames {
        Err(LoadError::FileTooLarge(max_bytes))
    } else {
        Ok(())
    }
}

fn shrink_buffer<T>(channels: &mut [Vec<T>]) {
    for ch in channels.iter_mut() {
        // If the allocated capacity is significantly greater than the
        // length, shrink it to save memory.
        if ch.capacity() > ch.len() + SHRINK_THRESHOLD {
            ch.shrink_to_fit();
        }
    }
}

fn decode_warning(err: &str) {
    #[cfg(any(feature = "tracing", feature = "log"))]
    // Decode errors are not fatal. Print the error message and try to decode the next
    // packet as usual.
    warn!("Symphonia decode warning: {}", err);

    #[cfg(not(any(feature = "tracing", feature = "log")))]
    let _ = err;
}