User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2
Here's code I wrote years ago for a now defunct company. It takes a
list of input filenames (.WAV files) and an output file name (.WAV
file), and combines the input files into a single output file. It isn't
iPhone, it isn't Objective C, it isn't CoreAudio. But it does combine
.WAV files by re-wrapping them into a single file. It was written in
Borland C++, but with a tiny bit of tweaking it can work with any C++
compiler. Maybe it will be of use to someone.
typedef struct _WAVEFMT * PWAVEFMT;
typedef struct _WAVEFMT {
char id[4];
int length;
short fmt;
short channels;
int samplesps;
int avgbytesps;
short align;
short bitsps;
} WAVEFMT;
Accepts a TList of AnsiString full-path file names, an AnsiString
output
full-path file name, and a MultiBlock flag.
Processing is as follows:
Remove from the TList any file name without a .wav extension. If no
files
remain, then quit.
For each input file, copy the wave data into the output file
according to
the MulitBlock flag.
If the MultiBlock flag is false, then all wave data is combined into a
single data block in the output file. The first file in the TList sets
the output format, and the remaining input files must have the same
format. The format blocks are not checked for consistency.
If the MultiBlock flag is true, then the input files may have different
formats, such as sampling rate, stereo, etc. The format block from each
file is copied to the output file, so that the .wav player can change
formats on-the-fly. This is the more powerful option, but may not be
compatible with all .wav players. In fact, I'm not aware of any that
support this, but it's here nonetheless.
// Write the FMT header
// If MultiBlock, write the FMT header for each input wave file,
// otherwise, only write one FMT header from the first input file
// Find the DATA block and add data length to total length
// Skip past any blocks between the FMT and DATA block, or
// break out if fread() returns less than we expect
if ( !LocateHeader( iWave, (PWAVEDATA) &data, "data" ) )
continue;
n = fread( &data.length, 1, sizeof( data.length ), iWave );
if ( n != sizeof( data.length ) ) continue;
total += data.length;
// Write the DATA header only for the first input file
// OR, for each input file when MultiBlock is specified
if ( ( !bDataWritten ) | MultiBlock ) {
bDataWritten = true;
fwrite( &data, 1, sizeof( data ), oWave );
if ( MultiBlock ) total += sizeof( data );
}
// Now, copy the actual data from input to output
// There is simple support here for a corrupt input wave file
with
// an excessive data length, so that we stop at end of file.
for ( n = 0; data.length > WAVBSIZE; data.length -= n ) {
if ( ( n = fread( buffer, 1, WAVBSIZE, iWave ) ) ==
WAVBSIZE ) {
fwrite( buffer, 1, n, oWave );
}
else {
if ( n ) fwrite( buffer, 1, n, oWave );
total -= ( WAVBSIZE - n );
data.length = 0;
break;
}
}
if ( data.length ) {
if ( ( n = fread( buffer, 1, data.length, iWave ) ) ==
data.length ) {
fwrite( buffer, 1, n, oWave );
data.length -= n;
}
else {
if ( n ) fwrite( buffer, 1, n, oWave );
total -= ( data.length - n );
data.length = 0;
}
}
fclose( iWave );
}
// If the total length is zero (which could happen on a read
error or
// when all the .wav files were missing) add dummy FMT and DATA
blocks
strncpy( data.id, "data", 4 );
data.length = 2;
buffer[0] = buffer[1] = 0;
total += data.length;
if ( MultiBlock ) total += sizeof( data );
fwrite( &data, 1, sizeof( data ), oWave );
fwrite( buffer, 1, 2, oWave );
}
// Now that the data copy is done we need to update the length in
// the data header to reflect the total of all files copied
// EXCEPT in MultiBlock mode, which has the correct length already
// in the individual data blocks
fclose( oWave );
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden