tags:

views:

267

answers:

2

How can I merge two wav files using java?

I tried this but it didn't work correctly, is their any other way to do it?

+2  A: 

Merge implies mixing, but it sounds like you mean concatenation here.

To concatenate with silence in the middle you need to insert a number of frames of silence into the file. A silent frame is one where every channel has a "0" - if you are using signed samples this is literally a 0, for unsigned, it is maxvalue/2.

Each frame will have one sample for each channel. So to generate one second of silence in CD format, you would insert 44100 (hz) * 2 (channels per frame) = 88200 16 bit signed ints with a value of 0 each. I am not sure how to access the raw file abstracted by the Java audio abstractions, but that is the data to insert.

Justin Smith