use rtaudio::{Buffers, StreamConfig, StreamInfo, StreamStatus};
use std::time::{Duration, Instant};
fn main() {
tracing::subscriber::set_global_default(
tracing_subscriber::FmtSubscriber::builder()
.with_max_level(tracing::Level::DEBUG)
.finish(),
)
.unwrap();
let (error_tx, error_rx) = std::sync::mpsc::channel();
rtaudio::set_error_callback(move |error| error_tx.send(error).unwrap());
let host = rtaudio::Host::default();
let mut stream_handle = host.open_stream(&StreamConfig::default()).unwrap();
stream_handle
.start(
move |buffers: Buffers<'_>, _info: &StreamInfo, _status: StreamStatus| {
if let Buffers::Float32 { output, input: _ } = buffers {
output.fill(0.0);
}
},
)
.unwrap();
let t = Instant::now();
while t.elapsed() < Duration::from_secs(5) {
if let Ok(error) = error_rx.try_recv() {
eprintln!("{}", error);
break;
}
std::thread::sleep(Duration::from_millis(16));
}
}