Esempio n. 1
0
        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();
                            }
                        }
                    }
            }
        }
Esempio n. 2
0
        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();
                        }
                }
            }
        }
Esempio n. 3
0
        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();
                    }
                }
            }
        }
Esempio n. 4
0
        public unsafe XtStream AggregateStream(XtDevice[] devices, XtChannels[] channels,
                                               double[] bufferSizes, int count, XtMix mix, bool interleaved, bool raw,
                                               XtDevice master, XtStreamCallback streamCallback, XtXRunCallback xRunCallback, object user)
        {
            IntPtr str;
            IntPtr channelsPtr = IntPtr.Zero;

            IntPtr[] ds     = devices.Select(d => d.d).ToArray();
            XtStream stream = new XtStream(raw, streamCallback, xRunCallback, user);

            try {
                int size = Marshal.SizeOf(typeof(XtChannels));
                channelsPtr = Marshal.AllocHGlobal(count * size);
                for (int i = 0; i < count; i++)
                {
                    Marshal.StructureToPtr(channels[i], new IntPtr((byte *)channelsPtr + i * size), false);
                }
                XtNative.HandleError(XtNative.XtServiceAggregateStream(s, ds, channelsPtr, bufferSizes, count,
                                                                       mix, interleaved, master.d, stream.streamCallbackPtr, stream.xRunCallbackPtr, IntPtr.Zero, out str));
            } finally {
                if (channelsPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(channelsPtr);
                }
            }
            stream.Init(str);
            return(stream);
        }
Esempio n. 5
0
        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();
                    }
                }
            }
        }
Esempio n. 6
0
        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());
                }
            }
        }
Esempio n. 7
0
 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());
             }
         }
     }
 }
Esempio n. 8
0
 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())); }
     }
 }
Esempio n. 9
0
        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();
                        }
                }
            }
        }
