VST.NET 与 NAUDIO(vstaudiobuffer 与 pcmstream 缓冲区)
请帮助我如何将 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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您的输入缓冲区是 16 位整数,其范围为 { -32767.0 .. 32767.0 }。您需要除/乘该值,而不是 7 位的 128。
另外,当您在转换后的值中减去/加上 1.0f 时,您的操作顺序是错误的,并且会导致发生削波。转换应该是:
并且
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:
And