JavaSound error when playing exported WAV file from http://www.bfxr.net/

http://www.bfxr.net/ lets you generate sound effects and then save them as a Wav file.
However, I keep getting a Java exception “UnsupportedAudioFileException” when trying to play them as clips. Audacity can play them ok. I can play other Wav files fine in JavaSound, just not the ones from bfxr.

Is it because Wav is actually just a container and the actual audio data is something JavaSound doesn’t understand? How could I find out what it is?

Hello,

What I would do, is try to convert the sound file twice the first time to, as example, mp3 and the second time back to wav. I think that could solve the problem.

biro

A bit of a long shot, but maybe your WAV files are generated with big-endian byte order. JavaSound doesn’t support that. You might want to look in bfxr for little-endian WAV generation.

I think Riven is probably right. There are lots of .wav variants, including things like 16-bit vs 32-bit, as well as the little vs big endian issue.

I just ran a program through the Eclipse debugger, based upon the info in the tutorial, inspecting the supported formats of a LineInfo object, and see 8 variants:

BigEndian = false, PCM_UNSIGNED, channels = 1, bits = 8
BigEndian = false, PCM_SIGNED, channels = 1, bits = 8
BigEndian = false, PCM_SIGNED, channels = 1, bits = 16
BigEndian = true, PCM_SIGNED, channels = 1, bits = 16
BigEndian = false, PCM_UNSIGNED, channels = 2, bits = 8
BigEndian = false, PCM_SIGNED, channels = 2, bits = 8
BigEndian = false, PCM_SIGNED, channels = 2, bits = 16
BigEndian = true, PCM_SIGNED, channels = 2, bits = 16

I haven’t run this through all my AudioSystem “Mixers” though, but I’m guessing this list is standard for what is supported.

Perhaps the following will help to inspect the format of the wav file you are trying to play?

			InputStream inStream = 
				PlayASourceDataLine.class.getResourceAsStream("MySound.wav");
			AudioInputStream aiStream = 
				AudioSystem.getAudioInputStream(inStream);
			AudioFormat audioFmt = aiStream.getFormat();
			DataLine.Info info = new DataLine.Info(SourceDataLine.class, 
					audioFmt);
			System.out.println(info);

@20thCenturyBoy

I have a similar problem, can’t reproduce exported WAVs from bfxr using libGDX.

As a workaround, I am opening them with Audacity and exporting them in OGG format to be used in my games.

I just checked out bfxr and generated a wav.

If you right click on the wav you save, and inspect the properties, (assuming Windows, I’m not sure how this is done on a Mac or Linux), the “Summary” tab of properties displays: “Bit rate” “Channels” “Audio sample size” “Audio sample rate”.

On my wav, the “Audio sample size” is 32-bits. I think Java only supports a max of 16-bits. (See the posting I have a couple before this one.) So, that would account for an “Unsupported format” error.

I haven’t fully explored the file & format converters in this tutorial: http://download.oracle.com/javase/tutorial/sound/converters.html (see the section “Converting Audio between Different Data Formats”) so the “easy” way they have of doing the conversion may or may not be supported. I don’t know.

But, I know it is possible to iterate through the data and convert it yourself. For example, I think it should be possible to convert the four bytes to a long, and then make the long a short int and convert that back to bytes. Or maybe the four bytes need to become a float between 0.0 and 1.0 and then converted back to 16 bit resolution. I think I can help with the coding of this if you run into any snags.

But it might be simpler to load the sound into a utility (I would import to my Sonar audio tool) and then export it as a 16-bit wav. Some of the other previous suggestions might accomplish this.