예제 #1
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();
                        }
                }
            }
        }
예제 #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(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();
                    }
                }
            }
        }
예제 #3
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();
                    }
                }
            }
        }
예제 #4
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();
                        }
                }
            }
        }
예제 #5
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);
            }
        }
예제 #6
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();
                    }
                }
            }
        }