Created
April 20, 2021 19:22
-
-
Save michidk/6120d4adf3be1926f28f1f1951e569d3 to your computer and use it in GitHub Desktop.
Sawtooth
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
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