public static bool InitializeInputDevice(this SoundioInput input, AudioFormat format, string[] args) { var index = args.GetInt("-i", "--input"); if (index == null || index.Value >= input.Devices.Count || index.Value < 0) { return(false); } var latencyMs = args.GetDouble("--input-latency"); if (latencyMs != null) { input.DesiredLatency = TimeSpan.FromMilliseconds(latencyMs.Value); } input.Initialize(input.Devices[index.Value], format); return(true); }
public static void InitializeInputFromConsole(this SoundioInput input, AudioFormat format) { Console.WriteLine("Input devices"); for (var i = 0; input.Devices.Count > i; i++) { Console.WriteLine($"[{i}] {input.Devices[i].Name}"); } var deviceIndex = ConsoleHelper.ReadInt("Input device index > ", input.Devices.Count - 1); var inputDevice = input.Devices[deviceIndex]; for (var i = 0; input.Devices.Count > i; i++) { if (i != deviceIndex) { input.Devices[i].RemoveReference(); } } input.Initialize(inputDevice, format); }
private bool InitAudio(string[] args, bool noShell) { var path = args.GetString("--audio"); AudioConfig audio; try { using var sr = new StreamReader(path); audio = AudioConfig.Deserialize(sr.ReadToEnd()); } catch (Exception ex) { Console.WriteLine(ex); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Failed to open the audio configuration file"); Console.ResetColor(); return(false); } Input = new SoundioInput(); SoundIODevice inputDevice = null; foreach (var device in Input.Devices) { if (device.Name == audio.InputDevice) { inputDevice = device; break; } } if (inputDevice != null) { Input.Initialize(inputDevice, audio.Format); SayInitialized($"Input {inputDevice.Name}, latency {Input.SoftwareLatency.TotalMilliseconds}ms"); } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Input device was not found ({audio.InputDevice})"); Console.ResetColor(); return(false); } if (audio.OutputDevice != null) { SoundIODevice outputDevice = null; Output = new SoundioOutput(); foreach (var device in Output.Devices) { if (device.Name == audio.OutputDevice) { outputDevice = device; break; } } if (outputDevice != null) { Output.Initialize(outputDevice, audio.Format); SayInitialized($"Output {outputDevice.Name}, latency {Output.SoftwareLatency.TotalMilliseconds}ms"); } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Output device was not found ({audio.OutputDevice})"); Console.ResetColor(); if (noShell) { return(false); } else { return(ConsoleHelper.ReadYesNo("Proceed anyway? [yes/no] > ")); } } } return(true); }