use crate::*;

/// Generate a 100ms sine wave beep at 1000Hz
pub fn generate_beep<F: ChunkFactory>(
    sample_rate: u32,
    chunk_factory: &mut F,
) -> Result<Arc<AudioChunk>> {
    const FREQUENCY_HZ: f32 = 1000.0;
    const DURATION_MS: f32 = 100.0;

    let sample_count = ((sample_rate as f32) * (DURATION_MS / 1000.0)) as usize;
    let mut samples = Vec::with_capacity(sample_count);

    for i in 0..sample_count {
        let t = i as f32 / sample_rate as f32;
        let sample = (std::f32::consts::TAU * FREQUENCY_HZ * t).sin();
        samples.push(sample);
    }

    // Create AudioChunk and fill it with samples
    let mut chunk = chunk_factory.create_chunk()?;
    chunk.append_samples(&samples, chunk_factory)?;

    Ok(chunk)
}
