use crate::config::SpeakerConfig;
use crate::{MeasurementRef, MeasurementSource};
pub(super) const PHASE_LINEAR_RECOMMENDED_MAX_FREQ_HZ: f64 = 2000.0;
pub fn collect_sources(speaker: &SpeakerConfig) -> Vec<&MeasurementSource> {
match speaker {
SpeakerConfig::SupportingSource(s) => vec![&s.primary, &s.support],
SpeakerConfig::Single(s) => vec![s],
SpeakerConfig::Group(g) => g.measurements.iter().collect(),
SpeakerConfig::Topology(t) => t.drivers.iter().map(|driver| &driver.measurement).collect(),
SpeakerConfig::MultiSub(m) => m.subwoofers.iter().collect(),
SpeakerConfig::Cardioid(c) => vec![&c.front, &c.rear],
SpeakerConfig::Dba(d) => d.front.iter().chain(d.rear.iter()).collect(),
}
}
pub(super) fn source_is_cea2034_shaped(source: &MeasurementSource) -> bool {
if source.speaker_name().is_some() {
return true;
}
let path_hints = |path: &std::path::Path| {
let lower = path.to_string_lossy().to_lowercase();
lower.contains("cea2034") || lower.contains("spinorama") || lower.contains("cea-2034")
};
let ref_hint = |r: &MeasurementRef| match r {
MeasurementRef::Path(p) => path_hints(p),
MeasurementRef::Named { path, name } => {
path_hints(path)
|| name
.as_deref()
.map(|n| {
n.to_lowercase().contains("cea2034")
|| n.to_lowercase().contains("spinorama")
})
.unwrap_or(false)
}
MeasurementRef::Inline(_) => false,
};
match source {
MeasurementSource::Single(s) => ref_hint(&s.measurement),
MeasurementSource::Multiple(m) => m.measurements.iter().any(ref_hint),
MeasurementSource::InMemory(_) | MeasurementSource::InMemoryMultiple(_) => false,
}
}
pub(super) fn is_valid_speaker_name(name: &str) -> bool {
if name.is_empty() {
return false;
}
name.chars()
.all(|c| c.is_alphanumeric() || c == ' ' || c == '-')
}