tags:

views:

25

answers:

1

please help me how to convert VSTaudiobuffer to PCMStream Buffer i tried from http://vstnet.codeplex.com/Thread/View.aspx?ThreadId=216682 but to no avail.

                int inputCount = PluginContext.PluginInfo.AudioInputCount;
                int outputCount = PluginContext.PluginInfo.AudioOutputCount;
                int blockSize = bytesWritten;                    

                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] = (float)destBuffer[i] / 128.0f - 1.0f;
                    }
                }

                PluginContext.PluginCommandStub.SetBlockSize(blockSize);
                PluginContext.PluginCommandStub.SetSampleRate(44.8f);

                PluginContext.PluginCommandStub.StartProcess();
                PluginContext.PluginCommandStub.ProcessReplacing(inputMgr.ToArray(), outputMgr.ToArray());
                PluginContext.PluginCommandStub.StopProcess();                   

                foreach (VstAudioBuffer buffer in outputMgr.ToArray())
                {
                    for (int i = 0; i < blockSize; i++)
                    {
                        destBuffer[i] = Convert.ToByte(((float)buffer[i] + 1.0f) * 128.0f);                           
                    }                        
                }
                inputMgr.ClearBuffer(inputMgr.ToArray()[0]);
                inputMgr.ClearBuffer(inputMgr.ToArray()[1]);
                inputMgr.Dispose();
                outputMgr.ClearBuffer(outputMgr.ToArray()[0]);
                outputMgr.ClearBuffer(outputMgr.ToArray()[1]);
                outputMgr.Dispose();
A: 

The problem is that your input buffers are 16-bit integers, which are in the range of { -32767.0 .. 32767.0 }. You need to be dividing/multiplying by that value, not 128, which would be for 7 bits.

Also, when you are subtracting/adding 1.0f to your converted value, you are doing it in the wrong order and will cause clipping to occur. The conversion should be:

buffer[i] = ((float)destBuffer[i]) / 32767.0f;

And

destBuffer[i] = Convert.ToByte(buffer[i] * 32768.0f);
Nik Reiman