I have the following code:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
int[] values = t.getIntArray();
for (int i = 0; i < values.length; i++)
dos.writeInt(values);
AudioFormat wavFormat = new AudioFormat(8000, 16, 1, true, true);
byte[] abAudioData = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(abAudioData);
AudioInputStream stream = new AudioInputStream(bais, wavFormat, abAudioData.length
/ wavFormat.getFrameSize());
AudioSystem.write(ais, AudioFileFormat.Type.WAVE, new File("mywav.wav"));The problem with this is "clipping" some of the samples created are clipped.
In fact I have limited understanding of sound and WAV, I've been reading about sound in general but I still strugle with basic things.
The whole issue here is the data I am working with, it is raw integers. So my questions are:
How do you convert such data into WAV format? Am i on the right path by what you see above?
How do I deal with clipping?
I tried:
dos.writeInt(values[i]/100);and
dos.writeInt(values[i]/1000);Nothing changed except for the amplitude.
How do compute the correct amplification needed if any?
Can I just take the raw data and copy it in to the audioinputstream, or do I have to work the data before.
I know I have too many questions but I am hoping I get some input to guide me further. Thank you in advance