コード例 #1
0
        public static XtSafeBuffer Register(XtStream stream, bool interleaved)
        {
            var result = new XtSafeBuffer(stream, interleaved);

            _map.Add(stream, result);
            return(result);
        }
コード例 #2
0
 void Stop()
 {
     _stream?.Stop();
     _stream?.Dispose();
     _stream = null;
     _captureFile?.Flush();
     _captureFile?.Dispose();
     _captureFile = null;
     _safeBuffer?.Dispose();
     _safeBuffer = null;
 }
コード例 #3
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);
        }