Skip to content

Commit

Permalink
Add module zero_crossing_tests.
Browse files Browse the repository at this point in the history
This commit adds a test module to `osc` with three tests, ensuring
waveforms that have zero crossings contain that value as their first
sample.
  • Loading branch information
joculatrix committed Aug 23, 2024
1 parent df6d023 commit b526c88
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/synth/osc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,34 @@ pub fn init_tables() {
let _ = &*SINE_TABLE;
let _ = &*SQUARE_TABLE;
let _ = &*TRI_TABLE;
}

/// These tests ensure the first samples of [`SAW_TABLE`], [`SINE_TABLE`], and [`TRI_TABLE`]
/// occur at zero-crossings (amplitude 0.0), making it more feasible to minimize audible popping
/// by starting notes at the first sample. See [`Oscillator::note_on()`].
///
/// These tests exclude the square wave because it only has values of `-1.0` and `1.0`.
///
/// [`Oscillator::note_on()`]: oscillator::Oscillator::note_on()
#[cfg(test)]
mod zero_crossing_tests {
use super::*;

#[test]
fn first_saw_sample_is_zero() {
init_tables();
assert_eq!(SAW_TABLE[0], 0.0)
}

#[test]
fn first_sine_sample_is_zero() {
init_tables();
assert_eq!(SINE_TABLE[0], 0.0)
}

#[test]
fn first_triangle_sample_is_zero() {
init_tables();
assert_eq!(TRI_TABLE[0], 0.0)
}
}

1 comment on commit b526c88

@joculatrix
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forced a reset to this commit after failing to implement some GitHub Action things that should have been in a different branch to avoid this.

Please sign in to comment.