Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if 8bit WAV File is signed or unsigned, using Java and without javax.sound

I need to know whether a ".wav" of 8bits, is signed or unsigned PCM, by only reading file. I cannot use "javax.sound.sampled.*" or AudioSystem libraries.

like image 512
joseluisbz Avatar asked May 24 '12 04:05

joseluisbz


2 Answers

In the wav File, 8-bit samples are stored as unsigned bytes, ranging from 0 to 255. The 16-bit samples are stored as signed integers in 2's-complement.

like image 113
joseluisbz Avatar answered Nov 15 '22 01:11

joseluisbz


8 bit (or lower) WAV files are always unsigned. 9 bit or higher are always signed:

Each sample is contained in an integer i. The size of i is the smallest number of bytes required to contain the specified sample size. The least significant byte is stored first. The bits that represent the sample amplitude are stored in the most significant bits of i, and the remaining bits are set to zero.

For example, if the sample size (recorded in nBitsPerSample) is 12 bits, then each sample is stored in a two-byte integer. The least significant four bits of the first (least significant) byte is set to zero.

The data format and maximum and minimums values for PCM waveform samples of various sizes are as follows:

enter image description here

Multimedia Programming Interface and Data Specifications 1.0 - IBM/Microsoft, August 1991

like image 26
endolith Avatar answered Nov 14 '22 23:11

endolith