6

When the following method is executed:

private void beep_player_1() {
    try {
        //clip_Player_2.close();
        clip_Player_1 = AudioSystem.getClip();
        ais = AudioSystem.getAudioInputStream(new File(Constants.Player1_Default_Tone)); // PATH FOR THE .WAV FILE
        clip_Player_1.open(ais);
        clip_Player_1.loop(0); // PLAY ONCE
    }catch(Exception exc) {
        System.out.println(exc);
     }
}

LineUnavailableException get thrown. What could be the reason for this?

javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 24 bit, stereo, 6 bytes/frame, little-endian not supported.
Jeff Holt
  • 2,940
  • 3
  • 22
  • 29
saplingPro
  • 20,769
  • 53
  • 137
  • 195

2 Answers2

3

What could be the reason for this ?

javax.sound.sampled.LineUnavailableException: line with format 
  PCM_SIGNED 44100.0 Hz, 
  24 bit, 
  stereo, 
  6 bytes/frame, 
  little-endian not supported.

I don't know about the rest, but most PCs I've encountered use 8 or 16 bit 'bit depth' while that uses 24 bits. It indicates a very finely nuanced recording quality. If 8 bit is 'phone quality' and 16 bit is 'CD quality', then 24 bit would be 'master recording quality'.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    You know if I change the sound clip,it works ! But I do not understand this. – saplingPro Apr 07 '13 at 01:54
  • The previous file has a bit rate of `2116kbps` and the new file has a bit rate of `1411kbps`. Does it make any difference ? – saplingPro Apr 07 '13 at 01:59
  • *"if I change the sound clip,it works"* Print the format (use [`AudioInputStream.getFormat()`](http://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/AudioInputStream.html#getFormat%28%29)) of the working (changed) sound-clip. – Andrew Thompson Apr 07 '13 at 02:04
  • 1
    `PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian` : format for the working one – saplingPro Apr 07 '13 at 02:10
  • So, why doesn't it play the 24 bit format ? Though I converted the that file to 16 bit from 24 – saplingPro Apr 07 '13 at 03:41
  • 1
    It's just the way things are. PCs are set up to handle 16 bit sound typically, so Java Sound provides no support for 24 bit, only 8 and 16 bit. – Andrew Thompson Apr 07 '13 at 07:52
  • okay ! Thanks. I didn't know about this. But seeing the growing popularity of 24 bit encoding, I hope it starts supporting soon :) – saplingPro Apr 08 '13 at 15:57
  • 1
    If someone is still interested in this: There are plenty of online wav-converters from x-Bit to 16-Bit .wav-files – Moritz Schmidt Mar 23 '20 at 13:48
0

This is a known issue, but it is on Windows only. Java does not recognize the ability of sound devices on Windows to play 24 bit data (or record 24 bit data). Java handles 24-bit on Linux and Mac well. I have seen other threads here and in other places on this, some started in 2012.

Not many people are pointing this issue out. I have only seen a couple of threads here and one on Oracle re this. I have not seen a workaround (other than convert sound data to 16 bit) and I have not seen any efforts to fix it.