Hello Guest

WaveData.create(AudioInputStream) not works correctly

  • 1 Replies
  • 9093 Views
WaveData.create(AudioInputStream) not works correctly
« 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):
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, source.getFrequrency(), 16, source.getChannels(), source.getChannels() * 2, source.getFrequrency(), false);
« Last Edit: July 20, 2013, 22:05:32 by sashok724 »