Concatenating wavs with Java

B

Big D

Hey there. I'd like to concatenate multiple wav files together. I've
got an almost completely working system for it, actually... I'm using
AudioSystem.write and my own subclass of AudioInputStream to do it.

Basically, my AudioInputStream contains a List of AudioInputStreams that
came from the wav files I want to concatenate, and
for each stream added, I add its frameLength to my subclass's framelength
so it reports as being the
right length. All my source wav files are the same type, so that is a safe
assumption to make.

Then when it comes time to read, my AudioInputStream just overrides the
read methods and calls read on each subsequent stream in its List.

It all works pretty well. When I open the resulting output in Audacity, it
plays perfectly. However, when I open it with Windows Media Player, it
reports an error mid-way through and then stops playing 2 seconds from the
end of the file.

When I export the file I created from Audacity as a wav, it creates a wav
of exactly the same number of bytes, however when I compare my output and
Audacity's output in a hex editor, I see that some of the bytes are
different throughout the files.

Can anyone tell me what I'm doing wrong / how to get the wavs I create to
work in media player?

I considered that maybe I'm getting the headers repeatedly in there, but
I've discounted that possibility because I can successfully concatenate my
test wavs 20+ times with repetitions and it plays fine every time until 2
seconds before the end. If I'd gotten headers in there, I'd expect them to
make popping sounds or screw things up earlier.

Thanks for any advice!
 
B

Big D

I hadn't found that - thanks!

Unfortunately, this code seems to be doing exactly what I'm doing. There
are a couple minor differences, though (like, I get the audio format from
the first source file instead of hard coding it, and I aggregate the
framelengths in my subclass rather than calculating each time). I'll give
it another look-over next to my code and see if there are any other
differences. I'll also probably compile that and see if it has the same
problem as mine - maybe whoever wrote it never tested with WMP. :)

Thanks!


(e-mail address removed) wrote in
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top