Example #1
0
 /// <summary>
 /// Plays back the current sample buffer
 /// </summary>
 /// <param name="outChannels">Output buffers. Must not be null.</param>
 public void PlayAudio(VstAudioBuffer[] outChannels)
 {
     if (IsPlaying)
     {
         _player.Play(outChannels[0], outChannels[1]);
     }
 }
Example #2
0
 private void AssertBufferHasValue(VstAudioBuffer buffer, float value)
 {
     for (int i = 0; i < buffer.SampleCount; i++)
     {
         buffer[i].Should().Be(value);
     }
 }
 private void AssertBufferHasValue(VstAudioBuffer buffer, float value)
 {
     for (int i = 0; i < buffer.SampleCount; i++)
     {
         Assert.AreEqual(value, buffer[i]);
     }
 }
Example #4
0
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            // check to see if we need to output midi here
            if (_plugin.MidiProcessor.SyncWithAudioProcessor)
            {
                _plugin.MidiProcessor.ProcessCurrentEvents();
            }

            if (_plugin.SampleManager.IsPlaying)
            {
                _plugin.SampleManager.PlayAudio(outChannels);
            }
            else
            {
                VstAudioBuffer input  = inChannels[0];
                VstAudioBuffer output = outChannels[0];

                for (int index = 0; index < output.SampleCount; index++)
                {
                    output[index] = input[index];
                }

                input  = inChannels[1];
                output = outChannels[1];

                for (int index = 0; index < output.SampleCount; index++)
                {
                    output[index] = input[index];
                }
            }
        }
Example #5
0
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            if (_plugin.SampleManager.IsPlaying)
            {
                _plugin.SampleManager.PlayAudio(outChannels);
            }
            else // audio thru
            {
                VstAudioBuffer input  = inChannels[0];
                VstAudioBuffer output = outChannels[0];

                for (int index = 0; index < output.SampleCount; index++)
                {
                    output[index] = input[index];
                }

                input  = inChannels[1];
                output = outChannels[1];

                for (int index = 0; index < output.SampleCount; index++)
                {
                    output[index] = input[index];
                }
            }

            if (_plugin.SampleManager.IsRecording)
            {
                _plugin.SampleManager.RecordAudio(inChannels);
            }
        }
Example #6
0
 // process a single audio channel
 private void Process(VstAudioBuffer input, VstAudioBuffer output)
 {
     for (int i = 0; i < input.SampleCount; i++)
     {
         output[i] = Delay.ProcessSample(input[i]);
     }
 }
Example #7
0
        /// <summary>
        /// Called by the host to allow the plugin to process audio samples.
        /// </summary>
        /// <param name="inChannels">Never null.</param>
        /// <param name="outChannels">Never null.</param>
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            // calling the base class transfers input samples to the output channels unchanged (bypass).
            //base.Process(inChannels, outChannels);

            if (_plugin._synth.IsPlaying)
            {
                _plugin._synth.SampleCount = outChannels[0].SampleCount;
                _plugin._synth.PlayAudio(outChannels);
            }
            else // audio thru
            {
                VstAudioBuffer input = inChannels[0];
                VstAudioBuffer output = outChannels[0];

                for (int index = 0; index < output.SampleCount; index++)
                {
                    output[index] = input[index];
                }

                input = inChannels[1];
                output = outChannels[1];

                for (int index = 0; index < output.SampleCount; index++)
                {
                    output[index] = input[index];
                }
            }

            _plugin.MidiProcessor.ProcessCurrentEvents();
        }
Example #8
0
        /// <summary>
        /// Perform audio processing on the specified <paramref name="inChannels"/>
        /// and produce a delay effect on the <paramref name="outChannels"/>.
        /// </summary>
        /// <param name="inChannels">The audio input buffers.</param>
        /// <param name="outChannels">The audio output buffers.</param>
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            VstAudioBuffer audioChannel = outChannels[0];

            for (int n = 0; n < audioChannel.SampleCount; n++)
            {
                audioChannel[n] = Delay.ProcessSample(inChannels[0][n]);
            }
        }
Example #9
0
        public static double AvgEnv(this VstAudioBuffer buffer)
        {
            double[] lvls = new double[buffer.SampleCount];
            for (int i = 0; i < buffer.SampleCount; i++)
            {
                lvls[i] = Math.Abs(buffer[i]);
            }

            return(lvls.Average());
        }
