-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
140 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::f32::consts::PI; | ||
|
||
const SRATE: f32 = 44100.; | ||
|
||
#[derive(Default)] | ||
pub struct TestSignal { | ||
counter: usize, | ||
oscillator_phase: f32, | ||
modulator_phase: f32, | ||
} | ||
|
||
impl TestSignal { | ||
pub fn new() -> Self { | ||
Default::default() | ||
} | ||
|
||
pub fn get(&mut self, buffer: &mut [f32]) -> bool { | ||
if self.counter == 0 { | ||
for sample in buffer.iter_mut() { | ||
let modulator = osc(&mut self.modulator_phase, 0.5); | ||
*sample = 0.8 * osc(&mut self.oscillator_phase, 300. * (1. + 0.2 * modulator)); | ||
} | ||
self.counter = 1; | ||
true | ||
} else { | ||
self.counter = 0; | ||
false | ||
} | ||
} | ||
} | ||
|
||
fn osc(phase: &mut f32, freq: f32) -> f32 { | ||
*phase += freq / SRATE; | ||
*phase = phase.fract(); | ||
(*phase * 2. * PI).sin() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters