> How would I concatenate two MP3 files, such that I can stream them out
> as a single file?
On the most part you can just directly concatenate them. If there is any
tag blocks at the end they need to be removed first.
An MP3 is an elementary stream, that is an unstructured
sequence of independent audio frames. As long as the last
frame of the first clip is a valid frame, you can just
append the second clip to it. Examples of invalid last
frames are a truncated frame or the ID3v1 tag.
Frames are independent from each other and they can have
different audio settings. However, while most MP3 decoders
will not mind a change in bitrate (since that's just what a
VBR stream is), they will most likely fail if the sampling
rate or channel count changes.
So, if you know that sampling rate and channel count are the
same and the files are not corrupted, just look for the
ID3v1 tag and remove it (that is, the last 128 bytes of the
file if they start with 'TAG') then append the files to each
other without worry.
If you want to be safe, you can use my sample MP3 parser to
make sure the files are neither corrupted nor incompatible:
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net
Actually, it's very easy to port to C# and you can almost
use that code as it is by replacing the file I/O function
calls with a CLR I/O stream method calls.
int[,,] bitrates = new int[4,4,16] and
int bitrates = new int
neither of which are working too well. I can paste the whole block of
code if you like.
Aside from the TAG block at the end of the MP3 file, I also see lots of
header data. Do I need to alter/cut that out too when concatenating two