I'm using Java Sound to play audio files (in standard PCM format) but I've noticed that it does not correctly play 24 bit data, in that the data output from the soundcard does not match the input from the file. It works fine for 16 bit (and even 8 bit) audio data, but not for 24 bit (and presumably 32 bit, but I have no real 32 bit audio files to test) files. From the output it appears that Java Sound is doing some extra (and unwanted) processing to the audio data before passing it to the soundcard. I can say for certain that it is Java Sound doing this because if I run the same test using ASIO to play the file then there is no problem and the data matches as expected.
A bit more information on the setup:
- Java JRE latest version (7u7 I think), running on Windows XP SP3.
- Sound played using AudioPlayer example on jsresources.org (I firstly tried using my own code, but switched to this in case I had made a mistake, the results are the same on both).
- The audio is played is on an M-Audio soundcard via the digital (S/PDIF) out, which is directly connected (via an external cable) to a digital in on a Lynx soundcard (in the same PC), where it is recorded (using Sony Sound Forge).
- The recorded file is then compared with the input Wave file.
For the test, four different input Wave files are used (generated from the same source file):
- 16 bit, 44.1 kHz
- 16 bit, 48 kHz
- 24 bit, 44.1 kHz
- 24 bit, 48 kHz
Using ASIO to play back the test files, all four of the files produced the correct output (the recorded data matches the input Wave file data byte for byte, after shifting to align the starting positions).
Using Java to play back the test files, the 16 bit ones (both the 44.1 kHz and 48 kHz) produce the correct output, whereas the 24 bit ones (both the 44.1 kHz and 48 kHz) do not. Not only that, but the way in which the output is incorrect is inconsistent (if I run the test two times, it produces a different output each time, neither of which comes close to matching the input file). So not only is Java sound playing the 24 bit files wrongly, it is doing so wrongly in a different way each time. If it will help I can take screenshots of the Java sound output compared to the input file (expected output).
The easiest way to reproduce this would be to use the AudioPlayer example I linked to above, play a 24 bit file and record the output (if you only have one soundcard it might be possible to use its mixer to route the data appropriately to allow it to be captured). While it's not wrong enough that I can hear any difference, it does kind of defeat the purpose of hi-resolution audio if the data is being altered in some unexpected way (you risk losing any gains from using 24 bit over 16 bit, though I don't really want to get into that argument here).
So to phrase this as a question - how can I get Java Sound to play back 24 bit audio correctly?
Thanks in advance for any help,
This post has been edited by macosxnerd101: 27 September 2012 - 02:05 PM
Reason for edit:: Added [Resolved] to title