public void Init(SoundIODevice device) { OutputDevice = device; if (OutputDevice.ProbeError != 0) { throw new Exception($"Probe Error : {OutputDevice.ProbeError}"); } Console.WriteLine($"Device Name : {OutputDevice.Name}"); outstream = OutputDevice.CreateOutStream(); outstream.WriteCallback = (min, max) => write_callback(outstream, min, max); outstream.UnderflowCallback = () => underflow_callback(outstream); outstream.SoftwareLatency = 0; outstream.SampleRate = Source.Format.SampleRate; if (OutputDevice.SupportsFormat(SoundIODevice.Float32NE)) { outstream.Format = SoundIODevice.Float32NE; } else { outstream.Dispose(); outstream = null; throw new Exception("No suitable format"); } outstream.Open(); if (outstream.LayoutErrorMessage != null) { Console.WriteLine("Layout Error : " + outstream.LayoutErrorMessage); } }
public void Initialize(SoundIODevice device, AudioFormat format) { if (format.Channels != 1) { throw new OutputInitializationException("Format must qualify channels == 1"); } Device = device; Format = format; var bytesPerSample = format.BitDepth / 8; var capacity = Format.SampleRate * Format.Channels * bytesPerSample * 30; ringBuffer = new RingBuffer <float>((uint)capacity); if (Device.ProbeError != 0) { throw new OutputInitializationException($"Probe Error : {Device.ProbeError}"); } outstream = Device.CreateOutStream(); outstream.WriteCallback = (min, max) => write_callback(outstream, min, max); outstream.UnderflowCallback = () => underflow_callback(outstream); outstream.SampleRate = Format.SampleRate; outstream.SoftwareLatency = DesiredLatency.TotalSeconds; outstream.Format = SoundIODevice.S16NE; outstream.Open(); outstream.Layout = SoundIOChannelLayout.GetDefault(Format.Channels); outstream.SoftwareLatency = DesiredLatency.TotalSeconds; api.FlushEvents(); ActualLatency = TimeSpan.FromSeconds(outstream.SoftwareLatency); }
/// <summary> /// Determines if SoundIO can connect to a supported backend /// </summary> /// <returns></returns> private static bool IsSupportedInternal() { SoundIO context = null; SoundIODevice device = null; SoundIOOutStream stream = null; bool backendDisconnected = false; try { context = new SoundIO(); context.OnBackendDisconnect = (i) => { backendDisconnected = true; }; context.Connect(); context.FlushEvents(); if (backendDisconnected) { return(false); } if (context.OutputDeviceCount == 0) { return(false); } device = FindNonRawDefaultAudioDevice(context); if (device == null || backendDisconnected) { return(false); } stream = device.CreateOutStream(); if (stream == null || backendDisconnected) { return(false); } return(true); } catch { return(false); } finally { if (stream != null) { stream.Dispose(); } if (context != null) { context.Dispose(); } } }