From a58fd7a74688933c715dc7e6082cc6ae3efb3d4f Mon Sep 17 00:00:00 2001 From: Otto Date: Wed, 20 Sep 2023 17:19:06 +0200 Subject: [PATCH] Fix and unify source/sink device_id selection Use empty ('') for default device Use 'none' to disable the output device (not for inputs) --- examples/microphone.rs | 15 ++++++--------- examples/roundtrip_latency_test.rs | 15 ++++++--------- examples/sink_id.rs | 10 +++------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/examples/microphone.rs b/examples/microphone.rs index dee5b9b5..9666b398 100644 --- a/examples/microphone.rs +++ b/examples/microphone.rs @@ -18,24 +18,21 @@ use web_audio_api::node::AudioNode; fn ask_source_id() -> Option { println!("Enter the input 'device_id' and press "); - println!("- Use 0 for the default audio input device"); + println!("- Leave empty ('') for the default audio input device"); let input = std::io::stdin().lines().next().unwrap().unwrap(); match input.trim() { - "0" => None, + "" => None, i => Some(i.to_string()), } } fn ask_sink_id() -> String { - println!("Enter the output 'sink' and press "); - println!("- Use 0 for the default audio output device"); + println!("Enter the output 'device_id' and press "); + println!("- type 'none' to disable the output"); + println!("- Leave empty ('') for the default audio output device"); - let input = std::io::stdin().lines().next().unwrap().unwrap(); - match input.trim() { - "0" => "".to_string(), - i => i.to_string(), - } + std::io::stdin().lines().next().unwrap().unwrap() } fn main() { diff --git a/examples/roundtrip_latency_test.rs b/examples/roundtrip_latency_test.rs index 65c153f2..d80f0a19 100644 --- a/examples/roundtrip_latency_test.rs +++ b/examples/roundtrip_latency_test.rs @@ -32,24 +32,21 @@ use std::sync::Arc; fn ask_source_id() -> Option { println!("Enter the input 'device_id' and press "); - println!("- Use 0 for the default audio input device"); + println!("- Leave empty ('') for the default audio input device"); let input = std::io::stdin().lines().next().unwrap().unwrap(); match input.trim() { - "0" => None, + "" => None, i => Some(i.to_string()), } } fn ask_sink_id() -> String { - println!("Enter the output 'sink' and press "); - println!("- Use 0 for the default audio output device"); + println!("Enter the output 'device_id' and press "); + println!("- type 'none' to disable the output"); + println!("- Leave empty ('') for the default audio output device"); - let input = std::io::stdin().lines().next().unwrap().unwrap(); - match input.trim() { - "0" => "none".to_string(), - i => i.to_string(), - } + std::io::stdin().lines().next().unwrap().unwrap() } struct AtomicF64 { diff --git a/examples/sink_id.rs b/examples/sink_id.rs index 1ffb7fb3..8d5eafb6 100644 --- a/examples/sink_id.rs +++ b/examples/sink_id.rs @@ -16,14 +16,10 @@ use web_audio_api::node::{AudioNode, AudioScheduledSourceNode}; fn ask_sink_id() -> String { println!("Enter the output 'device_id' and press "); - println!("- Leave empty for AudioSinkType 'none'"); - println!("- Use 0 for the default audio output device"); + println!("- type 'none' to disable the output"); + println!("- Leave empty ('') for the default audio output device"); - let input = std::io::stdin().lines().next().unwrap().unwrap(); - match input.trim() { - "0" => "none".to_string(), - i => i.to_string(), - } + std::io::stdin().lines().next().unwrap().unwrap() } fn main() {