Beispiel #1
0
        public override void Process()
        {
            if (haveSimulationError)
            {
                monoInput.PassThroughTo(monoOutput);
            }
            else
            {
                double[][] inBuffers  = monoInput.GetAudioBuffers();
                double[][] outBuffers = monoOutput.GetAudioBuffers();

                // Read input samples from unmanaged memory
                monoInput.ReadData();

                try
                {
                    SimulationProcessor.RunSimulation(inBuffers, outBuffers, inBuffers[0].Length);
                }
                catch (Exception ex)
                {
                    haveSimulationError = true;

                    new Thread(() =>
                    {
                        MessageBox.Show("Error running circuit simulation.\n\n" + ex.Message, "Simulation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }).Start();
                }

                // Write outout samples to unmanaged memory
                monoOutput.WriteData();
            }
        }
        /// <summary>
        /// Process a buffer of samples from the VST host
        /// </summary>
        /// <param name="input">IntPtr to a double** of input samples</param>
        /// <param name="output">IntPtr to a double** of output samples</param>
        /// <param name="inChannelCount">The number of input channels</param>
        /// <param name="outChannelCount">The number of output channels</param>
        /// <param name="bufferSize">The buffer size in samples</param>
        public void ProcessSample(IntPtr input, IntPtr output, uint inChannelCount, uint outChannelCount, uint bufferSize)
        {
            if (haveSimulationError)
            {
                // If we had an error running the simulation, bypass it

                uint bytesToCopy = bufferSize * sizeof(double);

                Buffer.MemoryCopy((void *)((double **)input)[0], (void *)((double **)output)[0], bytesToCopy, bytesToCopy);
            }
            else
            {
                // Check if our buffer size has changed
                if (currentBufferSize != bufferSize)
                {
                    if (currentBufferSize < bufferSize)
                    {
                        currentBufferSize = (int)bufferSize;

                        Array.Resize <double>(ref inputBuffers[0], currentBufferSize);
                        Array.Resize <double>(ref outputBuffers[0], currentBufferSize);
                    }
                    else
                    {
                        currentBufferSize = (int)bufferSize;
                    }
                }

                // We are doing mono processing, so just grab the left input and output channel
                IntPtr leftIn  = (IntPtr)((double **)input)[0];
                IntPtr leftOut = (IntPtr)((double **)output)[0];

                Marshal.Copy(leftIn, inputBuffers[0], 0, currentBufferSize);

                try
                {
                    SimulationProcessor.RunSimulation(inputBuffers, outputBuffers, currentBufferSize);
                }
                catch (Exception ex)
                {
                    haveSimulationError = true;

                    new Thread(() =>
                    {
                        MessageBox.Show("Error running circuit simulation.\n\n" + ex.Message, "Simulation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }).Start();
                }

                Marshal.Copy(outputBuffers[0], 0, leftOut, currentBufferSize);
            }
        }