Esempio n. 10
0
        private void OnStart(object sender, EventArgs ea)
        {
            try {
                StreamType type                  = (StreamType)streamType.SelectedItem;
                bool       input                 = type == StreamType.Capture || type == StreamType.Duplex || type == StreamType.Latency;
                bool       output                = type == StreamType.Render || type == StreamType.Duplex || type == StreamType.Latency;
                XtDevice   inputDevice           = ((DeviceView)this.inputDevice.SelectedItem).device;
                XtDevice   outputDevice          = ((DeviceView)this.outputDevice.SelectedItem).device;
                XtDevice   secondaryInputDevice  = ((DeviceView)this.secondaryInput.SelectedItem).device;
                XtDevice   secondaryOutputDevice = ((DeviceView)this.secondaryOutput.SelectedItem).device;

                if (input && inputDevice == null)
                {
                    MessageBox.Show(this,
                                    "Select an input device.",
                                    "Invalid input device.");
                    return;
                }

                if (output && outputDevice == null)
                {
                    MessageBox.Show(this,
                                    "Select an output device.",
                                    "Invalid output device.");
                    return;
                }

                if (type == StreamType.Duplex && outputDevice != inputDevice)
                {
                    MessageBox.Show(this,
                                    "For duplex operation, input and output device must be the same.",
                                    "Invalid duplex device.");
                    return;
                }

                if (type == StreamType.Aggregate &&
                    (inputDevice == null && secondaryInputDevice == null ||
                     outputDevice == null && secondaryOutputDevice == null))
                {
                    MessageBox.Show(this,
                                    "For aggregate operation, select at least 1 input and 1 output device.",
                                    "Invalid aggregate device.");
                    return;
                }

                XRunCallback xRunCallback = new XRunCallback(AddMessage);

                XtFormat inputFormat = GetFormat(false);
                inputFormat.inputs = (int)channelCount.SelectedItem;
                if (input && inputChannels.SelectedItems.Count > 0 && inputChannels.SelectedItems.Count != inputFormat.inputs)
                {
                    MessageBox.Show(this,
                                    "Selected either 0 input channels or a number equal to the selected format's channels.",
                                    "Invalid input channel mask.");
                    return;
                }
                for (int c = 0; c < inputChannels.SelectedItems.Count; c++)
                {
                    inputFormat.inMask |= (1UL << ((ChannelView)inputChannels.SelectedItems[c]).index);
                }

                XtFormat outputFormat = GetFormat(true);
                if (output && outputChannels.SelectedItems.Count > 0 && outputChannels.SelectedItems.Count != outputFormat.outputs)
                {
                    MessageBox.Show(this,
                                    "Selected either 0 output channels or a number equal to the selected format's channels.",
                                    "Invalid output channel mask.");
                    return;
                }
                for (int c = 0; c < outputChannels.SelectedItems.Count; c++)
                {
                    outputFormat.outMask |= (1UL << ((ChannelView)outputChannels.SelectedItems[c]).index);
                }

                if (type == StreamType.Capture)
                {
                    captureFile = new FileStream("xt-audio.raw", FileMode.Create, FileAccess.Write);
                    CaptureCallback callback = new CaptureCallback(OnStreamError, AddMessage, captureFile);
                    inputStream = inputDevice.OpenStream(inputFormat, streamInterleaved.Checked, streamRaw.Checked,
                                                         bufferSize.Value, callback.OnCallback, xRunCallback.OnCallback, "capture-user-data");
                    callback.Init(inputStream.GetFormat(), inputStream.GetFrames());
                    inputStream.Start();
                }
                else if (type == StreamType.Render)
                {
                    RenderCallback callback = new RenderCallback(OnStreamError, AddMessage);
                    outputStream = outputDevice.OpenStream(outputFormat, streamInterleaved.Checked, streamRaw.Checked,
                                                           bufferSize.Value, callback.OnCallback, xRunCallback.OnCallback, "render-user-data");
                    outputStream.Start();
                }
                else if (type == StreamType.Duplex)
                {
                    XtFormat duplexFormat = inputFormat;
                    duplexFormat.outputs = outputFormat.outputs;
                    duplexFormat.outMask = outputFormat.outMask;
                    FullDuplexCallback callback = new FullDuplexCallback(OnStreamError, AddMessage);
                    outputStream = outputDevice.OpenStream(duplexFormat, streamInterleaved.Checked, streamRaw.Checked,
                                                           bufferSize.Value, callback.OnCallback, xRunCallback.OnCallback, "duplex-user-data");
                    outputStream.Start();
                }
                else if (type == StreamType.Aggregate)
                {
                    List <XtDevice>   devices     = new List <XtDevice>();
                    List <double>     bufferSizes = new List <double>();
                    List <XtChannels> channels    = new List <XtChannels>();
                    if (inputDevice != null)
                    {
                        devices.Add(inputDevice);
                        bufferSizes.Add(bufferSize.Value);
                        channels.Add(new XtChannels(inputFormat.inputs, inputFormat.inMask, 0, 0));
                    }
                    if (outputDevice != null)
                    {
                        devices.Add(outputDevice);
                        bufferSizes.Add(bufferSize.Value);
                        channels.Add(new XtChannels(0, 0, outputFormat.outputs, outputFormat.outMask));
                    }
                    if (secondaryInputDevice != null)
                    {
                        devices.Add(secondaryInputDevice);
                        bufferSizes.Add(bufferSize.Value);
                        channels.Add(new XtChannels(inputFormat.inputs, inputFormat.inMask, 0, 0));
                    }
                    if (secondaryOutputDevice != null)
                    {
                        devices.Add(secondaryOutputDevice);
                        bufferSizes.Add(bufferSize.Value);
                        channels.Add(new XtChannels(0, 0, outputFormat.outputs, outputFormat.outMask));
                    }

                    XtDevice[]   devicesArray     = devices.ToArray();
                    double[]     bufferSizesArray = bufferSizes.ToArray();
                    XtChannels[] channelsArray    = channels.ToArray();
                    XtDevice     master           = outputMaster.Checked ?
                                                    (outputDevice != null ? outputDevice :
                                                     secondaryOutputDevice != null ? secondaryOutputDevice :
                                                     inputDevice != null ? inputDevice : secondaryInputDevice) :
                                                    (inputDevice != null ? inputDevice :
                                                     secondaryInputDevice != null ? secondaryInputDevice :
                                                     outputDevice != null ? outputDevice : secondaryOutputDevice);

                    AggregateCallback streamCallback = new AggregateCallback(OnStreamError, AddMessage);
                    outputStream = ((XtService)service.SelectedItem).AggregateStream(devicesArray, channelsArray,
                                                                                     bufferSizesArray, devicesArray.Length, outputFormat.mix, streamInterleaved.Checked, streamRaw.Checked,
                                                                                     master, streamCallback.OnCallback, xRunCallback.OnCallback, "aggregate-user-data");
                    streamCallback.Init(outputStream.GetFrames());
                    outputStream.Start();
                }
                else if (inputDevice == outputDevice)
                {
                    XtFormat duplexFormat = inputFormat;
                    duplexFormat.outputs = outputFormat.outputs;
                    duplexFormat.outMask = outputFormat.outMask;
                    LatencyCallback callback = new LatencyCallback(OnStreamError, AddMessage);
                    outputStream = outputDevice.OpenStream(duplexFormat, streamInterleaved.Checked, streamRaw.Checked,
                                                           bufferSize.Value, callback.OnCallback, xRunCallback.OnCallback, "latency-user-data");
                    outputStream.Start();
                }
                else
                {
                    XtDevice[]   devices     = new XtDevice[] { inputDevice, outputDevice };
                    double[]     bufferSizes = new double[] { bufferSize.Value, bufferSize.Value };
                    XtChannels[] channels    = new XtChannels[] {
                        new XtChannels(inputFormat.inputs, inputFormat.inMask, 0, 0),
                        new XtChannels(0, 0, outputFormat.outputs, outputFormat.outMask)
                    };
                    XtDevice        master   = outputMaster.Checked ? outputDevice : inputDevice;
                    LatencyCallback callback = new LatencyCallback(OnStreamError, AddMessage);
                    outputStream = ((XtService)service.SelectedItem).AggregateStream(devices, channels,
                                                                                     bufferSizes, devices.Length, outputFormat.mix, streamInterleaved.Checked, streamRaw.Checked,
                                                                                     master, callback.OnCallback, xRunCallback.OnCallback, "latency-user-data");
                    outputStream.Start();
                }

                stop.Enabled              = true;
                panel.Enabled             = false;
                start.Enabled             = false;
                streamRaw.Enabled         = false;
                bufferSize.Enabled        = false;
                streamType.Enabled        = false;
                outputMaster.Enabled      = false;
                secondaryInput.Enabled    = false;
                secondaryOutput.Enabled   = false;
                streamInterleaved.Enabled = false;
            } catch (XtException e) {
                Stop();
                MessageBox.Show(this, e.ToString(), "Failed to start stream.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 11
0
        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;
            }
        }
Esempio n. 12
0
 public XtAggregateDeviceParams(XtDevice device, in XtChannels channels, double bufferSize)
Esempio n. 13
0
        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();
                    }
                }
            }
        }
