Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

16bit WAVE value range

I have come across this MSDN link: Intro to Audio Programming, Part 2: Demystifying the WAV Format. The post says that:

16-bit samples range from -32760 to 32760

which is not +/-(2^16)/2 because of

some crazy business involving Endianness and 2’s complement

There are multiple mistakes in this post, but this part irritated me the most. How much of that is true if anything?

like image 903
user1146657 Avatar asked Oct 17 '25 23:10

user1146657


2 Answers

The post is wrong in this regard. First, endianness has absolutely nothing to do with anything at all. But there is an issue with 2s complement which is that there are more negative values than positive values. Often times when performing signal processing the values will be converted to double precision in the range of -1.0 to 1.0 only to later to convert to the desired output bit resolution. If you were to multiply by 32768 and convert to an integer then you'd obviously get an overflow on the positive 1.0. So it is best to multiply by 32767. I don't know if this is formalized in any way but in my experience that is just the way it is. And if you follow this assumption you run a small risk of encountering a wave file with a value of -32768 in it and you'll get a number slightly less than -1.0 when converting to float.

like image 157
jaket Avatar answered Oct 19 '25 22:10

jaket


I don't know if this is formalized in any way.

Yes! It is! Both what appears to be official RIFF spec and Broadcast WAVE format spec (which is supposed to be consumable by WAVE compliant applications) assert a pretty clear 16-bit sample range of -32768 to 32767 as jaket posited.

I've found I often need to take MSDN articles with a grain of salt, but they're sometimes hard to ignore since they're presented authoritatively. Searching the 'net for "wav 32760" will uncover some of the damage this article has done.

like image 31
Kaganar Avatar answered Oct 19 '25 23:10

Kaganar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!