use audio_samples::operations::AudioIirFiltering;
use audio_samples::sine_wave;
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use std::sync::Arc;
use std::time::Duration;

fn bench_iir_filters(c: &mut Criterion) {
    let audio = Arc::new(sine_wave::<f32, f32>(
        1000.0,
        Duration::from_secs_f32(0.25),
        44100,
        0.4,
    ));

    c.bench_function("iir_filtering::butterworth_lowpass", |b| {
        let audio = audio.clone();
        b.iter(move || {
            let mut a = audio.as_ref().clone();
            // 2nd-order Butterworth lowpass at 1500 Hz
            let _ = a
                .butterworth_lowpass::<f32>(2, 1500.0_f32, 44100.0_f32)
                .unwrap();
            black_box(&a);
        })
    });

    c.bench_function("iir_filtering::frequency_response", |b| {
        let audio = audio.clone();
        b.iter(move || {
            let a = audio.as_ref().clone();
            let freqs = vec![200.0_f32, 500.0_f32, 1000.0_f32, 2000.0_f32];
            let _ = a.frequency_response(&freqs, 44100.0_f32).unwrap();
        })
    });
}

criterion_group!(benches, bench_iir_filters);
criterion_main!(benches);
