LWJGL Forum

Programming => OpenAL => Topic started by: sashok724 on July 20, 2013, 21:37:29

Title: WaveData.create(AudioInputStream) not works correctly
Post by: sashok724 on July 20, 2013, 21:37:29
Try get WaveData with AudioInputStream. There no errors, but noise instead of music.
This code works fine (replace audio format with what you need, i use custom WAV encoder):
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, source.getFrequrency(), 16, source.getChannels(), source.getChannels() * 2, source.getFrequrency(), true);
SourceDataLine line = AudioSystem.getSourceDataLine(format);
line.open(format);
line.start();
line.write(source.getByteArray(), 0, source.getByteArray().length);

But when i replaced loading code from OpenAL Example 1 to my:
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, source.getFrequrency(), 16, source.getChannels(), source.getChannels() * 2, source.getFrequrency(), true);
AudioInputStream input = new AudioInputStream(new ByteArrayInputStream(source.getByteArray()), format, source.getByteArray().length);
WaveData data = WaveData.create(input);
AL10.alBufferData(buffer.get(0), data.format, data.data, data.samplerate);

There no errors, but noise instead of music. Please help me  :-[
EDIT: Proof that AudioInputStream created correcly, this code also works fine:
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, source.getFrequrency(), 16, source.getChannels(), source.getChannels() * 2, source.getFrequrency(), true);
AudioInputStream input = new AudioInputStream(new ByteArrayInputStream(source.getByteArray()), format, source.getByteArray().length);
try
{
SourceDataLine line = AudioSystem.getSourceDataLine(format);
line.open(format);
line.start();
byte[] buffer = new byte[65535];
for(int length = input.read(buffer); length != -1; length = input.read(buffer))
{
line.write(buffer, 0, length);
}
} catch(LineUnavailableException e)
{
e.printStackTrace();
}

EDIT2: I reproduced same noise on JavaSound when changed AudioFormat bigendian to false:
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, source.getFrequrency(), 16, source.getChannels(), source.getChannels() * 2, source.getFrequrency(), false);
Title: Re: WaveData.create(AudioInputStream) not works correctly
Post by: sashok724 on July 20, 2013, 22:23:19
https://github.com/LWJGL/lwjgl/pull/47
Fixed!