简体   繁体   English

播放文件中的nAudio奇数缓冲区值

[英]nAudio odd buffer values from playing files

The float array buffers I'm getting from nAudio seem really odd, when I replay it sounds perfect but graphing the buffer showed a picture that looked mostly like noise. 我从nAudio获得的float数组缓冲区看起来确实很奇怪,当我重播时听起来很完美,但是绘制缓冲区的图形显示的图像看上去大多像噪声。 It took me a while but I think I've made some headway but I'm a little stuck. 我花了一段时间,但我想我取得了一些进展,但我有些卡住。

The float array that comes out has a block align of 8, so 4 floats per sample (I'm recording at 16bit so one float should easily hold this. However there are 2 and often 3 (for load) floats provided per sample. I ended up graphing it - Charts of Data . The top picture is the closest I can get to reconstructing the wave, the bottom is the wave as recorded and the middle is a chart of the raw data. 出现的float数组的块对齐为8,因此每个样本有4个float(我以16bit进行记录,因此一个float应该很容易容纳它。但是每个样本提供2个(通常是3个)(用于负载)float。最终将其绘制成图表-数据图表 。上图是我最接近重建波形的图,下图是记录的波形,中图是原始数据的图表。

It seems to me that each float is simply holding a byte value but I'm very confused as to the first value which appears to be some kind of scaling factor. 在我看来,每个浮点数都只是持有一个字节值,但对于第一个似乎是某种比例因子的值,我感到非常困惑。

Before I go into to much detail on what I've found I might just leave it at that with the hope Mark will know exactly how/why I am seeing this. 在详细介绍发现的内容之前,我可能会先保留一下,希望Mark能够确切地知道我如何/为什么看到这种情况。

My current best attempt to decode this data is to convert the numbers to bytes then left shift them together which provides the top chart of the attached. 我当前解码此数据的最佳尝试是将数字转换为字节,然后将它们左移在一起,以提供附件的顶部图表。 I'm fairly sure that there is more to it however. 我很确定但是还有更多。

OK so after a bit more tweaking I figured out that the float array was in fact an array of bytes from floats. 好的,所以在进行了一些进一步的调整之后,我发现float数组实际上是float的字节数组。 Not sure if that makes sense, each "float" in the 4 floats per sample was raw bits that made up floats. 不确定是否有意义,每个样本4个浮点中的每个“浮点”都是组成浮点的原始位。

In the end this made it incredibly easy to process the buffer into an array of floats as follows; 最后,这使得将缓冲区处理为如下所示的浮点数组变得异常容易。

    _samplesToProcess = floatsIn.Length / WaveFormat.BlockAlign * WaveFormat.Channels;
    if (_rawFloatsOut.Length < _samplesToProcess)
        _rawFloatsOut = new float[_samplesToProcess];

    Buffer.BlockCopy(floatsIn, 0, _rawFloatsOut, 0, floatsIn.Length);

    BufferProcessor(_rawFloatsOut);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM