Skip to content

Commit

Permalink
Renamed Synth to Test
Browse files Browse the repository at this point in the history
Modules, files and types renamed
  • Loading branch information
iluvcapra committed Aug 15, 2024
1 parent a015eb4 commit 56d087a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,8 +65,8 @@ mod skippable;
mod spatial;
mod speed;
mod stoppable;
mod synth;
mod take;
mod test_waveform;
mod uniform;
mod zero;

Expand Down
6 changes: 3 additions & 3 deletions src/source/sine.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use crate::source::{SynthWaveform, SynthWaveformFunction};
use crate::source::{TestWaveform, TestWaveformFunction};
use crate::Source;

use super::SeekError;
Expand All @@ -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 {
Expand All @@ -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),
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/source/synth.rs → src/source/test_waveform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -64,7 +64,7 @@ impl SynthWaveform {
}
}

impl Iterator for SynthWaveform {
impl Iterator for TestWaveform {
type Item = f32;

#[inline]
Expand All @@ -75,7 +75,7 @@ impl Iterator for SynthWaveform {
}
}

impl Source for SynthWaveform {
impl Source for TestWaveform {
#[inline]
fn current_frame_len(&self) -> Option<usize> {
None
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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);
Expand Down

0 comments on commit 56d087a

Please sign in to comment.