use crate::complex::Complex32;

pub struct DCBlocker
{
    alpha: f32,
    last_input: Complex32,
    last_output: Complex32,
}

impl DCBlocker
{
    pub fn new(alpha: f32) -> Self
    {
        DCBlocker
        {
            alpha,
            last_input: Complex32::zero(),
            last_output: Complex32::zero()
        }
    }

    pub fn next(&mut self, sample: Complex32) -> Complex32
    {
        let output = sample - self.last_input + self.last_output * self.alpha;
        self.last_output = output;
        self.last_input = sample;
        output
    }

    pub fn next_real(&mut self, sample: f32) -> f32
    {
        self.next(Complex32::new(sample, 0.)).re
    }
}
