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

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

    c.bench_function("dynamic_range::apply_compressor", |b| {
        let audio = audio.clone();
        b.iter(move || {
            let mut a = audio.as_ref().clone();
            let cfg = CompressorConfig::vocal();
            let _ = a.apply_compressor(&cfg, 44100.0_f32).unwrap();
            black_box(&a);
        })
    });

    c.bench_function("dynamic_range::apply_limiter", |b| {
        let audio = audio.clone();
        b.iter(move || {
            let mut a = audio.as_ref().clone();
            let cfg = LimiterConfig::mastering();
            let _ = a.apply_limiter(&cfg, 44100.0_f32).unwrap();
            black_box(&a);
        })
    });

    c.bench_function("dynamic_range::get_compression_curve", |b| {
        let audio = audio.clone();
        b.iter(move || {
            let a = audio.as_ref().clone();
            let cfg = CompressorConfig::vocal();
            let levels = vec![-40.0_f32, -20.0_f32, -10.0_f32, -3.0_f32, 0.0_f32];
            let _ = a.get_compression_curve(&cfg, &levels, 44100.0_f32).unwrap();
        })
    });
}

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