From 1eb5b7d127a2356c511065640519b6cb543b65a2 Mon Sep 17 00:00:00 2001 From: Will Stott Date: Thu, 15 Nov 2018 22:15:57 +0000 Subject: [PATCH] Turns out I don't have an appropriate output device. --- playback/src/audio_backend/cpal.rs | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/playback/src/audio_backend/cpal.rs b/playback/src/audio_backend/cpal.rs index 693ee88d..8a71b9e4 100644 --- a/playback/src/audio_backend/cpal.rs +++ b/playback/src/audio_backend/cpal.rs @@ -3,12 +3,39 @@ extern crate cpal; use std::io; use std::thread; use std::sync::mpsc::{sync_channel, SyncSender}; +use std::process::exit; pub struct CpalSink { // event_loop: cpal::EventLoop, send: SyncSender, } +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 { fn open(device: Option) -> CpalSink { info!("Using cpal sink"); @@ -18,6 +45,10 @@ impl Open for CpalSink { let event_loop = cpal::EventLoop::new(); if device.is_some() { + if device == Some("?".to_string()) { + list_outputs(); + exit(0) + } // N.B. This is perfectly possible to support. // TODO: First need to enable listing of devices. // Remember to filter to those which support Stereo 16bit 44100Hz