Exemplo n.º 1
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());
                }
            }
        }
Exemplo n.º 2
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())); }
     }
 }
Exemplo n.º 3
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;
            }
        }