Example #10
0
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            var inChannel = inChannels[0];
            var outChannel = outChannels[0];

            for (var i = 0; i < inChannel.SampleCount; i++)
            {
                outChannel[i] = ProcessSample(inChannel[i]);
            }
        }
Example #11
0
        /// <summary>
        /// Traite le signal en entrée pour y ajouter un délai
        /// </summary>
        public void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            // Récupération d'un canal en sortie
            VstAudioBuffer audioChannel = outChannels[0];

            // Pour chaque échantillon on fait le traitement
            for (int n = 0; n < audioChannel.SampleCount; n++)
            {
                audioChannel[n] = Delay.ProcessSample(inChannels[0][n]);
            }
        }
Example #12
0
            public void Record(VstAudioBuffer left, VstAudioBuffer right)
            {
                for (int index = 0; index < left.SampleCount; index++)
                {
                    Buffer.LeftSamples.Add(left[index]);
                }

                for (int index = 0; index < right.SampleCount; index++)
                {
                    Buffer.RightSamples.Add(right[index]);
                }
            }
Example #13
0
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            if (_timeOut > 0)
            {
                _timeOut--;
                return;
            }
            try
            {
                if (_blockSize != BlockSize || _sampleRate != SampleRate)
                {
                    SetUp();
                }
                if (_out == null)
                {
                    throw new SlooException("Process", "null output");
                }
                VstAudioBuffer input  = inChannels[0];
                VstAudioBuffer output = outChannels[0];
                _out.NextBlock(++_blockNr);
                for (int index = 0; index < output.SampleCount; index++)
                {
                    output[index] = 0;
                    for (int c = 0; c < _out.Channels; c++)
                    {
                        output[index] += (float)_out[index, c];
                    }
                }


                for (int channel = 1; channel < outChannels.Length; channel++)
                {
                    for (int index = 0; index < output.SampleCount; index++)
                    {
                        outChannels[channel][index] = output[index];
                    }
                }

                CurrentSample += (uint)this.BlockSize;
            }
            catch (Exception e)
            {
                var msg = new StringBuilder(e.Message);
                msg.AppendLine(e.StackTrace);
                msg.Append("INNER: ");
                msg.AppendLine(e?.InnerException?.Message ?? "");
                msg.AppendLine(e?.InnerException?.StackTrace ?? "");
                LogLine(msg.ToString());
                _timeOut = 50;
            }
        }
Example #14
0
        /// <inheritdoc />
        /// <remarks>This method is used to push midi inputEvents to the host.</remarks>
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            if (_hostProcessor == null)
            {
                _hostProcessor = _plugin.Host.GetInstance<IVstMidiProcessor>();
            }

            if (_midiProcessor != null && _hostProcessor != null &&
                _midiProcessor.Events.Count > 0)
            {
                _hostProcessor.Process(_midiProcessor.Events);
                _midiProcessor.Events.Clear();
            }

            // perform audio-through
            base.Process(inChannels, outChannels);
        }
Example #15
0
        /// <summary>
        /// Méthode qui effectue le traitement
        /// </summary>
        /// <param name="inputs">Entrées</param>
        /// <param name="outputs">Sorties</param>
        public void Process(VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)
        {
            // On affecte à nos variables de traitement la première entrée et la première sortie (canal mono 1)
            VstAudioBuffer input  = inputs[0];
            VstAudioBuffer output = outputs[0];

            // Pour chaque échantillon en entrée on recopie le signal en sortie.
            for (int index = 0; index < output.SampleCount; index++)
            {
                output[index] = input[index];
            }

            // On effectue le même traitement avec la seconde entrée et la seconde sortie (canal mono 2)
            input  = inputs[1];
            output = outputs[1];

            for (int index = 0; index < output.SampleCount; index++)
            {
                output[index] = input[index];
            }
        }
