use crate::Curve;
use crate::error::{AutoeqError, Result};
use clap::ValueEnum;
use ndarray::Array1;
use std::collections::HashMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum LossType {
SpeakerFlat,
SpeakerFlatAsymmetric,
SpeakerScore,
HeadphoneFlat,
HeadphoneScore,
DriversFlat,
MultiSubFlat,
Epa,
}
#[derive(Debug, Clone)]
pub struct SpeakerLossData {
pub on: Array1<f64>,
pub lw: Array1<f64>,
pub sp: Array1<f64>,
pub pir: Array1<f64>,
}
impl SpeakerLossData {
pub fn try_new(spin: &HashMap<String, Curve>) -> Result<Self> {
let on = spin
.get("On Axis")
.ok_or_else(|| AutoeqError::MissingCea2034Curve {
curve_name: "On Axis".to_string(),
})?
.spl
.clone();
let lw = spin
.get("Listening Window")
.ok_or_else(|| AutoeqError::MissingCea2034Curve {
curve_name: "Listening Window".to_string(),
})?
.spl
.clone();
let sp = spin
.get("Sound Power")
.ok_or_else(|| AutoeqError::MissingCea2034Curve {
curve_name: "Sound Power".to_string(),
})?
.spl
.clone();
let pir = spin
.get("Estimated In-Room Response")
.ok_or_else(|| AutoeqError::MissingCea2034Curve {
curve_name: "Estimated In-Room Response".to_string(),
})?
.spl
.clone();
if on.len() != lw.len() || on.len() != sp.len() || on.len() != pir.len() {
return Err(AutoeqError::CurveLengthMismatch {
on_len: on.len(),
lw_len: lw.len(),
sp_len: sp.len(),
pir_len: pir.len(),
});
}
Ok(Self { on, lw, sp, pir })
}
}
#[derive(Debug, Clone)]
pub struct HeadphoneLossData {
pub smooth: bool,
pub smooth_n: usize,
}
impl HeadphoneLossData {
pub fn new(smooth: bool, smooth_n: usize) -> Self {
Self { smooth, smooth_n }
}
}