diff --git a/src/source/mod.rs b/src/source/mod.rs index 059c84e..6043318 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -33,7 +33,7 @@ pub use self::skippable::Skippable; pub use self::spatial::Spatial; pub use self::speed::Speed; pub use self::stoppable::Stoppable; -pub use self::synth::{SynthWaveform, SynthWaveformFunction}; +pub use self::test_waveform::{TestWaveform, TestWaveformFunction}; pub use self::take::TakeDuration; pub use self::uniform::UniformSourceIterator; pub use self::zero::Zero; @@ -65,8 +65,8 @@ mod skippable; mod spatial; mod speed; mod stoppable; -mod synth; mod take; +mod test_waveform; mod uniform; mod zero; diff --git a/src/source/sine.rs b/src/source/sine.rs index 6e78ec6..b9c11a0 100644 --- a/src/source/sine.rs +++ b/src/source/sine.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use crate::source::{SynthWaveform, SynthWaveformFunction}; +use crate::source::{TestWaveform, TestWaveformFunction}; use crate::Source; use super::SeekError; @@ -12,7 +12,7 @@ const SAMPLE_RATE: u32 = 48000; /// Always has a rate of 48kHz and one channel. #[derive(Clone, Debug)] pub struct SineWave { - synth: SynthWaveform, + synth: TestWaveform, } impl SineWave { @@ -21,7 +21,7 @@ impl SineWave { pub fn new(freq: f32) -> SineWave { let sr = cpal::SampleRate(SAMPLE_RATE); SineWave { - synth: SynthWaveform::new(sr, freq, SynthWaveformFunction::Sine), + synth: TestWaveform::new(sr, freq, TestWaveformFunction::Sine), } } } diff --git a/src/source/synth.rs b/src/source/test_waveform.rs similarity index 86% rename from src/source/synth.rs rename to src/source/test_waveform.rs index e87dfe9..6919bea 100644 --- a/src/source/synth.rs +++ b/src/source/test_waveform.rs @@ -7,14 +7,14 @@ use crate::Source; /// Syntheizer waveform functions. All of the synth waveforms are in the /// codomain [-1.0, 1.0]. #[derive(Clone, Debug)] -pub enum SynthWaveformFunction { +pub enum TestWaveformFunction { Sine, Triangle, Square, Sawtooth, } -impl SynthWaveformFunction { +impl TestWaveformFunction { /// Create a single sample for the given waveform #[inline] pub fn render(&self, i: u64, period: f32) -> f32 { @@ -38,24 +38,24 @@ impl SynthWaveformFunction { /// An infinite source that produces one of a selection of synthesizer /// waveforms. #[derive(Clone, Debug)] -pub struct SynthWaveform { +pub struct TestWaveform { sample_rate: cpal::SampleRate, period: f32, - f: SynthWaveformFunction, + f: TestWaveformFunction, i: u64, } -impl SynthWaveform { +impl TestWaveform { /// Create a new `SynthWaveform` object that generates an endless waveform /// `f`. #[inline] pub fn new( sample_rate: cpal::SampleRate, frequency: f32, - f: SynthWaveformFunction, - ) -> SynthWaveform { + f: TestWaveformFunction, + ) -> TestWaveform { let period = sample_rate.0 as f32 / frequency; - SynthWaveform { + TestWaveform { sample_rate, period, f, @@ -64,7 +64,7 @@ impl SynthWaveform { } } -impl Iterator for SynthWaveform { +impl Iterator for TestWaveform { type Item = f32; #[inline] @@ -75,7 +75,7 @@ impl Iterator for SynthWaveform { } } -impl Source for SynthWaveform { +impl Source for TestWaveform { #[inline] fn current_frame_len(&self) -> Option { None @@ -105,15 +105,15 @@ impl Source for SynthWaveform { #[cfg(test)] mod tests { - use crate::source::synth::*; + use crate::source::{TestWaveform, TestWaveformFunction}; use approx::assert_abs_diff_eq; #[test] fn square() { - let mut wf = SynthWaveform::new( + let mut wf = TestWaveform::new( cpal::SampleRate(2000), 500.0f32, - SynthWaveformFunction::Square, + TestWaveformFunction::Square, ); assert_eq!(wf.next(), Some(1.0f32)); assert_eq!(wf.next(), Some(1.0f32)); @@ -127,10 +127,10 @@ mod tests { #[test] fn triangle() { - let mut wf = SynthWaveform::new( + let mut wf = TestWaveform::new( cpal::SampleRate(8000), 1000.0f32, - SynthWaveformFunction::Triangle, + TestWaveformFunction::Triangle, ); assert_eq!(wf.next(), Some(-1.0f32)); assert_eq!(wf.next(), Some(-0.5f32)); @@ -152,10 +152,10 @@ mod tests { #[test] fn saw() { - let mut wf = SynthWaveform::new( + let mut wf = TestWaveform::new( cpal::SampleRate(200), 50.0f32, - SynthWaveformFunction::Sawtooth, + TestWaveformFunction::Sawtooth, ); assert_eq!(wf.next(), Some(0.0f32)); assert_eq!(wf.next(), Some(0.5f32)); @@ -169,7 +169,7 @@ mod tests { #[test] fn sine() { let mut wf = - SynthWaveform::new(cpal::SampleRate(1000), 100f32, SynthWaveformFunction::Sine); + TestWaveform::new(cpal::SampleRate(1000), 100f32, TestWaveformFunction::Sine); assert_abs_diff_eq!(wf.next().unwrap(), 0.0f32); assert_abs_diff_eq!(wf.next().unwrap(), 0.58778525f32);