use std::time::Duration;
use crate::source::{Function, SignalGenerator};
use crate::Source;
use super::SeekError;
#[derive(Clone, Debug)]
pub struct SineWave {
test_sine: SignalGenerator,
}
impl SineWave {
const SAMPLE_RATE: u32 = 48000;
#[inline]
pub fn new(freq: f32) -> SineWave {
let sr = cpal::SampleRate(Self::SAMPLE_RATE);
SineWave {
test_sine: SignalGenerator::new(sr, freq, Function::Sine),
}
}
}
impl Iterator for SineWave {
type Item = f32;
#[inline]
fn next(&mut self) -> Option<f32> {
self.test_sine.next()
}
}
impl Source for SineWave {
#[inline]
fn current_frame_len(&self) -> Option<usize> {
None
}
#[inline]
fn channels(&self) -> u16 {
1
}
#[inline]
fn sample_rate(&self) -> u32 {
Self::SAMPLE_RATE
}
#[inline]
fn total_duration(&self) -> Option<Duration> {
None
}
#[inline]
fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> {
Ok(())
}
}