hps_decode 0.3.0

A library for parsing and decoding Super Smash Bros. Melee music files
Documentation
use thiserror::Error;
use winnow::error::ContextError;

use crate::hps::COEFFICIENT_PAIRS_PER_CHANNEL;

#[derive(Error, Debug)]
pub enum HpsParseError {
    /// The first 8 bytes in the file are not ` HALPST\0`
    #[error("Invalid magic number. Expected ' HALPST\0'")]
    InvalidMagicNumber,

    /// The number of audio channels in the provided file is not supported by the library
    #[error("Only stereo is supported, but the provided file has {0} audio channel(s)")]
    UnsupportedChannelCount(u32),

    #[error("Tried to parse, but encountered invalid data. Cause: {}",
    match .0.cause() {
        Some(cause) => cause.to_string(),
        None => "None".to_string()
    })]
    InvalidData(ContextError),
}

impl From<ContextError> for HpsParseError {
    fn from(error: ContextError) -> Self {
        HpsParseError::InvalidData(error)
    }
}

#[derive(Error, Debug)]
pub enum HpsDecodeError {
    #[error(
        "One of the audio frame headers contains a coefficient index of {0} which is invalid. Length of the coefficients array is {COEFFICIENT_PAIRS_PER_CHANNEL}"
    )]
    InvalidCoefficientIndex(usize),
}