Change callback interface so that it takes a dedicated error callback
This commit is contained in:
parent
c97d1dd3fa
commit
3cce3e43d9
8 changed files with 50 additions and 71 deletions
|
|
@ -17,15 +17,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
(sample_clock * 440.0 * 2.0 * 3.141592 / sample_rate).sin()
|
||||
};
|
||||
|
||||
let stream = device.build_output_stream(&format, move |result| {
|
||||
let data = match result {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
eprintln!("an error occurred on stream: {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let stream = device.build_output_stream(&format, move |data| {
|
||||
match data {
|
||||
cpal::StreamData::Output { buffer: cpal::UnknownTypeOutputBuffer::U16(mut buffer) } => {
|
||||
for sample in buffer.chunks_mut(channels as usize) {
|
||||
|
|
@ -53,6 +45,8 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
},
|
||||
_ => (),
|
||||
}
|
||||
}, move |err| {
|
||||
eprintln!("an error occurred on stream: {}", err);
|
||||
})?;
|
||||
stream.play()?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue