1

My system has USB DAC capable to play formats 24/96 and 24/192, however when I try to play them using Java I am getting line unavailable exception. Accordingly Java sound documentation, Java doesn't bring any limitations for sample and bits rates, and the limitations are coming for underline sound system. So I traced down where the exception coming from and it looks like native function

 private static native void nGetFormats(int mixerIndex, int deviceID,
                                       boolean isSource, Vector formats);

doesn't fill formats with corresponding line info above 16/48. I looked in sources here.

However to prove that the function really doesn't return format I need or it just returns slight different, I have to see actual formats list. But I can't figure out how reach it. Method of DirectDL is private:

 private AudioFormat[] getHardwareFormats() {
          return hardwareFormats;
 }

So my question has two parts:

  1. How can I still get list of supported formats Java gets from hardware? In this case I could just write own DirectAudioDevice.

  2. Is there any other alternative to standard Java sound to manage higher sample rates from Java? For example, Tritonus, but it seems really old and not supported.

I did my testing on Window, so plan to repeat it on Linux using different than Oracle JRE. However I need to find portable solution anyway.

4

2 回答 2

1

I found some solution so I can listen to 24/96Khz and 24/192Khz recording using Java in FLAC, APE, and Wavpack formats. After some debugging in Java sound I found that for some reason Java runtime limits bits depth to 16bits, however accepts high sample rates as 96Khz and 192KHz. So I borrowed down sampling solution from MediaChest. I also got JustFLAC which provides 24/192 support for FLAC files. Supporting 24/192 directly through hardware seems not possible without updating Java runtime native libraries that I plan to do soon.

Edit: the latest update is: I looked in native Java runtime and found the following:

 static INT32 bitsArray[] = { 8, 16};
 ....
 #define BITS_COUNT sizeof(bitsArray)/sizeof(INT32)
 ....
     for (rateIndex = 0; rateIndex < SAMPLERATE_COUNT; rateIndex++) {
    for (channelIndex = 0; channelIndex < CHANNELS_COUNT; channelIndex++) {
        for (bitIndex = 0; bitIndex < BITS_COUNT; bitIndex++) {
            DAUDIO_AddAudioFormat(creator, bitsArray[bitIndex],

So as you can see 8, and 16 bits are hardcoded and used in supported formats matrix generation. A fix seems to be easy just by adding two more constants, however it leads in creation own copy of Java runtime and it isn't acceptable. So it looks like I need to initiate some community process to make my recommendations accepted by and then included in next Java runtime updates.

Edit: One more update. Linux sound native implementation seems better. It has only limitation 24bits sample size. So if underline sound system (ALSA) allows the sample depth, then Java can play 24 bits/ 192,000 format. I tested it on Raspberry Pi using latest Raspbian and JDK 8 EA. Unfortunately even latest Arch and Pidora do not have the ALSA improvement.

于 2013-06-11T07:08:48.413 回答
0

对于读取和写入私有字段中的值,您可以使用反射。Java 教程和StackOverflow 中的一个问题

关于您的第二个问题,我发现了一个名为jd3lib的库,它似乎是最近的。

于 2013-06-04T18:32:27.087 回答