Update examples to use std Termination
This commit is contained in:
parent
a733bdb4f9
commit
0b6e66d38e
4 changed files with 37 additions and 30 deletions
|
|
@ -3,23 +3,23 @@
|
|||
//! The input data is recorded to "$CARGO_MANIFEST_DIR/recorded.wav".
|
||||
|
||||
extern crate cpal;
|
||||
extern crate failure;
|
||||
extern crate hound;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), failure::Error> {
|
||||
// Setup the default input device and stream with the default input format.
|
||||
let device = cpal::default_input_device().expect("Failed to get default input device");
|
||||
println!("Default input device: {}", device.name().unwrap());
|
||||
println!("Default input device: {}", device.name()?);
|
||||
let format = device.default_input_format().expect("Failed to get default input format");
|
||||
println!("Default input format: {:?}", format);
|
||||
let event_loop = cpal::EventLoop::new();
|
||||
let stream_id = event_loop.build_input_stream(&device, &format)
|
||||
.expect("Failed to build input stream");
|
||||
event_loop.play_stream(stream_id).unwrap();
|
||||
let stream_id = event_loop.build_input_stream(&device, &format)?;
|
||||
event_loop.play_stream(stream_id)?;
|
||||
|
||||
// The WAV file we're recording to.
|
||||
const PATH: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/recorded.wav");
|
||||
let spec = wav_spec_from_format(&format);
|
||||
let writer = hound::WavWriter::create(PATH, spec).unwrap();
|
||||
let writer = hound::WavWriter::create(PATH, spec)?;
|
||||
let writer = std::sync::Arc::new(std::sync::Mutex::new(Some(writer)));
|
||||
|
||||
// A flag to indicate that recording is in progress.
|
||||
|
|
@ -73,8 +73,9 @@ fn main() {
|
|||
// Let recording go for roughly three seconds.
|
||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||
recording.store(false, std::sync::atomic::Ordering::Relaxed);
|
||||
writer.lock().unwrap().take().unwrap().finalize().unwrap();
|
||||
writer.lock().unwrap().take().unwrap().finalize()?;
|
||||
println!("Recording {} complete!", PATH);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn sample_format(format: cpal::SampleFormat) -> hound::SampleFormat {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue