VST.NET 与 NAUDIO(vstaudiobuffer 与 pcmstream 缓冲区)

发布于 2024-09-06 15:53:05 字数 2025 浏览 4 评论 0原文

请帮助我如何将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潦草背影 2024-09-13 15:53:05

问题是您的输入缓冲区是 16 位整数,其范围为 { -32767.0 .. 32767.0 }。您需要除/乘该值,而不是 7 位的 128。

另外,当您在转换后的值中减去/加上 1.0f 时,您的操作顺序是错误的,并且会导致发生削波。转换应该是:

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

并且

destBuffer[i] = Convert.ToByte(buffer[i] * 32768.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:

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

And

destBuffer[i] = Convert.ToByte(buffer[i] * 32768.0f);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文