Implementation of synth waveforms, tests

This commit is contained in:
Jamie Hardt 2024-08-09 12:54:41 -07:00
parent eef2edaa3d
commit 107454efde

View file

@ -106,6 +106,7 @@ impl Source for SynthWaveform {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::source::synth::*; use crate::source::synth::*;
use approx::assert_abs_diff_eq;
#[test] #[test]
fn square() { fn square() {
@ -165,10 +166,17 @@ mod tests {
assert_eq!(wf.next(), Some(-1.0f32)); assert_eq!(wf.next(), Some(-1.0f32));
} }
// #[test] #[test]
// fn sine() { fn sine() {
// let mut wf = let mut wf =
// SynthWaveform::new(cpal::SampleRate(1000), 100f32, SynthWaveformFunction::Sine); SynthWaveform::new(cpal::SampleRate(1000), 100f32, SynthWaveformFunction::Sine);
//
// } assert_abs_diff_eq!(wf.next().unwrap(), 0.0f32);
assert_abs_diff_eq!(wf.next().unwrap(), 0.58778525f32);
assert_abs_diff_eq!(wf.next().unwrap(), 0.95105652f32);
assert_abs_diff_eq!(wf.next().unwrap(), 0.95105652f32);
assert_abs_diff_eq!(wf.next().unwrap(), 0.58778525f32);
assert_abs_diff_eq!(wf.next().unwrap(), 0.0f32);
assert_abs_diff_eq!(wf.next().unwrap(), -0.58778554f32);
}
} }