Update examples for addition of new StreamEvent API
This commit is contained in:
parent
e41baa248b
commit
39cd5d0084
|
@ -17,7 +17,16 @@ fn main() -> Result<(), failure::Error> {
|
|||
(sample_clock * 440.0 * 2.0 * 3.141592 / sample_rate).sin()
|
||||
};
|
||||
|
||||
event_loop.run(move |_, data| {
|
||||
event_loop.run(move |id, event| {
|
||||
let data = match event {
|
||||
cpal::StreamEvent::Data(data) => data,
|
||||
cpal::StreamEvent::Close(cpal::StreamCloseCause::Error(err)) => {
|
||||
eprintln!("stream {:?} closed due to an error: {}", id, err);
|
||||
return;
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
|
||||
match data {
|
||||
cpal::StreamData::Output { buffer: cpal::UnknownTypeOutputBuffer::U16(mut buffer) } => {
|
||||
for sample in buffer.chunks_mut(format.channels as usize) {
|
||||
|
|
|
@ -49,7 +49,16 @@ fn main() -> Result<(), failure::Error> {
|
|||
|
||||
// Run the event loop on a separate thread.
|
||||
std::thread::spawn(move || {
|
||||
event_loop.run(move |id, data| {
|
||||
event_loop.run(move |id, event| {
|
||||
let data = match event {
|
||||
cpal::StreamEvent::Data(data) => data,
|
||||
cpal::StreamEvent::Close(cpal::StreamCloseCause::Error(err)) => {
|
||||
eprintln!("stream {:?} closed due to an error: {}", id, err);
|
||||
return;
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
|
||||
match data {
|
||||
cpal::StreamData::Input { buffer: cpal::UnknownTypeInputBuffer::F32(buffer) } => {
|
||||
assert_eq!(id, input_stream_id);
|
||||
|
|
|
@ -30,7 +30,16 @@ fn main() -> Result<(), failure::Error> {
|
|||
let writer_2 = writer.clone();
|
||||
let recording_2 = recording.clone();
|
||||
std::thread::spawn(move || {
|
||||
event_loop.run(move |_, data| {
|
||||
event_loop.run(move |id, event| {
|
||||
let data = match event {
|
||||
cpal::StreamEvent::Data(data) => data,
|
||||
cpal::StreamEvent::Close(cpal::StreamCloseCause::Error(err)) => {
|
||||
eprintln!("stream {:?} closed due to an error: {}", id, err);
|
||||
return;
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
|
||||
// If we're done recording, return early.
|
||||
if !recording_2.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue