Skip to content

Instantly share code, notes, and snippets.

@michidk
Created April 20, 2021 19:22
Show Gist options
  • Save michidk/6120d4adf3be1926f28f1f1951e569d3 to your computer and use it in GitHub Desktop.
Save michidk/6120d4adf3be1926f28f1f1951e569d3 to your computer and use it in GitHub Desktop.
Sawtooth
use portaudio as pa;
use anyhow::Result;
fn main() -> Result<()> {
let pa = pa::PortAudio::new()?;
let mut settings = pa.default_output_stream_settings(1, 44_100.0, 64u32)?;
settings.flags = pa::stream_flags::CLIP_OFF;
let mut phase = 0.0;
let callback = move |pa::OutputStreamCallbackArgs { buffer, frames, .. }| {
for i in 0..frames {
buffer[i] = phase;
phase += 0.01;
if phase >= 1.0 {
phase -= 2.0;
}
}
pa::Continue
};
let mut stream = pa.open_non_blocking_stream(settings, callback)?;
stream.start()?;
pa.sleep(3_000);
stream.stop()?;
stream.close()?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment