将 32 位波形转换为 16 位波形

发布于 2024-09-25 12:56:24 字数 667 浏览 5 评论 0原文

我一直在使用环回捕获模式捕获音频。捕获的波形是 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 技术交流群。

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

发布评论

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

评论(3

静赏你的温柔 2024-10-02 12:56:24

格式 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.

鱼窥荷 2024-10-02 12:56:24

Sox 可以为您转换此值。

http://sox.sourceforge.net/

合适的命令行:

<块引用>

http://sox.sourceforge.net/Docs/FAQ

sox 任意文件 -b 16 输出文件率 -I
22050 抖动 -s

NB 重采样和抖动
需要一些净空。如果 SoX 报告
期间发生任何剪裁
处理然后转换应该
重做一些衰减,例如

sox 任意文件 -b 16 输出文件增益 -1
速率 44100 抖动 -s

Sox can convert this for you.

http://sox.sourceforge.net/

Suitable commandlines:

http://sox.sourceforge.net/Docs/FAQ

sox any-file -b 16 outfile rate -I
22050 dither -s

N.B. Both resampling and dithering
require some headroom. If SoX reports
that any clipping has occurred during
processing then the conversion should
be redone with some attenuation, e.g.

sox any-file -b 16 outfile gain -1
rate 44100 dither -s

裂开嘴轻声笑有多痛 2024-10-02 12:56:24

如果您的 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.

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