Help - Search - Members - Calendar
Full Version: Merging two .wav-files (both in same format)
Hydrogenaudio Forums > Hydrogenaudio Forum > General Audio
NBG
Hello,

i just would like to merge 2 .wav-files into one (not mix, merge!).

The got the same settings (KHz, Bit, ...).

Example:

1.wav (100.000 bytes)
2.wav (200.000 bytes)

I load in this 2 files and remove the first 44 bytes (wav-header)
from the 2.wav and append it to 1.wav. Then i write the new
size of the file into the first wav-header (Byte 4). In this case i would
be 299.964 bytes (300.000 bytes - 44 bytes (header of 2.wav) - 8 bytes).

Problem: The new .wav-file only plays the first part (1.wav) and not
the second part after that...

Must i change some things in the subchunks or remove other
tags in the end of both wav-files?
AndyH-ha
This is easy to accomplish a number of ways in an audio editor. If you are trying to say you want to write your own program, I guess that fact is no help unless you can get access to existing code.
In CoolEdit/Audition the three simplest ways are:

Open first file in single waveform view.
Open Append second file.
Save As a new file.

Open first file in single waveform view.
Place cursor at very end.
Open second file. This will be in a new window.
Copy second file.
Switch to first file's window
Paste second file.
Save As a new file.

Insert both files into multi-track view (as separate tracks).
Adjust track 2's start position to where you want it after the end of track 1.
Select All.
Mixdown.
Save new file.
NBG
Yep this solution is okay for 3-4 files, but if you have to merge ~50 files then it's really work :-)

So i need a own tool... merging works, but some little thing might be wrong...
cliveb
QUOTE (NBG @ Jul 16 2006, 18:38) *
I load in this 2 files and remove the first 44 bytes (wav-header)
from the 2.wav and append it to 1.wav. Then i write the new
size of the file into the first wav-header (Byte 4). In this case i would
be 299.964 bytes (300.000 bytes - 44 bytes (header of 2.wav) - 8 bytes).

Problem: The new .wav-file only plays the first part (1.wav) and not
the second part after that...

Must i change some things in the subchunks or remove other
tags in the end of both wav-files?

As Andy says, this is easy to do with an audio editor. But if you want to write code to do it, then here's what you need to do:

1. Stripping off the first 44 bytes of file 2 is only correct if you know that there are no additional chunks before the data chunk.

2. The number to be written into bytes 4-7 of the new file (where the first byte is byte 0) is the number of bytes in the file minus 8. The file size field here *excludes* the RIFF header and the file size field itself.

3. You must also rewrite the datalength field. This is typically in bytes 40-43 (but could be elsewhere if there are other chunks - basically it's the last four bytes before the actual audio data begins, and immediately following the "data" chunk descriptor). It should contain the number of bytes of data.

4. If the first file had extra stuff at the end, after the audio data, you'll need to remove that. It's easy to tell if this is the case, by reading the datalength field, working out what file size that would imply, and checking whether the file size is greater than this.

Note: all size fields must be written in Intel format (least significant byte first).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.