Example #16
0
            public void Play(VstAudioBuffer left, VstAudioBuffer right)
            {
                if (IsFinished)
                {
                    return;
                }

                int count = Math.Min(left.SampleCount, Buffer.LeftSamples.Count - _bufferIndex);

                for (int index = 0; index < count; index++)
                {
                    left[index] = Buffer.LeftSamples[_bufferIndex + index];
                }

                for (int index = 0; index < count; index++)
                {
                    right[index] = Buffer.RightSamples[_bufferIndex + index];
                }

                _bufferIndex += left.SampleCount;
            }
 /// <summary>
 /// Not implemented.
 /// </summary>
 /// <param name="inputs">Not used.</param>
 /// <param name="outputs">Not used.</param>
 /// <remarks>Method does nothing.</remarks>
 public virtual void ProcessAcc(VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)
 {
     // nop
 }
Example #18
0
        public bool PlayAudio(VstAudioBuffer[] outChannels)
        {
            if (!_isPlaying || _lockPlay)
                return false;
            if (_sndFloatBufferListIndex==-1 || (int)_sndFloatBufferIndex >= _sndFloatBufferList[_sndFloatBufferListIndex].Length)
                _isPlaying = false;
            if (_isPlaying)
            {
                int n = 0;
                int ll = outChannels[0].SampleCount;

                lock (_sndFloatBufferList)
                {
                    if ((int)_sndFloatBufferIndex < _sndFloatBufferList[_sndFloatBufferListIndex].Length)
                    {
                        float[] fBuff = new float[ll];
                        float[][] fBuffMore = null;

                        int l = _sndFloatBufferList[_sndFloatBufferListIndex].Length - (int)_sndFloatBufferIndex;
                        for (int i = 0; i < ll; i++)
                        {
                            if ((int)_sndFloatBufferIndex + i < _sndFloatBufferList[_sndFloatBufferListIndex].Length)
                                fBuff[i] = _sndFloatBufferList[_sndFloatBufferListIndex][(int)_sndFloatBufferIndex + i];
                            else
                                fBuff[i] = 0;
                        }

                        if (_currentNoteList.Count > 0)
                        {
                            lock (_currentNoteList)
                            {
                                int ii = 0;
                                fBuffMore = new float[_currentNoteList.Count][];
                                foreach (CurrentNote cNote in _currentNoteList)
                                {
                                    if ((int)cNote._bufferIndex < _sndFloatBufferList[cNote._bufferListIndex].Length)
                                    {
                                        fBuffMore[ii] = new float[ll];

                                        l = _sndFloatBufferList[cNote._bufferListIndex].Length - (int)cNote._bufferIndex;
                                        for (int i = 0; i < ll; i++)
                                        {
                                            if ((int)cNote._bufferIndex + i < _sndFloatBufferList[cNote._bufferListIndex].Length)
                                                fBuffMore[ii][i] = _sndFloatBufferList[cNote._bufferListIndex][(int)cNote._bufferIndex + i];
                                            else
                                                fBuffMore[ii][i] = 0;
                                        }
                                        cNote._bufferIndex += ll;
                                    }
                                    ++ii;
                                }
                            }
                        }

                        for (n = 0; n < ll; n++)
                        {
                            if (_currentNoteList.Count > 0 && fBuffMore != null)
                            {
                                int nn = 0;
                                for (int i = 0; i < _currentNoteList.Count; i++)
                                {
                                    if (fBuffMore[i] != null)
                                    {
                                        fBuff[n] += fBuffMore[i][n];
                                        ++nn;
                                    }
                                }
                                if (nn > 0)
                                    fBuff[n] = fBuff[n] / nn;
                            }
                        }

                        _pitchShifter.PitchShift(_pitchTune, ll, 1024, 4, 44100, fBuff);

                        for (n = 0; n < ll; n++)
                        {
                            outChannels[0][n] = (fBuff[n]*_currentVelocity);
                            outChannels[1][n] = outChannels[0][n];
                        }
                    }

                    _sndFloatBufferIndex += ll;

                    if (_currentNoteList.Count > 0)
                    {
                        _currentNoteToKeepList.Clear();
                        lock (_currentNoteList)
                        {
                            foreach (CurrentNote cNote in _currentNoteList)
                            {
                                if (cNote._bufferIndex < _sndFloatBufferList[cNote._bufferListIndex].Length)
                                    _currentNoteToKeepList.Add(cNote);
                            }
                            if (_currentNoteToKeepList.Count < _currentNoteList.Count)
                                _currentNoteList = new List<CurrentNote>(_currentNoteToKeepList);
                        }
                    }
                }
                return true;
            }
            return false;
        }
 public void ProcessReplacing(VstAudioBuffer[] input, VstAudioBuffer[] outputs)
 {
 }
