Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
Last active August 15, 2020 08:50
Show Gist options
  • Save justanotherdot/1b992813978344a54a9922795be04bcf to your computer and use it in GitHub Desktop.
Save justanotherdot/1b992813978344a54a9922795be04bcf to your computer and use it in GitHub Desktop.
fn sine_wave_oscillator (w : f32) -> impl Iterator<Item=f32> {
let mut x0 = w.sin();
let mut x1 = 0.0;
let b = 2.0 * w.cos();
std::iter::repeat_with(move || {
let xn = b * x0 - x1;
x1 = x0;
x0 = xn;
xn
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment