Example #1
0
        internal void StreamCallback(IntPtr stream, IntPtr input, IntPtr output,
            int frames, double time, ulong position, bool timeValid, ulong error, IntPtr u) {

            XtFormat format = GetFormat();
            bool interleaved = IsInterleaved();
            object inData = raw ? (object)input : input == IntPtr.Zero ? null : interleaved ? inputInterleaved : inputNonInterleaved;
            object outData = raw ? (object)output : output == IntPtr.Zero ? null : interleaved ? outputInterleaved : outputNonInterleaved;

            if (!raw && inData != null)
                if (interleaved)
                    CopyInterleavedBufferFromNative(format.mix.sample, input, (Array)inData, format.inputs, frames);
                else
                    CopyNonInterleavedBufferFromNative(format.mix.sample, input, (Array)inData, format.inputs, frames);

            try {
                streamCallback(this, inData, outData, frames, time, position, timeValid, error, user);
            } catch (Exception e) {
                if (XtAudio.trace != null)
                    XtAudio.trace(XtLevel.Fatal, string.Format("Exception caught in xrun callback: {0}.", e));
                Console.WriteLine(e);
                Console.WriteLine(e.StackTrace);
                Environment.FailFast("Exception caught in stream callback.", e);
            }

            if (!raw && outData != null)
                if (interleaved)
                    CopyInterleavedBufferToNative(format.mix.sample, (Array)outData, output, format.outputs, frames);
                else
                    CopyNonInterleavedBufferToNative(format.mix.sample, (Array)outData, output, format.outputs, frames);
        }
Example #2
0
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            log = new StreamWriter("xt-audio.log");

            audio      = new XtAudio("XT-Gui", Handle, OnTrace, OnFatal);
            debug.Text = "Debug: False";
#if DEBUG
            debug.Text = "Debug: True";
#endif
            x64.Text     = "X64: " + (IntPtr.Size == 8);
            isWin32.Text = "Win32: " + XtAudio.IsWin32();
            version.Text = "Version: " + XtAudio.GetVersion();

            rate.DataSource           = Rates;
            rate.SelectedItem         = 44100;
            sample.DataSource         = Samples;
            sample.SelectedItem       = XtSample.Int16;
            channelCount.DataSource   = ChannelCounts;
            channelCount.SelectedItem = 2;
            streamType.DataSource     = StreamTypes;
            streamType.SelectedItem   = StreamType.Render;

            List <XtService> services = new List <XtService>();
            for (int i = 0; i < XtAudio.GetServiceCount(); i++)
            {
                services.Add(XtAudio.GetServiceByIndex(i));
            }
            service.DataSource = services;
        }
Example #3
0
        void FormatOrDeviceChanged()
        {
            if (_suspendDeviceChanged)
            {
                return;
            }
            _bufferSize.Minimum = 1;
            _bufferSize.Maximum = 5000;
            _bufferSize.Value   = 1000;
            _output.FormatOrDeviceChanged(true, GetFormat(true));
            _input.FormatOrDeviceChanged(false, GetFormat(false));

            if (_sample.SelectedItem != null)
            {
                var attrs = XtAudio.GetSampleAttributes((XtSample)_sample.SelectedItem);
                _attributes.Text = $"Size: {attrs.size}, Count: {attrs.count}, Float: {attrs.isFloat}, Signed: {attrs.isSigned}";
            }

            var  format    = GetFormat(true);
            bool supported = format == null ? false : (_output._device.SelectedItem as DeviceInfo)?.Device?.SupportsFormat(format.Value) == true;
            var  buffer    = format == null || !supported ? null : (_output._device.SelectedItem as DeviceInfo)?.Device?.GetBufferSize(format.Value);

            if (buffer != null)
            {
                _bufferSize.Minimum       = (int)Math.Floor(buffer.Value.min);
                _bufferSize.Maximum       = (int)Math.Ceiling(buffer.Value.max);
                _bufferSize.Value         = (int)Math.Ceiling(buffer.Value.current);
                _bufferSize.TickFrequency = (_bufferSize.Maximum - _bufferSize.Minimum) / 10;
            }
        }
Example #4
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();
                        }
                }
            }
        }
Example #5
0
        static int GetBufferSize(XtStream stream, int frames)
        {
            XtFormat format     = stream.GetFormat();
            int      sampleSize = XtAudio.GetSampleAttributes(format.mix.sample).size;

            return(frames * format.inputs * sampleSize);
        }
