Renamed Synth to Test

Modules, files and types renamed
This commit is contained in:
Jamie Hardt 2024-08-15 00:33:02 -07:00
parent a015eb49a2
commit 56d087afbc
3 changed files with 23 additions and 23 deletions

View file

@ -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;

View file

@ -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),
}
}
}

View file

@ -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<usize> {
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);