Esempio n. 14
0
        object Start()
        {
            StreamType type                  = (StreamType)_streamType.SelectedItem;
            bool       input                 = type == StreamType.Capture || type == StreamType.Duplex;
            bool       output                = type == StreamType.Render || type == StreamType.Duplex;
            var        inputInfo             = _input._device.SelectedItem as DeviceInfo;
            var        outputInfo            = _output._device.SelectedItem as DeviceInfo;
            XtDevice   inputDevice           = inputInfo?.Device;
            XtDevice   outputDevice          = outputInfo?.Device;
            XtDevice   secondaryInputDevice  = (_secondaryInput.SelectedItem as DeviceInfo).Device;
            XtDevice   secondaryOutputDevice = (_secondaryOutput.SelectedItem as DeviceInfo).Device;

            bool   anyInput         = inputDevice != null || secondaryInputDevice != null;
            bool   anyOutput        = outputDevice != null || secondaryOutputDevice != null;
            string duplexMessage    = "For duplex operation, input and output device must be the same.";
            string aggregateMessage = "For aggregate operation, select at least 1 input and 1 output device.";

            if (input && inputDevice == null)
            {
                return(MessageBox.Show(this, "Select an input device.", "Invalid input device."));
            }
            if (output && outputDevice == null)
            {
                return(MessageBox.Show(this, "Select an output device.", "Invalid output device."));
            }
            if (type == StreamType.Duplex && inputInfo.Id != outputInfo.Id)
            {
                return(MessageBox.Show(this, duplexMessage, "Invalid duplex device."));
            }
            if (type == StreamType.Aggregate && (!anyInput || !anyOutput))
            {
                return(MessageBox.Show(this, aggregateMessage, "Invalid aggregate device."));
            }

            var      state         = _logXRuns.CheckState;
            XtSystem system        = (XtSystem)_system.SelectedItem;
            OnXRun   onXRunWrapper = new OnXRun(AddMessage);
            bool     doLogXRuns    = state == CheckState.Checked || (state == CheckState.Indeterminate && system != XtSystem.JACK);
            XtOnXRun onXRun        = doLogXRuns ? onXRunWrapper.Callback : (XtOnXRun)null;

            XtFormat inputFormat    = GetFormat(false).Value;
            var      inputSelection = _input._channels.SelectedItems;

            inputFormat.channels.inputs = (int)_channelCount.SelectedItem;
            string inputChannelMessage = "Selected either 0 input channels or a number equal to the selected format's channels.";

            if (input && inputSelection.Count > 0 && inputSelection.Count != inputFormat.channels.inputs)
            {
                return(MessageBox.Show(this, inputChannelMessage, "Invalid input channel mask."));
            }
            for (int c = 0; c < inputSelection.Count; c++)
            {
                inputFormat.channels.inMask |= (1UL << ((ChannelInfo)inputSelection[c]).Index);
            }

            XtFormat outputFormat    = GetFormat(true).Value;
            var      outputSelection = _output._channels.SelectedItems;

            outputFormat.channels.outputs = (int)_channelCount.SelectedItem;
            string outputChannelMessage = "Selected either 0 output channels or a number equal to the selected format's channels.";

            if (output && outputSelection.Count > 0 && outputSelection.Count != outputFormat.channels.outputs)
            {
                return(MessageBox.Show(this, outputChannelMessage, "Invalid output channel mask."));
            }
            for (int c = 0; c < outputSelection.Count; c++)
            {
                outputFormat.channels.outMask |= (1UL << ((ChannelInfo)outputSelection[c]).Index);
            }

            int  buffer      = _bufferSize.Value;
            bool native      = _streamNative.Checked;
            bool interleaved = _streamInterleaved.Checked;

            var @params = new OnBufferParams(interleaved, native, AddMessage);

            if (type == StreamType.Capture)
            {
                @params.Name = "Capture";
                _captureFile = new FileStream("xt-audio.raw", FileMode.Create, FileAccess.Write);
                OnCapture callback     = new OnCapture(@params, _captureFile);
                var       streamParams = new XtStreamParams(interleaved, callback.Callback, onXRun, OnRunning);
                var       deviceParams = new XtDeviceStreamParams(in streamParams, in inputFormat, buffer);
                _stream = inputDevice.OpenStream(in deviceParams, "capture-user-data");
                callback.Init(_stream.GetFormat(), _stream.GetFrames());
                _safeBuffer = XtSafeBuffer.Register(_stream, interleaved);
                _stream.Start();
            }
            else if (type == StreamType.Render)
            {
                @params.Name = "Render";
                OnRender callback     = new OnRender(@params);
                var      streamParams = new XtStreamParams(interleaved, callback.Callback, onXRun, OnRunning);
                var      deviceParams = new XtDeviceStreamParams(in streamParams, in outputFormat, buffer);
                _stream     = outputDevice.OpenStream(in deviceParams, "render-user-data");
                _safeBuffer = XtSafeBuffer.Register(_stream, interleaved);
                _stream.Start();
            }
            else if (type == StreamType.Duplex)
            {
                @params.Name = "Duplex";
                XtFormat duplexFormat = inputFormat;
                duplexFormat.channels.outputs = outputFormat.channels.outputs;
                duplexFormat.channels.outMask = outputFormat.channels.outMask;
                OnFullDuplex callback     = new OnFullDuplex(@params);
                var          streamParams = new XtStreamParams(interleaved, callback.Callback, onXRun, OnRunning);
                var          deviceParams = new XtDeviceStreamParams(in streamParams, in duplexFormat, buffer);
                _stream     = outputDevice.OpenStream(in deviceParams, "duplex-user-data");
                _safeBuffer = XtSafeBuffer.Register(_stream, interleaved);
                _stream.Start();
            }
            else if (type == StreamType.Aggregate)
            {
                @params.Name = "Aggregate";
                var      devices = new List <XtAggregateDeviceParams>();
                XtDevice master  = _outputMaster.Checked ? (outputDevice ?? secondaryOutputDevice) : (inputDevice ?? secondaryInputDevice);
                if (inputDevice != null)
                {
                    devices.Add(new XtAggregateDeviceParams(inputDevice, inputFormat.channels, buffer));
                }
                if (outputDevice != null)
                {
                    devices.Add(new XtAggregateDeviceParams(outputDevice, outputFormat.channels, buffer));
                }
                if (secondaryInputDevice != null)
                {
                    devices.Add(new XtAggregateDeviceParams(secondaryInputDevice, inputFormat.channels, buffer));
                }
                if (secondaryOutputDevice != null)
                {
                    devices.Add(new XtAggregateDeviceParams(secondaryOutputDevice, outputFormat.channels, buffer));
                }
                OnAggregate streamCallback  = new OnAggregate(@params);
                var         streamParams    = new XtStreamParams(interleaved, streamCallback.Callback, onXRun, OnRunning);
                var         aggregateParams = new XtAggregateStreamParams(in streamParams, devices.ToArray(), devices.Count, outputFormat.mix, master);
                _stream = _platform.GetService(system).AggregateStream(in aggregateParams, "aggregate-user-data");
                streamCallback.Init(_stream.GetFrames());
                _safeBuffer = XtSafeBuffer.Register(_stream, interleaved);
                _stream.Start();
            }
            return(null);
        }