use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct DcBlocker {
x_prev: f32,
y_prev: f32,
r: f32,
}
impl DcBlocker {
pub fn new() -> Self {
Self {
x_prev: 0.0,
y_prev: 0.0,
r: 0.995,
}
}
#[inline]
pub fn process(&mut self, x: f32) -> f32 {
let y = x - self.x_prev + self.r * self.y_prev;
self.x_prev = x;
self.y_prev = y;
y
}
#[inline]
pub fn process_buffer(&mut self, samples: &mut [f32]) {
for s in samples.iter_mut() {
*s = self.process(*s);
}
}
pub fn reset(&mut self) {
self.x_prev = 0.0;
self.y_prev = 0.0;
}
}
#[cfg(feature = "naad-backend")]
#[allow(dead_code)]
pub(crate) fn map_naad_error(
synth_name: &str,
component: &str,
err: naad::NaadError,
) -> crate::error::PraniError {
let msg = alloc::format!("{synth_name}: {component} init failed: {err}");
#[cfg(feature = "logging")]
tracing::error!(synth = synth_name, component, %err, "naad backend error");
crate::error::PraniError::SynthesisFailed(msg)
}