private void ServiceChanged() { XtService s = (XtService)(service.SelectedItem); inputDevice.DataSource = null; outputDevice.DataSource = null; ClearDevices(); DeviceView inputView = new DeviceView(); inputView.defaultInput = true; inputView.device = s.OpenDefaultDevice(false); if (inputView.device != null) { deviceViews.Add(inputView); } DeviceView outputView = new DeviceView(); outputView.defaultOutput = true; outputView.device = s.OpenDefaultDevice(true); if (outputView.device != null) { deviceViews.Add(outputView); } for (int i = 0; i < s.GetDeviceCount(); i++) { DeviceView view = new DeviceView(); view.device = s.OpenDevice(i); view.index = i; deviceViews.Add(view); } List <DeviceView> inputViews = (from v in deviceViews where v.defaultInput || v.device.GetChannelCount(false) > 0 select v).ToList(); inputViews.Insert(0, new DeviceView()); List <DeviceView> outputViews = (from v in deviceViews where v.defaultOutput || v.device.GetChannelCount(true) > 0 select v).ToList(); outputViews.Insert(0, new DeviceView()); inputDevice.DataSource = new List <DeviceView>(inputViews); outputDevice.DataSource = new List <DeviceView>(outputViews); secondaryInput.DataSource = new List <DeviceView>(inputViews); secondaryOutput.DataSource = new List <DeviceView>(outputViews); inputDevice.SelectedIndex = inputViews.Count == 1 ? 0 : 1; outputDevice.SelectedIndex = outputViews.Count == 1 ? 0 : 1; system.Text = s.GetSystem().ToString(); capabilities.Text = XtPrint.CapabilitiesToString(s.GetCapabilities()); defaultInput.Text = inputView.device == null ? "null" : inputView.device.ToString(); defaultOutput.Text = outputView.device == null ? "null" : outputView.device.ToString(); inputControlPanel.Enabled = s.GetSystem() == XtSystem.Asio; outputControlPanel.Enabled = s.GetSystem() == XtSystem.Asio; }
public static void Main(string[] args) { XtMix mix = new XtMix(48000, XtSample.Int16); XtFormat inputFormat = new XtFormat(mix, 2, 0, 0, 0); XtChannels inputChannels = new XtChannels(2, 0, 0, 0); XtFormat outputFormat = new XtFormat(mix, 0, 0, 2, 0); XtChannels outputChannels = new XtChannels(0, 0, 2, 0); using (XtAudio audio = new XtAudio(null, IntPtr.Zero, null, null)) { XtService service = XtAudio.GetServiceBySetup(XtSetup.SystemAudio); using (XtDevice input = service.OpenDefaultDevice(false)) using (XtDevice output = service.OpenDefaultDevice(true)) { if (input != null && input.SupportsFormat(inputFormat) && output != null && output.SupportsFormat(outputFormat)) { using (XtStream stream = service.AggregateStream( new XtDevice[] { input, output }, new XtChannels[] { inputChannels, outputChannels }, new double[] { 30.0, 30.0 }, 2, mix, true, false, output, OnAggregate, XRun, "user-data")) { stream.Start(); Console.WriteLine("Streaming aggregate, press any key to continue..."); Console.ReadLine(); stream.Stop(); } } } } }
public static void Main(string[] args) { using (XtAudio audio = new XtAudio(null, IntPtr.Zero, null, null)) { XtService service = XtAudio.GetServiceBySetup(XtSetup.ConsumerAudio); if (service == null) { return; } using (XtDevice device = service.OpenDefaultDevice(false)) { if (device == null || !device.SupportsFormat(Format)) { return; } XtBuffer buffer = device.GetBuffer(Format); using (FileStream recording = new FileStream( "xt-audio.raw", FileMode.Create, FileAccess.Write)) using (XtStream stream = device.OpenStream(Format, true, false, buffer.current, Capture, null, recording)) { stream.Start(); Thread.Sleep(1000); stream.Stop(); } } } }
void OnSystemChanged(object sender, EventArgs e) { _suspendDeviceChanged = true; try { XtService s = _platform.GetService((XtSystem)_system.SelectedItem); _streamType.DataSource = GetStreamTypes(s); _streamType.SelectedItem = StreamType.Render; ClearDevices(); var defaultInputId = s.GetDefaultDeviceId(false); var defaultOutputId = s.GetDefaultDeviceId(true); using var inputList = s.OpenDeviceList(XtEnumFlags.Input); using var outputList = s.OpenDeviceList(XtEnumFlags.Output); var inputs = GetDeviceInfos(s, inputList, defaultInputId); var outputs = GetDeviceInfos(s, outputList, defaultOutputId); _input.SystemChanged(s, inputs); _output.SystemChanged(s, outputs); _serviceCaps.Text = s.GetCapabilities().ToString(); _secondaryInput.DataSource = new List <DeviceInfo>(inputs); _secondaryOutput.DataSource = new List <DeviceInfo>(outputs); _defaultInput.Text = defaultInputId == null ? "[None]" : inputList.GetName(defaultInputId); _defaultOutput.Text = defaultOutputId == null ? "[None]" : outputList.GetName(defaultOutputId); } finally { _suspendDeviceChanged = false; } FormatOrDeviceChanged(); }
public static void Main(string[] args) { using (XtAudio audio = new XtAudio(null, IntPtr.Zero, null, null)) { XtService service = XtAudio.GetServiceBySetup(XtSetup.ConsumerAudio); if (service == null) { return; } using (XtDevice device = service.OpenDefaultDevice(true)) { if (device == null || !device.SupportsFormat(Format)) { return; } XtBuffer buffer = device.GetBuffer(Format); using (XtStream stream = device.OpenStream(Format, true, false, buffer.current, Render, null, null)) { stream.Start(); Thread.Sleep(1000); stream.Stop(); } } } }
public static void Main(string[] args) { XtFormat format; XtFormat int44100 = new XtFormat(new XtMix(44100, XtSample.Int32), 2, 0, 2, 0); XtFormat int48000 = new XtFormat(new XtMix(48000, XtSample.Int32), 2, 0, 2, 0); XtFormat float44100 = new XtFormat(new XtMix(44100, XtSample.Float32), 2, 0, 2, 0); XtFormat float48000 = new XtFormat(new XtMix(48000, XtSample.Float32), 2, 0, 2, 0); using (XtAudio audio = new XtAudio(null, IntPtr.Zero, null, null)) { XtService service = XtAudio.GetServiceBySetup(XtSetup.ProAudio); if (service == null) { return; } using (XtDevice device = service.OpenDefaultDevice(true)) { if (device == null) { return; } if (device.SupportsFormat(int44100)) { format = int44100; } else if (device.SupportsFormat(int48000)) { format = int48000; } else if (device.SupportsFormat(float44100)) { format = float44100; } else if (device.SupportsFormat(float48000)) { format = float48000; } else { return; } XtBuffer buffer = device.GetBuffer(format); using (XtStream stream = device.OpenStream(format, true, false, buffer.min, Callback, null, null)) { stream.Start(); Console.WriteLine("Streaming full-duplex, press any key to continue..."); Console.ReadLine(); stream.Stop(); } } } }
public static void Main(String[] args) { using (XtAudio audio = new XtAudio("Sample", IntPtr.Zero, OnTrace, OnFatal)) { try { Console.WriteLine("Win32: " + XtAudio.IsWin32()); Console.WriteLine("Version: " + XtAudio.GetVersion()); XtService pro = XtAudio.GetServiceBySetup(XtSetup.ProAudio); Console.WriteLine("Pro Audio: " + (pro == null ? "None" : pro.GetName())); XtService system = XtAudio.GetServiceBySetup(XtSetup.SystemAudio); Console.WriteLine("System Audio: " + (system == null ? "None" : system.GetName())); XtService consumer = XtAudio.GetServiceBySetup(XtSetup.ConsumerAudio); Console.WriteLine("Consumer Audio: " + (consumer == null ? "None" : consumer.GetName())); for (int s = 0; s < XtAudio.GetServiceCount(); s++) { XtService service = XtAudio.GetServiceByIndex(s); Console.WriteLine("Service " + service.GetName() + ":"); Console.WriteLine(" System: " + service.GetSystem()); Console.WriteLine(" Device count: " + service.GetDeviceCount()); Console.WriteLine(" Capabilities: " + XtPrint.CapabilitiesToString(service.GetCapabilities())); using (XtDevice defaultInput = service.OpenDefaultDevice(false)) Console.WriteLine(" Default input: " + defaultInput); using (XtDevice defaultOutput = service.OpenDefaultDevice(true)) Console.WriteLine(" Default output: " + defaultOutput); for (int d = 0; d < service.GetDeviceCount(); d++) { using (XtDevice device = service.OpenDevice(d)) { Console.WriteLine(" Device " + device.GetName() + ":"); Console.WriteLine(" System: " + device.GetSystem()); Console.WriteLine(" Current mix: " + device.GetMix()); Console.WriteLine(" Input channels: " + device.GetChannelCount(false)); Console.WriteLine(" Output channels: " + device.GetChannelCount(true)); Console.WriteLine(" Interleaved access: " + device.SupportsAccess(true)); Console.WriteLine(" Non-interleaved access: " + device.SupportsAccess(false)); } } } } catch (XtException e) { Console.WriteLine("Error: system %s, fault %s, cause %s, text %s, message: %s.\n", XtException.GetSystem(e.GetError()), XtException.GetFault(e.GetError()), XtException.GetCause(e.GetError()), XtException.GetText(e.GetError()), e.ToString()); } } }
DeviceInfo GetDeviceInfo(XtService service, XtDeviceList list, int index, string defaultId) { var id = list.GetId(index); var result = new DeviceInfo(); result.Id = id; result.Name = list.GetName(id); result.DefaultInput = id == defaultId; result.DefaultOutput = id == defaultId; result.Device = service.OpenDevice(id); result.Capabilities = list.GetCapabilities(id); return(result); }
public static void Main(string[] args) { using (XtAudio audio = new XtAudio(null, IntPtr.Zero, null, null)) { for (int s = 0; s < XtAudio.GetServiceCount(); s++) { XtService service = XtAudio.GetServiceByIndex(s); for (int d = 0; d < service.GetDeviceCount(); d++) { using (XtDevice device = service.OpenDevice(d)) Console.WriteLine(service.GetName() + ": " + device.GetName()); } } } }
static IList <StreamType> GetStreamTypes(XtService service) { var result = new List <StreamType>(); result.Add(StreamType.Render); result.Add(StreamType.Capture); if ((service.GetCapabilities() & XtServiceCaps.FullDuplex) != 0) { result.Add(StreamType.Duplex); } if ((service.GetCapabilities() & XtServiceCaps.Aggregation) != 0) { result.Add(StreamType.Aggregate); } return(result); }
public static void Main() { XtAudio.SetOnError(OnError); using XtPlatform platform = XtAudio.Init("Sample", IntPtr.Zero); try { XtVersion version = XtAudio.GetVersion(); Console.WriteLine("Version: " + version.major + "." + version.minor); XtSystem pro = platform.SetupToSystem(XtSetup.ProAudio); Console.WriteLine("Pro Audio: " + pro + " (" + (platform.GetService(pro) != null) + ")"); XtSystem system = platform.SetupToSystem(XtSetup.SystemAudio); Console.WriteLine("System Audio: " + system + " (" + (platform.GetService(system) != null) + ")"); XtSystem consumer = platform.SetupToSystem(XtSetup.ConsumerAudio); Console.WriteLine("Consumer Audio: " + consumer + " (" + (platform.GetService(consumer) != null) + ")"); foreach (XtSystem s in platform.GetSystems()) { XtService service = platform.GetService(s); using XtDeviceList all = service.OpenDeviceList(XtEnumFlags.All); Console.WriteLine("System: " + s); Console.WriteLine(" Capabilities: " + service.GetCapabilities()); string defaultInput = service.GetDefaultDeviceId(false); if (defaultInput != null) { string name = all.GetName(defaultInput); Console.WriteLine(" Default input: " + name + " (" + defaultInput + ")"); } string defaultOutput = service.GetDefaultDeviceId(true); if (defaultOutput != null) { string name = all.GetName(defaultOutput); Console.WriteLine(" Default output: " + name + " (" + defaultOutput + ")"); } using XtDeviceList inputs = service.OpenDeviceList(XtEnumFlags.Input); Console.WriteLine(" Input device count: " + inputs.GetCount()); PrintDevices(service, inputs); using XtDeviceList outputs = service.OpenDeviceList(XtEnumFlags.Output); Console.WriteLine(" Output device count: " + outputs.GetCount()); PrintDevices(service, outputs); } } catch (XtException e) { Console.WriteLine(XtAudio.GetErrorInfo(e.GetError())); } catch (Exception e) { Console.WriteLine(e.Message); } }
IList <DeviceInfo> GetDeviceInfos(XtService service, XtDeviceList list, string defaultId) { var result = new List <DeviceInfo>(); var noDevice = new DeviceInfo(); noDevice.Id = "None"; noDevice.Name = "[None]"; result.Add(noDevice); for (int i = 0; i < list.GetCount(); i++) { try { var info = GetDeviceInfo(service, list, i, defaultId); result.Insert(info.DefaultInput || info.DefaultInput ? 1 : result.Count, info); _allDevices.Add(info); } catch (XtException e) { AddMessage(() => XtAudio.GetErrorInfo(e.GetError()).ToString()); } } return(result); }
static void PrintDevices(XtService service, XtDeviceList list) { for (int d = 0; d < list.GetCount(); d++) { string id = list.GetId(d); try { using XtDevice device = service.OpenDevice(id); XtMix?mix = device.GetMix(); Console.WriteLine(" Device " + id + ":"); Console.WriteLine(" Name: " + list.GetName(id)); Console.WriteLine(" Capabilities: " + list.GetCapabilities(id)); Console.WriteLine(" Input channels: " + device.GetChannelCount(false)); Console.WriteLine(" Output channels: " + device.GetChannelCount(true)); Console.WriteLine(" Interleaved access: " + device.SupportsAccess(true)); Console.WriteLine(" Non-interleaved access: " + device.SupportsAccess(false)); if (mix != null) { Console.WriteLine(" Current mix: " + mix.Value.rate + " " + mix.Value.sample); } } catch (XtException e) { Console.WriteLine(XtAudio.GetErrorInfo(e.GetError())); } } }
public static void Main(string[] args) { using (XtAudio audio = new XtAudio(null, IntPtr.Zero, null, null)) { XtService service = XtAudio.GetServiceBySetup(XtSetup.ConsumerAudio); XtFormat format = new XtFormat(new XtMix(44100, XtSample.Int24), 2, 0, 0, 0); using (XtDevice device = service.OpenDefaultDevice(false)) { if (device == null) { Console.WriteLine("No default device found."); return; } if (!device.SupportsFormat(format)) { Console.WriteLine("Format not supported."); return; } Context context = new Context(); XtBuffer buffer = device.GetBuffer(format); using (FileStream recording = new FileStream( "xt-audio-interleaved.raw", FileMode.Create, FileAccess.Write)) using (XtStream stream = device.OpenStream(format, true, false, buffer.current, CaptureInterleaved, XRun, context)) { context.recording = recording; context.intermediate = new byte[GetBufferSize(stream, stream.GetFrames())]; stream.Start(); Console.WriteLine("Capturing interleaved..."); ReadLine(); stream.Stop(); } using (FileStream recording = new FileStream( "xt-audio-interleaved-raw.raw", FileMode.Create, FileAccess.Write)) using (XtStream stream = device.OpenStream(format, true, true, buffer.current, CaptureInterleavedRaw, XRun, context)) { context.recording = recording; context.intermediate = new byte[GetBufferSize(stream, stream.GetFrames())]; stream.Start(); Console.WriteLine("Capturing interleaved, raw buffers..."); ReadLine(); stream.Stop(); } using (FileStream recording = new FileStream( "xt-audio-non-interleaved.raw", FileMode.Create, FileAccess.Write)) using (XtStream stream = device.OpenStream(format, false, false, buffer.current, CaptureNonInterleaved, XRun, context)) { context.recording = recording; context.intermediate = new byte[GetBufferSize(stream, stream.GetFrames())]; stream.Start(); Console.WriteLine("Capturing non-interleaved..."); ReadLine(); stream.Stop(); } using (FileStream recording = new FileStream( "xt-audio-non-interleaved-raw.raw", FileMode.Create, FileAccess.Write)) using (XtStream stream = device.OpenStream(format, false, true, buffer.current, CaptureNonInterleavedRaw, XRun, context)) { context.recording = recording; context.intermediate = new byte[GetBufferSize(stream, stream.GetFrames())]; stream.Start(); Console.WriteLine("Capturing non-interleaved, raw buffers..."); ReadLine(); stream.Stop(); } } } }
public static void Main(String[] args) { using (XtAudio audio = new XtAudio(null, IntPtr.Zero, null, null)) { XtService service = XtAudio.GetServiceBySetup(XtSetup.ConsumerAudio); XtFormat format = new XtFormat(new XtMix(44100, XtSample.Float32), 0, 0, 2, 0); using (XtDevice device = service.OpenDefaultDevice(true)) { if (device == null) { Console.WriteLine("No default device found."); return; } if (!device.SupportsFormat(format)) { Console.WriteLine("Format not supported."); return; } XtBuffer buffer = device.GetBuffer(format); using (XtStream stream = device.OpenStream(format, true, false, buffer.current, RenderInterleaved, XRun, "user-data")) { stream.Start(); Console.WriteLine("Rendering interleaved..."); ReadLine(); stream.Stop(); } using (XtStream stream = device.OpenStream(format, true, true, buffer.current, RenderInterleavedRaw, XRun, "user-data")) { stream.Start(); Console.WriteLine("Rendering interleaved, raw buffers..."); ReadLine(); stream.Stop(); } using (XtStream stream = device.OpenStream(format, false, false, buffer.current, RenderNonInterleaved, XRun, "user-data")) { stream.Start(); Console.WriteLine("Rendering non-interleaved..."); ReadLine(); stream.Stop(); } using (XtStream stream = device.OpenStream(format, false, true, buffer.current, RenderNonInterleavedRaw, XRun, "user-data")) { stream.Start(); Console.WriteLine("Rendering non-interleaved, raw buffers..."); ReadLine(); stream.Stop(); } XtFormat sendTo0 = new XtFormat(new XtMix(44100, XtSample.Float32), 0, 0, 1, 1L << 0); using (XtStream stream = device.OpenStream(sendTo0, true, false, buffer.current, RenderInterleaved, XRun, "user-data")) { stream.Start(); Console.WriteLine("Rendering channel mask, channel 0..."); ReadLine(); stream.Stop(); } XtFormat sendTo1 = new XtFormat(new XtMix(44100, XtSample.Float32), 0, 0, 1, 1L << 1); using (XtStream stream = device.OpenStream(sendTo1, true, false, buffer.current, RenderInterleaved, XRun, "user-data")) { stream.Start(); Console.WriteLine("Rendering channel mask, channel 1..."); ReadLine(); stream.Stop(); } } } }