请帮助我如何将VSTaudiobuffer转换为PCMStream Buffer 我试过http://vstnet.codeplex.com/Thread/View.aspx?ThreadId=216682,但无济于事。
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();
答案 0 :(得分:1)
问题是输入缓冲区是16位整数,范围为{-32767.0 .. 32767.0}。你需要分割/乘以该值,而不是128,这将是7位。
此外,当您向转换后的值减去/添加1.0f时,您按错误的顺序执行此操作会导致剪切。转换应该是:
buffer[i] = ((float)destBuffer[i]) / 32767.0f;
和
destBuffer[i] = Convert.ToByte(buffer[i] * 32768.0f);