将 32 位波形转换为 16 位波形
我一直在使用环回捕获模式捕获音频。捕获的波形是 32 位波形。我正在努力将其转换为 16 位波形,以便像 lame 这样的编码器可以处理它(它说不支持的数据格式:0x0003)。
我尝试过将波流本身的位(不是我的强项)从 32 位转换为 16 位,但结果听起来仍然失真。
Wave32To16Stream 类似乎在这种情况下爆炸了: if (sourceStream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat) throw new ApplicationException("仅支持 32 位浮点");
理想情况下,我只想直接捕获 16 位,有没有办法设置捕获位深度?如果没有,有人可以帮我转换波流吗?
可以在此处找到捕获波形的示例:http://dl.dropbox.com/ u/454409/test.wav (10mb)
我也会采用某种方式用 lame 将其编码为 mp3,我已经尝试了我能想到的所有参数排列,以使其接受波形文件。有趣的是 Audacity(使用 lame_enc 来编码 mp3)能够从波形创建 mp3(但也许 Audacity 在将其传递给 lame 之前会自动将其转换为 16 位)。
I've been capturing audio using the loopback capture mode. The captured waveform is a 32 bit waveform. I'm struggling with converting this to a 16 bit waveform so encoders like lame can deal with it (it says Unsupported data format: 0x0003).
I've tried shifting the bits (not my strong point) in the wave stream itself from 32 bit to 16 bit but the result still sounds distorted.
The Wave32To16Stream class seems to blow up on this case:
if (sourceStream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat) throw new ApplicationException("Only 32 bit Floating point supported");
Ideally I would want to just capture straight to 16 bit, is there no way to set the capture bit depth? If not, could somebody help me with converting the wavestream?
An example of a captured waveform can be found here: http://dl.dropbox.com/u/454409/test.wav (10mb)
I would also settle for some way to encode this to mp3 with lame, I've tried every parameter permutation I can think of to get it to accept the wave file. What's interesting is Audacity (which uses lame_enc to encode mp3s) was able to create an mp3 from the waveform (but maybe Audacity automatically converts it to 16bit before passing it to lame).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
格式 0x0003 实际上是 ieeeFloat,你不应该得到这个异常。最好检查它读取的值。您无法通过位移位来转换值,必须从浮点转换为短整型。一个简单的演员就可以完成工作。
Format 0x0003 is in fact ieeeFloat, you shouldn't get this exception. Better check the value it read. You cannot convert the values with bit shifting, you have to convert from float to short. A simple cast gets the job done.
Sox 可以为您转换此值。
http://sox.sourceforge.net/
合适的命令行:
Sox can convert this for you.
http://sox.sourceforge.net/
Suitable commandlines:
如果您的 32 位格式是浮点型,则样本值的范围很可能是 -1 到 1。要转换为 16 位(整数),您需要乘以 32767 并转换为 INT16。
如果 32 位浮点范围大于 -1..1,则您需要找到最小值和最大值并计算比例因子,以获得 INT16 范围内的样本。
您可能需要添加一些抖动。
If your 32-bit format is float, then most likely the sample values range from -1 to 1. To convert to 16-bit (integers) you would need to multiply by 32767 and cast to INT16.
If the 32-bit float range is larger than -1..1 then you need to find the minimum and maximum values and calculate a scale factor that gets the samples within the INT16 range.
You may need to add some dither.