Hello there,
I am trying to combine at least 2 WAV files (my example uses 3) into a single file. I have tried several examples (
http://www.jsresources.org/examples/AudioConcat.html and
http://stackoverflow.com/questions/653861/join-two-wav-files-from-java) but both have the same problem: the output file is an exact copy of the last file to have been joined.
Here is the code for the simpler of the 2 examples which I have altered to meet my needs.
File outputFile = new File("concat.wav");
for (int i = 0; i < files.length - 1; i++) {
try {
AudioInputStream clip1 = AudioSystem.getAudioInputStream(files);
AudioInputStream clip2 = AudioSystem.getAudioInputStream(files[i + 1]);
AudioInputStream appendedFiles =
new AudioInputStream(
new SequenceInputStream(clip1, clip2),
clip1.getFormat(),
clip1.getFrameLength() + clip2.getFrameLength());
AudioSystem.write(appendedFiles,
AudioFileFormat.Type.WAVE,
outputFile);
files[i + 1] = outputFile;//first file read in next loop, will contain joined file so far
} catch (Exception e) {
e.printStackTrace();
}
}
return outputFile;
I am unsure as where the problem lies, so would be grateful for anyone to point out the (no doubt obvious) mistake i've made :p