mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
add wavy example code
This commit is contained in:
1 parent
39bdce3380
commit
9482fb2302
1 file changed
+35
@@ -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)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user