crates/format/audio/src/lib.rs 1.6 KiB 47 lines Raw
1 //! inf3r-audio — the samples the engine carries.2 //!3 //! The crate is a leaf because audio crosses the core before any codec. Wav is4 //! the only container here: a plugin that needs opus links opus itself, so the5 //! core never links a codec that it does not use (spec section 18, rule 2).6 7 use std::fmt;8 9 pub mod mel;10 pub mod pcm;11 pub mod resample;12 pub mod wav;13 14 pub use pcm::Pcm;15 16 /// The reason an audio operation failed.17 #[derive(Clone, PartialEq, Eq, Debug)]18 pub enum AudioError {19     /// A block with no samples has no frame to carry.20     Empty,21     /// The rate is outside the range that a device or a model accepts.22     Rate,23     /// The channel count is neither mono nor stereo.24     Channels,25     /// The sample count does not agree with the channel count, or a filterbank26     /// does not have the dimensions that the caller named.27     Shape,28     /// A wav header or body does not have the shape that RIFF requires.29     Format(&'static str),30     /// The rate change is not an integer multiple or an integer divisor.31     Ratio,32 }33 34 impl fmt::Display for AudioError {35     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {36         match self {37             AudioError::Empty => write!(f, "the sample block is empty"),38             AudioError::Rate => write!(f, "the sample rate is not allowed"),39             AudioError::Channels => write!(f, "the channel count is not 1 or 2"),40             AudioError::Shape => write!(f, "the sample or filter shape does not fit"),41             AudioError::Format(why) => write!(f, "{why}"),42             AudioError::Ratio => write!(f, "the rate change is not an integer ratio"),43         }44     }45 }46 47 impl std::error::Error for AudioError {}