Example #6
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();
                            }
                        }
                    }
            }
        }
Example #7
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();
                    }
                }
            }
        }
Example #8
0
        static void HandleAssert()
        {
            var assert = XtAudio.GetLastAssert();

            if (assert != null)
            {
                throw new InvalidOperationException(assert);
            }
        }
Example #9
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();
                    }
                }
            }
        }
Example #10
0
        static void OnRunning(XtStream stream, bool running, ulong error, object user)
        {
            string evt = running ? "Started" : "Stopped";

            Console.WriteLine("Stream event: " + evt + ", new state: " + stream.IsRunning() + ".");
            if (error != 0)
            {
                Console.WriteLine(XtAudio.GetErrorInfo(error).ToString());
            }
        }
Example #11
0
        static void OnError(Exception e)
        {
            string message = e.ToString();

            if (e is XtException xt)
            {
                message = XtAudio.GetErrorInfo(xt.GetError()).ToString();
            }
            MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Example #12
0
 internal XtSafeBuffer(XtStream stream, bool interleaved)
 {
     _stream      = stream;
     _interleaved = interleaved;
     _format      = stream.GetFormat();
     _inputs      = _format.channels.inputs;
     _outputs     = _format.channels.outputs;
     _attrs       = XtAudio.GetSampleAttributes(_format.mix.sample);
     _input       = CreateBuffer(_inputs);
     _output      = CreateBuffer(_outputs);
 }
Example #13
0
        static void OnAggregate(XtStream stream, object input, object output, int frames, double time,
                                ulong position, bool timeValid, ulong error, object user)
        {
            XtFormat     format = stream.GetFormat();
            XtAttributes attrs  = XtAudio.GetSampleAttributes(format.mix.sample);

            if (frames > 0)
            {
                Buffer.BlockCopy((Array)input, 0, (Array)output, 0, frames * format.inputs * attrs.size);
            }
        }
Example #14
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());
                }
            }
        }
Example #15
0
 internal void XRunCallback(int index, IntPtr user) {
     try {
         xRunCallback(index, this.user);
     } catch (Exception e) {
         if (XtAudio.trace != null)
             XtAudio.trace(XtLevel.Fatal, string.Format("Exception caught in xrun callback: {0}.", e));
         Console.WriteLine(e);
         Console.WriteLine(e.StackTrace);
         Environment.FailFast("Exception caught in stream callback.", e);
     }
 }
Example #16
0
 void OnStart(object sender, EventArgs ea)
 {
     try
     {
         Start();
     } catch (XtException e)
     {
         Stop();
         var caption = "Failed to start stream.";
         var message = XtAudio.GetErrorInfo(e.GetError()).ToString();
         MessageBox.Show(this, message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #17
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());
             }
         }
     }
 }
Example #18
0
        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); }
        }
Example #19
0
 static void CaptureNonInterleaved(XtStream stream, object input, object output,
                                   int frames, double time, ulong position, bool timeValid, ulong error, object user)
 {
     if (frames > 0)
     {
         Context  ctx        = (Context)user;
         XtFormat format     = stream.GetFormat();
         int      channels   = format.inputs;
         int      sampleSize = XtAudio.GetSampleAttributes(format.mix.sample).size;
         for (int f = 0; f < frames; f++)
         {
             for (int c = 0; c < channels; c++)
             {
                 // Don't do this.
                 ctx.recording.Write(((byte[][])input)[c], f * sampleSize, sampleSize);
             }
         }
     }
 }
Example #20
0
 static unsafe void CaptureNonInterleavedRaw(XtStream stream, object input, object output,
                                             int frames, double time, ulong position, bool timeValid, ulong error, object user)
 {
     if (frames > 0)
     {
         Context  ctx        = (Context)user;
         XtFormat format     = stream.GetFormat();
         int      channels   = format.inputs;
         int      sampleSize = XtAudio.GetSampleAttributes(format.mix.sample).size;
         for (int f = 0; f < frames; f++)
         {
             for (int c = 0; c < channels; c++)
             {
                 IntPtr source = new IntPtr(&(((byte **)(IntPtr)input)[c][f * sampleSize]));
                 Marshal.Copy(source, ctx.intermediate, 0, sampleSize);
                 // Don't do this.
                 ctx.recording.Write(ctx.intermediate, 0, sampleSize);
             }
         }
     }
 }
