Hey everyone, I’m not sure if this is a bug in SDL, or if I just have
incorrect WAV files. The problem I’m having is loading multiple
concatenated WAVs from SDL_LoadWAV_RW. Some WAV files put comments at
the end of the file (which may be bad form), and SDL doesn’t skip past
them when reading from the RWops. So the next WAV I try to load will
start at the comment section of the previous WAV, which obviously
doesn’t work. If anyone else is having this problem, one quick fix you
can do is run sox on the bad WAVs, which strips out all of the comment
sections.
Eg:
$ sox sound.wav tmp.wav
$ mv -f tmp.wav sound.wav
The other fix is to patch SDL_wave.c, which is included with this email.
(Assuming I made the patch correctly :). All it does is calculate how
much remaining space there is in the WAV file after the data chunk, and
does SDL_RWseek to skip it. I don’t think it should interfere with
anything else, but if someone could check it that would be nice :). If
the bug is really with SDL and not with my WAVs, can someone work this
into the next version of SDL? Thanks,
-Mike Shal
-------------- next part --------------
421c421
< Uint32 wavelen;—
Uint32 wavelen = 0;
422a423
Uint32 headerDiff = 0;
448a450
headerDiff += sizeof(Uint32); // for WAVE
460a463,464
// 2 Uint32’s for chunk header+len, plus the lenread
headerDiff += lenread + 2 * sizeof(Uint32);
537a542
if(chunk.magic != DATA) headerDiff += lenread + 2 * sizeof(Uint32);
538a544
headerDiff += 2 * sizeof(Uint32); // for the data chunk and len
566a573,576
else {
// seek to the end of the file (given by the RIFF chunk)
SDL_RWseek(src, wavelen - chunk.length - headerDiff, SEEK_CUR);
}
Oops, already found a bug in my patch! Hopefully this is correct
now…still, anyone have any idea if this actually needs to be fixed?
Thanks,
-Mike ShalOn Tue, 2003-06-10 at 15:30, Mike Shal wrote:
Hey everyone, I’m not sure if this is a bug in SDL, or if I just have
incorrect WAV files. The problem I’m having is loading multiple
concatenated WAVs from SDL_LoadWAV_RW. Some WAV files put comments at
the end of the file (which may be bad form), and SDL doesn’t skip past
them when reading from the RWops. So the next WAV I try to load will
start at the comment section of the previous WAV, which obviously
doesn’t work. If anyone else is having this problem, one quick fix you
can do is run sox on the bad WAVs, which strips out all of the comment
sections.
Eg:
$ sox sound.wav tmp.wav
$ mv -f tmp.wav sound.wav
The other fix is to patch SDL_wave.c, which is included with this email.
(Assuming I made the patch correctly :). All it does is calculate how
much remaining space there is in the WAV file after the data chunk, and
does SDL_RWseek to skip it. I don’t think it should interfere with
anything else, but if someone could check it that would be nice :). If
the bug is really with SDL and not with my WAVs, can someone work this
into the next version of SDL? Thanks,
-Mike Shal
421c421
< Uint32 wavelen;
Uint32 wavelen = 0;
422a423
Uint32 headerDiff = 0;
448a450
headerDiff += sizeof(Uint32); // for WAVE
460a463,464
// 2 Uint32's for chunk header+len, plus the lenread
headerDiff += lenread + 2 * sizeof(Uint32);
537a542
if(chunk.magic != DATA) headerDiff += lenread + 2 * sizeof(Uint32);
538a544
headerDiff += 2 * sizeof(Uint32); // for the data chunk and len
566a573,576
else {
// seek to the end of the file (given by the RIFF chunk)
SDL_RWseek(src, wavelen - chunk.length - headerDiff, SEEK_CUR);
}
-------------- next part --------------
421c421
< Uint32 wavelen;
Uint32 wavelen = 0;
422a423
Uint32 headerDiff = 0;
448a450
headerDiff += sizeof(Uint32); // for WAVE
460a463,464
// 2 Uint32’s for chunk header+len, plus the lenread
headerDiff += lenread + 2 * sizeof(Uint32);
537a542
if(chunk.magic != DATA) headerDiff += lenread + 2 * sizeof(Uint32);
538a544
headerDiff += 2 * sizeof(Uint32); // for the data chunk and len
563a570,573
else {
// seek to the end of the file (given by the RIFF chunk)
SDL_RWseek(src, wavelen - chunk.length - headerDiff, SEEK_CUR);
}
Mike Shal wrote:
Hey everyone, I’m not sure if this is a bug in SDL, or if I just have
incorrect WAV files. The problem I’m having is loading multiple
concatenated WAVs from SDL_LoadWAV_RW.
Plain concatenation is not safe, since the state of the RWOps object after
SDL_LoadWAV_RW is undefined. In fact, passing the RWOps object of the whole
(concatenated) file is unsafe, period. SDL_LoadWAV_RW is allowed to assume
that the WAV file it’s loading ends at the end of the sequence defined by
the RWOps object.
Solution: don’t just concatenate. Make an index containing the starting
(and end) positions of each WAV file within the archive. Then create RWOps
objects from these and pass them to SDL_LoadWAV_RW.–
Rainer Deyke - rainerd at eldwood.com - http://eldwood.com