2 byte integer / .wav data - sample value conversion
Posted on 2003-03-10
I'm trying to simply display a wave file graphically ...
I'm stuck in reading the bytes and convert it to a sample value :
ie. for 16bit PCM , I have to convert 2 bytes to a value ranging from -32768 to 32767
so , I have the 2 byte values , ranging from 0 to 255 which represent the 65536-step value , but I dont know how to convert them ,
I guess i could just multiply them, so I have 256 * 256 (=65536) possible values ,
but that must be not correct , cause I have values like (0 and 9) or (0 and 200) which is multiplied =>> 0 * 9 = 0 ???
My guesss is that I have to read as a byte ranging from 0x7FFF(=32767) to 0x8000(-32768),
a 2 byte integer ... but
how do you do that ??
how do you read 2 byte integers ??