final byte[] rawBytes = currentAudioBuffer.getSamplesAsByteBuffer().array();
ByteArrayInputStream bais = new ByteArrayInputStream(rawBytes);
//audioFormatXa is taken from the JavaSoundAudioGrabber instance earlier not shown above.
long length = (long)(rawBytes.length / audioFormatXa.getFrameSize());
AudioInputStream audioInputStreamTemp = new AudioInputStream(bais,audioFormatXa,length);
AudioSystem.write(
audioInputStreamTemp
,AudioFileFormat.Type.WAVE
,new File("testfile.wav"));
However, I just get noise in the file ? any pointers would be usefull
Thanks in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Whenever that happened to me it was usually a big-endian/little-endian problem. You're capturing 16bit samples and writing them as 8 bit value so you need to make sure the bytes are in the right order. The format should do that for you, but maybe there's a problem there? Perhaps check that the byte array contains the expected values before you write it and that the wave file contains those values in its data block?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2015-10-19
Post awaiting moderation.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Hi
I am trying to write audio to file using the JavaSoundAudioGrabber. However, not being very sucessfull. I have the following code:
final JavaSoundAudioGrabber xa = new JavaSoundAudioGrabber(new AudioFormat(16, 44.1, 1));
xa.setMaxBufferSize(this.sampleChunkSize);
I then write the currentAudioBuffer later using :
However, I just get noise in the file ? any pointers would be usefull
Thanks in advance
Whenever that happened to me it was usually a big-endian/little-endian problem. You're capturing 16bit samples and writing them as 8 bit value so you need to make sure the bytes are in the right order. The format should do that for you, but maybe there's a problem there? Perhaps check that the byte array contains the expected values before you write it and that the wave file contains those values in its data block?