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

fn bench_parametric_eq(c: &mut Criterion) {
    let audio = Arc::new(sine_wave::<f32, f32>(
        600.0,
        Duration::from_secs(5),
        44100,
        0.6,
    ));

    c.bench_function("parametric_eq::apply_peak_filter", |b| {
        let audio = audio.clone();
        b.iter(move || {
            let mut a = audio.as_ref().clone();
            // Apply a modest peak filter at 600 Hz, +6 dB, Q=1.0
            let _ = a
                .apply_peak_filter::<f32>(600.0_f32, 6.0_f32, 1.0_f32, 44100.0_f32)
                .unwrap();
            black_box(&a);
        })
    });

    c.bench_function("parametric_eq::apply_low_shelf", |b| {
        let audio = audio.clone();
        b.iter(move || {
            let mut a = audio.as_ref().clone();
            let _ = a
                .apply_low_shelf::<f32>(120.0_f32, 4.0_f32, 0.707_f32, 44100.0_f32)
                .unwrap();
            black_box(&a);
        })
    });

    c.bench_function("parametric_eq::three_band_eq", |b| {
        let audio = audio.clone();
        b.iter(move || {
            let mut a = audio.as_ref().clone();
            let _ = a
                .apply_three_band_eq::<f32>(
                    100.0_f32,
                    3.0_f32,
                    1000.0_f32,
                    -2.0_f32,
                    1.0_f32,
                    5000.0_f32,
                    2.0_f32,
                    44100.0_f32,
                )
                .unwrap();
            black_box(&a);
        })
    });

    c.bench_function("parametric_eq::eq_frequency_response", |b| {
        let audio = audio.clone();
        b.iter(move || {
            let a = audio.as_ref().clone();
            let eq = ParametricEq::three_band(
                100.0_f32, 3.0_f32, 1000.0_f32, -2.0_f32, 1.0_f32, 5000.0_f32, 2.0_f32,
            );
            let freqs = vec![100.0_f32, 500.0_f32, 1000.0_f32, 5000.0_f32];
            let _ = a.eq_frequency_response(&eq, &freqs, 44100.0_f32).unwrap();
            black_box(&eq);
        })
    });
}

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