Example #20
0
 /// <summary>
 /// plugin.PluginCommandStub.ProcessReplacing(inputs, outputs);
 /// </summary>
 /// <param name="plugin"></param>
 /// <param name="inputs"></param>
 /// <param name="outputs"></param>
 VstAudioBuffer[] PluginPreProcess2(VstPlugin plugin, VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)
 {
     plugin.PluginCommandStub.StartProcess();
       plugin.PluginCommandStub.ProcessReplacing(inputs, outputs);
       plugin.PluginCommandStub.StopProcess();
       return outputs;
 }
Example #21
0
 /// <summary>
 /// Ignore nulll entries.
 /// Convert output to 2 channel if necessary.
 /// </summary>
 /// <param name="plugin"></param>
 /// <param name="inputs"></param>
 /// <param name="outputs">VstAudioBuffer[2]</param>
 VstAudioBuffer[] PluginProcess(VstPlugin plugin, VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)
 {
     VstAudioBuffer[] newinputs = inputs.Length == 1 ? new VstAudioBuffer[] {
     inputs[0],
     inputs[0]
       } : inputs;
       return plugin == null ? newinputs : PluginPreProcess2(plugin, newinputs, outputs);
 }
Example #22
0
            public void Play(VstAudioBuffer left, VstAudioBuffer right)
            {
                if (IsFinished)
                {
                    return;
                }

                //Add effects per gridItem here (gain, panning)
                //per effect waarschijnlijk class schrijven die de verschillende channels processed
                //Hier is ook informatie nodig van de CurrentKit uit de kitmanager

                int    count       = Math.Min(left.SampleCount, Buffer.LeftSamples.Count - _bufferIndex);
                double gain_factor = Math.Pow(10.0, GridItem.Gain / 20.0);

                float  dividingfactor = 120;
                double panfactorLeft  = Math.Pow(10.0, (GridItem.Panning * dividingfactor) / 20.0);
                double panfactorRight = Math.Pow(10.0, (GridItem.Panning * dividingfactor) / 20.0);

                for (int index = 0; index < count; index++)
                {
                    float signal = Buffer.LeftSamples[_bufferIndex + index];

                    //Add Gain
                    signal = signal * (float)gain_factor;

                    //Panning

                    //Optie 1
                    //ignal = signal - (GridItem.Panning / 2);

                    //Optie 2
                    //if (GridItem.Panning > 0) {
                    //    if (GridItem.Panning == 1) {
                    //        signal = signal * float.MinValue;
                    //    } else {
                    //        signal = signal * (float)panfactorLeft;
                    //    }
                    //}

                    //pan a mono audio source into stereo
                    //x is a numpy array, angle is the angle in radiants
                    double angle = GridItem.Panning * 100;
                    signal = (float)(Math.Sqrt(2) / 2.0 * (Math.Cos(angle) + Math.Sin(angle)) * signal);

                    left[index] = signal;
                }

                for (int index = 0; index < count; index++)
                {
                    float signal = Buffer.RightSamples[_bufferIndex + index];
                    //Add Gain
                    signal = signal * (float)gain_factor;

                    //Panning

                    //Optie 1
                    //signal = signal + (GridItem.Panning / 2);

                    //Optie 2
                    //if (GridItem.Panning < 0) {
                    //    if (GridItem.Panning == -1) {
                    //        signal = signal * float.MinValue;
                    //    } else {
                    //        signal = signal * (float)panfactorRight;
                    //    }
                    //}

                    //Optie 3
                    double angle = GridItem.Panning * 100;
                    signal = (float)(Math.Sqrt(2) / 2.0 * (Math.Cos(angle) - Math.Sin(angle)) * signal);

                    right[index] = signal;
                }

                _bufferIndex += left.SampleCount;
            }
