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) { 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(); } } } }
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) { 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(); } } } }
private void FormatOrDeviceChanged() { if (sample.SelectedItem != null) { var attrs = XtAudio.GetSampleAttributes((XtSample)sample.SelectedItem); attributes.Text = XtPrint.AttributesToString(attrs); } XtFormat inputFormat = GetFormat(false); XtDevice inputDevice = this.inputDevice.SelectedItem == null ? null : ((DeviceView)(this.inputDevice.SelectedItem)).device; bool inputSupported = inputDevice == null ? false : inputDevice.SupportsFormat(inputFormat); inputFormatSupported.Text = inputSupported.ToString(); XtBuffer inputBuffer = !inputSupported ? null : inputDevice.GetBuffer(inputFormat); inputBufferSizes.Text = !inputSupported ? "N/A" : string.Format("{0} / {1} / {2}", inputBuffer.min.ToString("N1"), inputBuffer.current.ToString("N1"), inputBuffer.max.ToString("N1")); inputMix.Text = inputDevice == null || inputDevice.GetMix() == null ? "N/A" : inputDevice.GetMix().ToString(); inputInterleaved.Text = inputDevice == null ? "N/A" : inputDevice.SupportsAccess(true) && inputDevice.SupportsAccess(false) ? "Both" : inputDevice.SupportsAccess(false) ? "False" : "True"; List <ChannelView> inputViews = new List <ChannelView>(); if (inputDevice != null) { inputViews = (from i in Enumerable.Range(0, inputDevice.GetChannelCount(false)) select new ChannelView { index = i, name = (1 + i) + ": " + inputDevice.GetChannelName(false, i) }) .ToList(); } inputChannels.DataSource = null; inputChannels.DataSource = inputViews; inputChannels.SelectedItems.Clear(); XtFormat outputFormat = GetFormat(true); XtDevice outputDevice = this.outputDevice.SelectedItem == null ? null : ((DeviceView)(this.outputDevice.SelectedItem)).device; bool outputSupported = outputDevice == null ? false : outputDevice.SupportsFormat(outputFormat); outputFormatSupported.Text = outputSupported.ToString(); XtBuffer outputBuffer = !outputSupported ? null : outputDevice.GetBuffer(outputFormat); outputBufferSizes.Text = !outputSupported ? "N/A" : string.Format("{0} / {1} / {2}", outputBuffer.min.ToString("N1"), outputBuffer.current.ToString("N1"), outputBuffer.max.ToString("N1")); outputMix.Text = outputDevice == null || outputDevice.GetMix() == null ? "N/A" : outputDevice.GetMix().ToString(); outputInterleaved.Text = outputDevice == null ? "N/A" : outputDevice.SupportsAccess(true) && outputDevice.SupportsAccess(false) ? "Both" : outputDevice.SupportsAccess(false) ? "False" : "True"; List <ChannelView> outputViews = new List <ChannelView>(); if (outputDevice != null) { outputViews = (from i in Enumerable.Range(0, outputDevice.GetChannelCount(true)) select new ChannelView { index = i, name = (1 + i) + ": " + outputDevice.GetChannelName(true, i) }) .ToList(); } outputChannels.DataSource = null; outputChannels.DataSource = outputViews; outputChannels.SelectedItems.Clear(); bufferSize.Minimum = 1; bufferSize.Maximum = 5000; bufferSize.Value = 1000; if (outputBuffer != null) { bufferSize.Minimum = (int)Math.Floor(outputBuffer.min); bufferSize.Maximum = (int)Math.Ceiling(outputBuffer.max); bufferSize.Value = (int)Math.Ceiling(outputBuffer.current); bufferSize.TickFrequency = (bufferSize.Maximum - bufferSize.Minimum) / 10; } }
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(); } } } }