Turns out I don't have an appropriate output device.

This commit is contained in:
Will Stott 2018-11-15 22:15:57 +00:00
parent b81bdca707
commit 1eb5b7d127

View file

@ -3,12 +3,39 @@ extern crate cpal;
use std::io; use std::io;
use std::thread; use std::thread;
use std::sync::mpsc::{sync_channel, SyncSender}; use std::sync::mpsc::{sync_channel, SyncSender};
use std::process::exit;
pub struct CpalSink { pub struct CpalSink {
// event_loop: cpal::EventLoop, // event_loop: cpal::EventLoop,
send: SyncSender<i16>, send: SyncSender<i16>,
} }
fn list_outputs() {
println!("Default Audio Device:\n {:?}", cpal::default_output_device().map(|e| e.name()));
println!("Available Audio Devices:");
for device in cpal::output_devices() {
println!("- {}", device.name());
// Output formats
if let Ok(fmt) = device.default_output_format() {
println!(" Default format:\n {:?}", fmt);
}
let mut output_formats = match device.supported_output_formats() {
Ok(f) => f.peekable(),
Err(e) => {
println!("Error: {:?}", e);
continue;
},
};
if output_formats.peek().is_some() {
println!(" All formats:");
for format in output_formats {
println!(" {:?}", format);
}
}
}
}
impl Open for CpalSink { impl Open for CpalSink {
fn open(device: Option<String>) -> CpalSink { fn open(device: Option<String>) -> CpalSink {
info!("Using cpal sink"); info!("Using cpal sink");
@ -18,6 +45,10 @@ impl Open for CpalSink {
let event_loop = cpal::EventLoop::new(); let event_loop = cpal::EventLoop::new();
if device.is_some() { if device.is_some() {
if device == Some("?".to_string()) {
list_outputs();
exit(0)
}
// N.B. This is perfectly possible to support. // N.B. This is perfectly possible to support.
// TODO: First need to enable listing of devices. // TODO: First need to enable listing of devices.
// Remember to filter to those which support Stereo 16bit 44100Hz // Remember to filter to those which support Stereo 16bit 44100Hz