1

I use the following code to append as many wav files present in the sdcard to a single file. audFullPath is an arraylist containing the path of the audiofiles. Is it correct. When I play the recordedaudio1, after doing this. It play only the first file. I want to play all the files. Any suggestion..

File file=new File("/sdcard/AudioRecorder/recordedaudio1.wav");

RandomAccessFile raf = new RandomAccessFile(file, "rw");

for(int i=0;i<audFullPath.size();i++) {
    f=new File(audFullPath.get(i));      
    fileContent = new byte[(int)f.length()];
    System.out.println("Filecontent"+fileContent);
    raf.seek(raf.length()); 
    raf.writeBytes(audFullPath.get(i));
}
Andrii Turkovskyi
  • 27,554
  • 16
  • 95
  • 105
Manikandan
  • 1,479
  • 6
  • 48
  • 89

1 Answers1

4

You can't append WAV files the way you do. That's because each WAV has special format:

The simplest possible WAV file looks like this:

[RIFF HEADER]
...
totalFileSize    

[FMT CHUNK]
...
audioFormat
frequency
bytesPerSample
numberOfChannels
...

[DATA CHUNK]
dataSize
<audio data>

What you need to do is:

  1. Make sure that all WAV files are of compatible: same audioFormat, frequency, bits per sample, number of channels, etc.
  2. Create proper RIFF header with total file size
  3. Create proper FMT header
  4. Create proper DATA header with total audio data size

This algorithm will definitely work for LPCM, ULAW, ALAW audio formats. Not sure about others.

inazaruk
  • 74,247
  • 24
  • 188
  • 156
  • It will work for PCM. The WAV file format is described here: http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/wave.html; And also here: http://www.sonicspot.com/guide/wavefiles.html. – inazaruk May 31 '11 at 08:47