Example #21
0
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            var version = XtAudio.GetVersion();

            _log = new StreamWriter($"xt-audio.log");
            Text = $"XT-Audio {version.major}.{version.minor}";
            XtAudio.SetOnError(OnError);
            _platform = XtAudio.Init("XT-Gui", Handle);
            _input._deviceLabel.Text              = "Input device: ";
            _output._deviceLabel.Text             = "Output device: ";
            _input._device.SelectedValueChanged  += OnDeviceChanged;
            _output._device.SelectedValueChanged += OnDeviceChanged;
            _rate.DataSource           = Rates;
            _rate.SelectedItem         = 48000;
            _sample.DataSource         = Samples;
            _sample.SelectedItem       = XtSample.Int16;
            _channelCount.DataSource   = ChannelCounts;
            _channelCount.SelectedItem = 2;
            _system.DataSource         = _platform.GetSystems();
        }
Example #22
0
        public static void Main(string[] args)
        {
            int index = args.Length == 1 ? int.Parse(args[0]) : -1;

            try
            {
                if (index >= 0)
                {
                    RunSample(index);
                }
                else
                {
                    for (int i = 0; i < Samples.Length; i++)
                    {
                        RunSample(i);
                    }
                }
            } catch (XtException e)
            { Console.WriteLine(XtAudio.GetErrorInfo(e.GetError())); } catch (Exception e)
            { Console.WriteLine(e.Message); }
        }
Example #23
0
        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);
        }
Example #24
0
        internal override unsafe void OnCallback(XtFormat format, bool interleaved,
                                                 bool raw, object input, object output, int frames)
        {
            int sampleSize = XtAudio.GetSampleAttributes(format.mix.sample).size;

            if (!raw)
            {
                if (interleaved)
                {
                    Buffer.BlockCopy((Array)input, 0, (Array)output, 0, frames * format.inputs * sampleSize);
                }
                else
                {
                    for (int i = 0; i < format.inputs; i++)
                    {
                        Buffer.BlockCopy((Array)(((Array)input).GetValue(i)), 0, (Array)(((Array)output).GetValue(i)), 0, frames * sampleSize);
                    }
                }
            }
            else
            {
                if (interleaved)
                {
                    Utility.MemCpy((IntPtr)output, (IntPtr)input, new IntPtr(frames * format.inputs * sampleSize));
                }
                else
                {
                    for (int i = 0; i < format.inputs; i++)
                    {
                        Utility.MemCpy(
                            new IntPtr(((void **)(((IntPtr)output).ToPointer()))[i]),
                            new IntPtr(((void **)(((IntPtr)input).ToPointer()))[i]),
                            new IntPtr(frames * sampleSize));
                    }
                }
            }
        }
Example #25
0
        void OnRunning(XtStream stream, bool running, ulong error, object user)
        {
            bool evt      = running;
            bool newState = stream.IsRunning();

            BeginInvoke(new Action(() => {
                string evtDesc = running ? "Started" : "Stopped";
                AddMessage(() => "Stream event: " + evtDesc + ", new state: " + newState + ".");
                if (error != 0)
                {
                    AddMessage(() => XtAudio.GetErrorInfo(error).ToString());
                }
                _stop.Enabled              = running;
                panel.Enabled              = !running;
                _start.Enabled             = !running;
                _bufferSize.Enabled        = !running;
                _streamType.Enabled        = !running;
                _streamNative.Enabled      = !running;
                _outputMaster.Enabled      = !running;
                _secondaryInput.Enabled    = !running;
                _secondaryOutput.Enabled   = !running;
                _streamInterleaved.Enabled = !running;
            }));
        }
Example #26
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())); }
     }
 }
Example #27
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;
            }
        }
Example #28
0
        static int GetBufferSize(int channels, int frames)
        {
            int size = XtAudio.GetSampleAttributes(Mix.sample).size;

            return(channels * frames * size);
        }
Example #29
0
 internal void Init(XtFormat format, int maxFrames)
 {
     frameSize         = format.inputs * XtAudio.GetSampleAttributes(format.mix.sample).size;
     block             = new byte[maxFrames * frameSize];
     interleavedBuffer = Utility.CreateInterleavedBuffer(format.mix.sample, format.inputs, maxFrames);
 }
Example #30
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();
                        }
                }
            }
        }