是否可以设置 NAudio 读取请求的样本数?

发布于 2024-09-15 05:35:21 字数 570 浏览 3 评论 0原文

我正在使用 naudio 生成脉宽调制音频信号来控制一对伺服系统。目前我正在使用 Mark Heath 编写的 WaveProvider32 类(http://mark-dot-net.blogspot.com/2009/10/playback-of-sine-wave-in-naudio.html),它实现了 IWaveProvider 接口。采样率为 44100

音频信号基本上是一个 N 宽的块,其中信号的第一部分的所有值都很高,而块的其余部分的值都很低。由于读取操作需要比块宽度更多的样本,因此我只需重复信号,直到填满缓冲区。我遇到的问题是缓冲区的长度不是信号块宽度的倍数,因此最后一个块的一部分被切断,这与伺服器拧紧并使其抽搐。我意识到我可以做一些花哨的代码来跟踪它并偏移下一次读取的开始,但是如果我可以设置 WaveProvider 必须立即提供的值的数量,以便我可以将其设置为多个值,我会更容易信号块大小(或者可能是确切的宽度)。

这可能吗?

I am using naudio to generate pulse width modulated audio signals for controlling a pair of servo's. Currently I am using the WaveProvider32 class that Mark Heath wrote (http://mark-dot-net.blogspot.com/2009/10/playback-of-sine-wave-in-naudio.html) which implements the IWaveProvider interface. The sample rate is 44100

The audio signal is basically a block N wide where the first part of the signal all the values are high, and for the remainder of the block the values are low. Since the Read operation asks for more samples than the width of the block I just repeat the signal until I fill up the buffer. The problem I have is that the length of the buffer is not a multiple of the width of my signal block, so part of the last block is cut off which screws with the servo and makes it twitch. I realize I could do some code fanciness to keep track of it and offset the beginning of the next read, but I would be easier if I could set the number of values that WaveProvider had to provide at once so that I could make it a multiple (or maybe the exact width) of the signal block size.

Is that possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

仅一夜美梦 2024-09-22 05:35:21

Read 函数请求的数据量取决于您选择的 IWaveOut 实现以及它运行时的延迟和缓冲区数量。您需要创建一个中间 IWaveProvider,以确保底层提供程序的 Read 方法始终请求正确的数字。看看我为类似问题创建的 BlockAlignReductionStream

The amount of data requested by the Read function is determined by the IWaveOut implementation you choose, and the latency and number of buffers it is operating at. You would need to create an intermediate IWaveProvider that ensures that Read methods to the underlying provider always ask for the right number. Have a look at the BlockAlignReductionStream which I created for a similar issue.

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