Skip to content

Commit

Permalink
Fix and unify source/sink device_id selection
Browse files Browse the repository at this point in the history
Use empty ('') for default device
Use 'none' to disable the output device (not for inputs)
  • Loading branch information
orottier committed Sep 20, 2023
1 parent 0f5250c commit a58fd7a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
15 changes: 6 additions & 9 deletions examples/microphone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@ use web_audio_api::node::AudioNode;

fn ask_source_id() -> Option<String> {
println!("Enter the input 'device_id' and press <Enter>");
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 <Enter>");
println!("- Use 0 for the default audio output device");
println!("Enter the output 'device_id' and press <Enter>");
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() {
Expand Down
15 changes: 6 additions & 9 deletions examples/roundtrip_latency_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,21 @@ use std::sync::Arc;

fn ask_source_id() -> Option<String> {
println!("Enter the input 'device_id' and press <Enter>");
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 <Enter>");
println!("- Use 0 for the default audio output device");
println!("Enter the output 'device_id' and press <Enter>");
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 {
Expand Down
10 changes: 3 additions & 7 deletions examples/sink_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ use web_audio_api::node::{AudioNode, AudioScheduledSourceNode};

fn ask_sink_id() -> String {
println!("Enter the output 'device_id' and press <Enter>");
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() {
Expand Down

0 comments on commit a58fd7a

Please sign in to comment.