Example #23
0
 /// <summary>
 /// With midi info
 /// </summary>
 /// <param name="plugin"></param>
 /// <param name="blockSize"></param>
 /// <param name="inputs"></param>
 /// <param name="outputs"></param>
 VstAudioBuffer[] PluginPreProcess1(VstPlugin plugin, int blockSize, VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)
 {
     if (HasMidi(plugin.Host.Parent))
     VstMidiEnumerator.SendMidi2Plugin( plugin, plugin.Host.Parent, blockSize );
       return PluginPreProcess2(plugin,inputs,outputs);
 }
Example #24
0
            public void Play(VstAudioBuffer left, VstAudioBuffer right)
            {
                _bufferIndex = 0;
                float clip;
                //System.IO.File.AppendAllText(@"C:\Users\Kavun\School\SPRING 12\CSC498\VST\KevinMidi1\KevinMidi1\bin\Debug\debug.txt", "PreLoad\n" + "_bufferIndex: " + _bufferIndex + "\n" + "bufferOffset: " + bufferOffset + "\n" + "Synth samples: " + SynthBuffer.LeftSamples.Count + "\n" + "OutputBufferSize: " + left.SampleCount + "\n\n");
                while (_bufferIndex + SynthBuffer.LeftSamples.Count < left.SampleCount)
                {
                    for (int index = bufferOffset; index < SynthBuffer.LeftSamples.Count; index++)
                    {
                        clip = SynthBuffer.LeftSamples[index];

                        if (time < attackTime) // attack envelope
                        {
                            clip = time / attackTime * clip;
                        }
                        else if (shouldEnd) // forced release envelope
                        {

                            if (releaseIndex == 0)
                            {
                                clip = 0;
                                isOn = false;
                            }
                            else
                            {
                                clip = clip * releaseIndex / releaseTime;
                                releaseIndex--;
                            }
                        }
                        left[_bufferIndex] = clip;
                        right[_bufferIndex] = clip;
                        _bufferIndex++;
                        time++;
                    }
                    if (bufferOffset != 0)
                        bufferOffset = 0;
                }
                bufferOffset = left.SampleCount - _bufferIndex;
                for (int index = 0; index < bufferOffset; index++)
                {

                        clip = SynthBuffer.LeftSamples[index];

                    if (time < attackTime)
                    {
                        clip = time / attackTime * clip; // attack envelope
                    }
                    else if (shouldEnd) // forced release envelope
                    {

                        if (releaseIndex == 0)
                        {
                            clip = 0;
                            isOn = false;
                        }
                        else
                        {
                            clip = clip * releaseIndex / releaseTime;
                            releaseIndex--;
                        }
                    }
                    left[_bufferIndex] = clip;
                    right[_bufferIndex] = clip;
                    _bufferIndex++;
                    time++;
                }
                //System.IO.File.AppendAllText(@"C:\Users\Kavun\School\SPRING 12\CSC498\VST\KevinMidi1\KevinMidi1\bin\Debug\debug.txt", "PostLoad\n" + "_bufferIndex: " + _bufferIndex + "\n" + "bufferOffset: " + bufferOffset + "\n" + "Synth samples: " + SynthBuffer.LeftSamples.Count + "\n" + "OutputBufferSize: " + left.SampleCount + "\n\n");
            }
Example #25
0
 public void Process(VstPlugin plugin, VstAudioBuffer[] insI, VstAudioBuffer[] insO)
 {
     plugin.PluginCommandStub.StartProcess();
     plugin.PluginCommandStub.ProcessReplacing(insI, insO);
     plugin.PluginCommandStub.StopProcess();
 }
        /// <summary>
        /// Called by the host once every cycle to process incoming audio as well as output audio.
        /// </summary>
        /// <param name="inputs">An array with audio input buffers.</param>
        /// <param name="outputs">An array with audio output buffers.</param>
        /// <remarks>The implementation calls the <see cref="IVstPluginAudioProcessor"/> interface.</remarks>
        public virtual void ProcessReplacing(VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)
        {
            IVstPluginAudioProcessor audioProcessor = pluginCtx.Plugin.GetInstance<IVstPluginAudioProcessor>();

            if (audioProcessor != null)
                audioProcessor.Process(inputs, outputs);
        }
Example #27
0
 public void Process(VstPlugin plugin, VstAudioBuffer[] inputs)
 {
     Process(plugin,inputs,boutput);
 }