naudio waveProvider.AddSamples 导致崩溃
private unsafe static void AudioStreamCallback(IntPtr buff, Int32 size)
{
byte[] samples = new byte[size];
Marshal.Copy(buff, samples, 0, size);
waveProvider.AddSamples(samples, 0, size);
bytes_played += size;
}
在上面的代码中,buff
是从用C
编写的本机dll返回的。对于日志记录,我已经打印了添加到示例中的字节数。根据此日志,我在播放大约 2.4 Mb 样本后收到下面提到的错误。
未处理的异常:System.InvalidOperationException:NAudio.Wave.BufferedWaveProvider.AddSamples 处的缓冲区已满(Byte[] 缓冲区,Int32 偏移量,Int32 计数)
我是否需要释放一些缓冲区或确保在添加新样本之前刷新旧条目?我查看了源代码,但没有找到任何与缓冲区大小相关的内容。我是不是错过了什么?
感谢您的帮助。
private unsafe static void AudioStreamCallback(IntPtr buff, Int32 size)
{
byte[] samples = new byte[size];
Marshal.Copy(buff, samples, 0, size);
waveProvider.AddSamples(samples, 0, size);
bytes_played += size;
}
In the above code, buff
is returned from a native dll written in C
. For logging, I have printed the number of bytes added to sample. Based on this log, I am getting the below mentioned error after playing about 2.4 Mb samples.
Unhandled Exception: System.InvalidOperationException: Buffer full at NAudio.Wave.BufferedWaveProvider.AddSamples(Byte[] buffer, Int32 offset, Int32 count)
Do I need to free some buffer or make sure to flush the old entries before adding new samples? I looked at the source code, but didn't find anything related to buffer size. Am I missing some thing.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BufferedWaveProvider
由固定大小的循环缓冲区支持。一旦满了,它就会抛出异常(较新版本的 NAudio 允许您配置是否抛出异常或是否默默地丢弃音频)。最新代码还允许您在首次调用AddSamples
之前设置BufferDuration
,以增加默认的 5 秒音频缓冲区大小。BufferedWaveProvider
is backed by a fixed size circular buffer. Once it is full it throws an exception (newer versions of NAudio allow you to configure whether an exception is thrown or whether audio is silently discarded). The latest code also allows you to setBufferDuration
before your first call toAddSamples
to increase the buffer size from the default of 5 seconds worth of audio.