add wavy example code

This commit is contained in:
Brandon Thomas committed 2019-09-13 01:50:00 -04:00
1 parent 39bdce3380
commit 9482fb2302
1 file changed
+35
+35
View File
@@ -0,0 +1,35 @@
//! NB: From wavy library
//!
//! This example records audio and plays it back in real time as it's being recorded.
extern crate wavy;
use wavy::*;
use std::collections::VecDeque;
fn main() -> Result<(), AudioError> {
println!("Opening microphone system");
let mut mic = MicrophoneSystem::new(SampleRate::Studio)?;
println!("Opening speaker system");
let mut speaker = SpeakerSystem::new(SampleRate::Studio)?;
println!("Done");
let mut buffer = VecDeque::new();
loop {
mic.record(&mut |_index, l, r| {
buffer.push_back((l, l));
});
speaker.play(&mut || {
if let Some((lsample, rsample)) = buffer.pop_front() {
AudioSample::stereo(lsample, rsample)
} else {
AudioSample::stereo(0, 0)
}
});
}
}