Converting a 32 bit wave form to a 16 bit wave form

心已入冬 提交于 2019-12-04 17:08:00

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 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

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!