mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 21:52:38 +00:00
Renamed Synth to Test
Modules, files and types renamed
This commit is contained in:
parent
a015eb49a2
commit
56d087afbc
3 changed files with 23 additions and 23 deletions
|
@ -33,7 +33,7 @@ pub use self::skippable::Skippable;
|
||||||
pub use self::spatial::Spatial;
|
pub use self::spatial::Spatial;
|
||||||
pub use self::speed::Speed;
|
pub use self::speed::Speed;
|
||||||
pub use self::stoppable::Stoppable;
|
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::take::TakeDuration;
|
||||||
pub use self::uniform::UniformSourceIterator;
|
pub use self::uniform::UniformSourceIterator;
|
||||||
pub use self::zero::Zero;
|
pub use self::zero::Zero;
|
||||||
|
@ -65,8 +65,8 @@ mod skippable;
|
||||||
mod spatial;
|
mod spatial;
|
||||||
mod speed;
|
mod speed;
|
||||||
mod stoppable;
|
mod stoppable;
|
||||||
mod synth;
|
|
||||||
mod take;
|
mod take;
|
||||||
|
mod test_waveform;
|
||||||
mod uniform;
|
mod uniform;
|
||||||
mod zero;
|
mod zero;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::source::{SynthWaveform, SynthWaveformFunction};
|
use crate::source::{TestWaveform, TestWaveformFunction};
|
||||||
use crate::Source;
|
use crate::Source;
|
||||||
|
|
||||||
use super::SeekError;
|
use super::SeekError;
|
||||||
|
@ -12,7 +12,7 @@ const SAMPLE_RATE: u32 = 48000;
|
||||||
/// Always has a rate of 48kHz and one channel.
|
/// Always has a rate of 48kHz and one channel.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SineWave {
|
pub struct SineWave {
|
||||||
synth: SynthWaveform,
|
synth: TestWaveform,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SineWave {
|
impl SineWave {
|
||||||
|
@ -21,7 +21,7 @@ impl SineWave {
|
||||||
pub fn new(freq: f32) -> SineWave {
|
pub fn new(freq: f32) -> SineWave {
|
||||||
let sr = cpal::SampleRate(SAMPLE_RATE);
|
let sr = cpal::SampleRate(SAMPLE_RATE);
|
||||||
SineWave {
|
SineWave {
|
||||||
synth: SynthWaveform::new(sr, freq, SynthWaveformFunction::Sine),
|
synth: TestWaveform::new(sr, freq, TestWaveformFunction::Sine),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,14 @@ use crate::Source;
|
||||||
/// Syntheizer waveform functions. All of the synth waveforms are in the
|
/// Syntheizer waveform functions. All of the synth waveforms are in the
|
||||||
/// codomain [-1.0, 1.0].
|
/// codomain [-1.0, 1.0].
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum SynthWaveformFunction {
|
pub enum TestWaveformFunction {
|
||||||
Sine,
|
Sine,
|
||||||
Triangle,
|
Triangle,
|
||||||
Square,
|
Square,
|
||||||
Sawtooth,
|
Sawtooth,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SynthWaveformFunction {
|
impl TestWaveformFunction {
|
||||||
/// Create a single sample for the given waveform
|
/// Create a single sample for the given waveform
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn render(&self, i: u64, period: f32) -> f32 {
|
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
|
/// An infinite source that produces one of a selection of synthesizer
|
||||||
/// waveforms.
|
/// waveforms.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SynthWaveform {
|
pub struct TestWaveform {
|
||||||
sample_rate: cpal::SampleRate,
|
sample_rate: cpal::SampleRate,
|
||||||
period: f32,
|
period: f32,
|
||||||
f: SynthWaveformFunction,
|
f: TestWaveformFunction,
|
||||||
i: u64,
|
i: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SynthWaveform {
|
impl TestWaveform {
|
||||||
/// Create a new `SynthWaveform` object that generates an endless waveform
|
/// Create a new `SynthWaveform` object that generates an endless waveform
|
||||||
/// `f`.
|
/// `f`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
sample_rate: cpal::SampleRate,
|
sample_rate: cpal::SampleRate,
|
||||||
frequency: f32,
|
frequency: f32,
|
||||||
f: SynthWaveformFunction,
|
f: TestWaveformFunction,
|
||||||
) -> SynthWaveform {
|
) -> TestWaveform {
|
||||||
let period = sample_rate.0 as f32 / frequency;
|
let period = sample_rate.0 as f32 / frequency;
|
||||||
SynthWaveform {
|
TestWaveform {
|
||||||
sample_rate,
|
sample_rate,
|
||||||
period,
|
period,
|
||||||
f,
|
f,
|
||||||
|
@ -64,7 +64,7 @@ impl SynthWaveform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator for SynthWaveform {
|
impl Iterator for TestWaveform {
|
||||||
type Item = f32;
|
type Item = f32;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -75,7 +75,7 @@ impl Iterator for SynthWaveform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Source for SynthWaveform {
|
impl Source for TestWaveform {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn current_frame_len(&self) -> Option<usize> {
|
fn current_frame_len(&self) -> Option<usize> {
|
||||||
None
|
None
|
||||||
|
@ -105,15 +105,15 @@ impl Source for SynthWaveform {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::source::synth::*;
|
use crate::source::{TestWaveform, TestWaveformFunction};
|
||||||
use approx::assert_abs_diff_eq;
|
use approx::assert_abs_diff_eq;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn square() {
|
fn square() {
|
||||||
let mut wf = SynthWaveform::new(
|
let mut wf = TestWaveform::new(
|
||||||
cpal::SampleRate(2000),
|
cpal::SampleRate(2000),
|
||||||
500.0f32,
|
500.0f32,
|
||||||
SynthWaveformFunction::Square,
|
TestWaveformFunction::Square,
|
||||||
);
|
);
|
||||||
assert_eq!(wf.next(), Some(1.0f32));
|
assert_eq!(wf.next(), Some(1.0f32));
|
||||||
assert_eq!(wf.next(), Some(1.0f32));
|
assert_eq!(wf.next(), Some(1.0f32));
|
||||||
|
@ -127,10 +127,10 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn triangle() {
|
fn triangle() {
|
||||||
let mut wf = SynthWaveform::new(
|
let mut wf = TestWaveform::new(
|
||||||
cpal::SampleRate(8000),
|
cpal::SampleRate(8000),
|
||||||
1000.0f32,
|
1000.0f32,
|
||||||
SynthWaveformFunction::Triangle,
|
TestWaveformFunction::Triangle,
|
||||||
);
|
);
|
||||||
assert_eq!(wf.next(), Some(-1.0f32));
|
assert_eq!(wf.next(), Some(-1.0f32));
|
||||||
assert_eq!(wf.next(), Some(-0.5f32));
|
assert_eq!(wf.next(), Some(-0.5f32));
|
||||||
|
@ -152,10 +152,10 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn saw() {
|
fn saw() {
|
||||||
let mut wf = SynthWaveform::new(
|
let mut wf = TestWaveform::new(
|
||||||
cpal::SampleRate(200),
|
cpal::SampleRate(200),
|
||||||
50.0f32,
|
50.0f32,
|
||||||
SynthWaveformFunction::Sawtooth,
|
TestWaveformFunction::Sawtooth,
|
||||||
);
|
);
|
||||||
assert_eq!(wf.next(), Some(0.0f32));
|
assert_eq!(wf.next(), Some(0.0f32));
|
||||||
assert_eq!(wf.next(), Some(0.5f32));
|
assert_eq!(wf.next(), Some(0.5f32));
|
||||||
|
@ -169,7 +169,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn sine() {
|
fn sine() {
|
||||||
let mut wf =
|
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.0f32);
|
||||||
assert_abs_diff_eq!(wf.next().unwrap(), 0.58778525f32);
|
assert_abs_diff_eq!(wf.next().unwrap(), 0.58778525f32);
|
Loading…
Reference in a new issue