コード例 #1
0
        private int ProcessAudio(ref ProcessData data)
        {
            // flushing parameters
            if (data.NumInputs == 0 || data.NumOutputs == 0 || data.NumSamples == 0)
            {
                return(TResult.S_OK);
            }

            if (data.NumInputs != _audioInputs.Count || data.NumOutputs != _audioOutputs.Count)
            {
                return(TResult.E_Unexpected);
            }

            var inputBusInfo  = _audioInputs[0];
            var outputBusInfo = _audioOutputs[0];

            if (!inputBusInfo.IsActive || !outputBusInfo.IsActive)
            {
                return(TResult.S_False);
            }

            // hard-coded on one stereo input and one stereo output bus (see ctor)
            var inputBus  = new AudioBusAccessor(ref data, BusDirections.Input, 0);
            var outputBus = new AudioBusAccessor(ref data, BusDirections.Output, 0);

            unsafe
            {
                for (int c = 0; c < inputBus.ChannelCount; c++)
                {
                    var input  = inputBus.GetUnsafeBuffer32(c);
                    var output = outputBus.GetUnsafeBuffer32(c);
                    outputBus.SetChannelSilent(0, input == null);

                    if (input != null && output != null)
                    {
                        for (int i = 0; i < outputBus.SampleCount; i++)
                        {
                            output[i] = input[i];
                        }
                    }
                }
            }

            return(TResult.S_OK);
        }
コード例 #2
0
ファイル: PluginComponent.cs プロジェクト: autophage/vst.net
        private int ProcessAudio(ref ProcessData data)
        {
            // flushing parameters
            if (data.NumInputs == 0 || data.NumOutputs == 0)
            {
                return(TResult.S_OK);
            }

            if (data.NumInputs != _audioInputs.Count || data.NumOutputs != _audioOutputs.Count)
            {
                return(TResult.E_Unexpected);
            }

            var inputBusInfo  = _audioInputs[0];
            var outputBusInfo = _audioOutputs[0];

            if (!inputBusInfo.IsActive || !outputBusInfo.IsActive)
            {
                return(TResult.S_False);
            }

            // hard-coded on one stereo input and one stereo output bus
            var inputBus  = new AudioBusAccessor(ref data, BusDirections.Input, 0);
            var outputBus = new AudioBusAccessor(ref data, BusDirections.Output, 0);

            unsafe
            {
                // can return null!
                var inputLeft = inputBus.GetUnsafeBuffer32(0);
                //var inputRight = inputBus.GetUnsafeBuffer32(1);
                // TODO: check max num channels
                float *inputRight = null;

                var outputLeft = outputBus.GetUnsafeBuffer32(0);
                //var outputRight = outputBus.GetUnsafeBuffer32(1);
                // TODO: check max num channels
                float *outputRight = null;

                // silent inputs result in silent outputs
                outputBus.SetChannelSilent(0, inputLeft == null);
                outputBus.SetChannelSilent(1, inputRight == null);

                if (outputLeft != null && inputLeft != null &&
                    outputRight != null && inputRight != null)
                {
                    // copy samples
                    for (int i = 0; i < outputBus.SampleCount; i++)
                    {
                        outputLeft[i]  = inputLeft[i];
                        outputRight[i] = inputRight[i];
                    }
                }
                else if (outputLeft != null && inputLeft != null)
                {
                    // copy samples
                    for (int i = 0; i < outputBus.SampleCount; i++)
                    {
                        outputLeft[i] = inputLeft[i];
                    }
                }
                else if (outputRight != null && inputRight != null)
                {
                    // copy samples
                    for (int i = 0; i < outputBus.SampleCount; i++)
                    {
                        outputRight[i] = inputRight[i];
                    }
                }
            }

            return(TResult.S_OK);
        }