Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PCM down-sampling from 16-bit to 8-bit

843802Mar 6 2009 — edited Mar 10 2009
Studying the downsampling code posted here:

http://forums.sun.com/thread.jspa?threadID=5339012&start=45

I understand that to convert 16-bit PCM into 8-bit PCM, I only need to discard one byte from each sample. Is this correct? Assuming it is, I wrote the following simple code, but it doesn't work.
// audioData holds 16-bit PCM audio
		int i, j;
		int len = audioData.length;
		for (i=0, j=0; i<len; i+=2, j++){
			audioData[j] = audioData;;
}
// after this, I output only the first half of the byte array
Of course, I adjusted the .wav file header to reflect the change from 16-bit to 8-bit.The resulting file contains loud random noise.

In the process of trying to figure out the problem, I used QuickTime Pro to do the conversion and compared the original 16-bit file against the converted 8-bit file. Here's what I found:

[8-bit.wav: starting with the audio data portion in hex]

80 80 80 80 80 80 80 80 80 80 81 81 81 81 81 81 81 80 7f 7f ...

[16-bit.wav: starting with the audio data portion in hex]

0a-00 e3-ff c9-ff e3-ff c2-ff 02-00 14-00 16-00 3a-00 55-00 8b-00 a3-00 c3-00 ee-00 fe-00 df-00...

The 8-bit data and the 16-bit data don't match up at all as I expected. Did QuickTime Pro do something else? Am I overlooking something obvious???                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2009
Added on Mar 6 2009
7 comments
2,617 views