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
|
|
@ -49,15 +49,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
|
||||
// Build streams.
|
||||
println!("Attempting to build both streams with `{:?}`.", format);
|
||||
let input_stream = input_device.build_input_stream(&format, move |result| {
|
||||
let data = match result {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
eprintln!("an error occurred on input stream: {}", err);
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
||||
let input_stream = input_device.build_input_stream(&format, move |data| {
|
||||
match data {
|
||||
cpal::StreamData::Input {
|
||||
buffer: cpal::UnknownTypeInputBuffer::F32(buffer),
|
||||
|
|
@ -74,15 +66,10 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
},
|
||||
_ => panic!("Expected input with f32 data"),
|
||||
}
|
||||
}, move |err| {
|
||||
eprintln!("an error occurred on input stream: {}", err);
|
||||
})?;
|
||||
let output_stream = output_device.build_output_stream(&format, move |result| {
|
||||
let data = match result {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
eprintln!("an error occurred on output stream: {}", err);
|
||||
return;
|
||||
},
|
||||
};
|
||||
let output_stream = output_device.build_output_stream(&format, move |data| {
|
||||
match data {
|
||||
cpal::StreamData::Output {
|
||||
buffer: cpal::UnknownTypeOutputBuffer::F32(mut buffer),
|
||||
|
|
@ -103,6 +90,8 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
},
|
||||
_ => panic!("Expected output with f32 data"),
|
||||
}
|
||||
}, move |err| {
|
||||
eprintln!("an error occurred on output stream: {}", err);
|
||||
})?;
|
||||
println!("Successfully built streams.");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue