This project has moved. For the latest updates, please go here.

VSTi sound is rubbish

Apr 10, 2011 at 9:21 PM

Hi,

I'm creating a simple host program and have managed to load and process some Midi data in a VSTi. Unfortunatly the audio that is produced is just a stuttered noise. The code im using for audio out is as follows:

(Thanks to Yuryk for most of this!)

class VSTStream : WaveStream
    {
        public override WaveFormat WaveFormat { get { return new WaveFormat(); } }
        public override long Length { get { throw new System.NotSupportedException(); } }
        public override long Position { get { throw new System.NotSupportedException(); } set { throw new System.NotSupportedException(); } }

        public override int Read(byte[] buffer, int offset, int sampleCount)

        {
            // FILL THE AUDIO BUFFER WITH THE VST BUFFER HERE
          //  byte[] tempBuffer = vsti.processReplace(sampleCount);

            // Copying Vst buffer inside Audio buffer, no conversion needed for WaveProvider32
           // for (int i = 0; i < tempBuffer.Length; i++)
             //   buffer[i] = tempBuffer[i];


            // LET'S PLAY A SINE WAVE FOR NOW...
           // int sampleRate = 44100;
            //double amplitude = 0.25 * byte.MaxValue;
            //double frequency = 150;

            for (int n = 0; n < buffer.Length; n++)
            {
                // buffer[n] = (byte)(amplitude * Math.Sin((2 * Math.PI * n * frequency) / sampleRate));
                buffer[n] = (byte)Globals.globuf[n];
            }
            return sampleCount;
        }
    }

 

The Golbal variable globuf is loaded with data from the output buffers of the VSTi with the following code: (Again thanks to Yuryk for this!)

private void audioOut()
        {
            int inputCount = this.ctx.PluginInfo.AudioInputCount;
            int outputCount = this.ctx.PluginInfo.AudioOutputCount;
            int blockSize = 1024;
            VstAudioBufferManager inputMgr = new VstAudioBufferManager(inputCount, blockSize);
            VstAudioBufferManager outputMgr = new VstAudioBufferManager(outputCount, blockSize);

            foreach (VstAudioBuffer buffer in inputMgr.ToArray())
            {
                for (int i = 0; i < blockSize; i++)
                {
                    buffer[i] = 0; // Initialize to 0
                }
            }

            this.ctx.PluginCommandStub.SetBlockSize(blockSize);
            this.ctx.PluginCommandStub.SetSampleRate(44100f);

            VstAudioBuffer[] inputBuffers = inputMgr.ToArray();
            VstAudioBuffer[] outputBuffers = outputMgr.ToArray();

            this.ctx.PluginCommandStub.ProcessReplacing(inputBuffers, outputBuffers);

            for (int i = 0;/* i < inputBuffers.Length &&*/ i < outputBuffers.Length; i++)
            {
                for (int j = 0; j < blockSize; j++)
                {
                    if (outputBuffers[i][j] != 0.0)
                    {
                        // IF THIS LINE IS HIT YOU HAVE SOMETHING PLAYING
                        outputBuffers[i][j] = outputBuffers[i][j] * 1000000000;  //(I multiply by this due to the conversion to byte in the playback read function otherwise the data just becomes 0, is there a way to avoid this?)
                        Globals.globuf[j] = outputBuffers[i][j];

                    }
                }
            }
        }

 

The audio output sounds terrible and stuttered. I want to produce a steady held note that i can manipulate by adjusting the plugin parameters.

 

Hope someone can help me out please?

Perm

Apr 10, 2011 at 9:23 PM

Sorry posted this in the wrong forum but might be still relevant on here?