Mercurial > sdl-ios-xcode
comparison src/audio/SDL_wave.c @ 1260:80f8c94b5199
Date: 10 Jun 2003 15:30:59 -0400
From: Mike Shal
Subject: [SDL] Bug in SDL_wave.c?
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
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 24 Jan 2006 07:20:18 +0000 |
parents | b8d311d90021 |
children | c9b51268668f |
comparison
equal
deleted
inserted
replaced
1259:36f24cdfcda7 | 1260:80f8c94b5199 |
---|---|
416 int MS_ADPCM_encoded, IMA_ADPCM_encoded; | 416 int MS_ADPCM_encoded, IMA_ADPCM_encoded; |
417 int samplesize; | 417 int samplesize; |
418 | 418 |
419 /* WAV magic header */ | 419 /* WAV magic header */ |
420 Uint32 RIFFchunk; | 420 Uint32 RIFFchunk; |
421 Uint32 wavelen; | 421 Uint32 wavelen = 0; |
422 Uint32 WAVEmagic; | 422 Uint32 WAVEmagic; |
423 Uint32 headerDiff = 0; | |
423 | 424 |
424 /* FMT chunk */ | 425 /* FMT chunk */ |
425 WaveFMT *format = NULL; | 426 WaveFMT *format = NULL; |
426 | 427 |
427 /* Make sure we are passed a valid data source */ | 428 /* Make sure we are passed a valid data source */ |
444 if ( (RIFFchunk != RIFF) || (WAVEmagic != WAVE) ) { | 445 if ( (RIFFchunk != RIFF) || (WAVEmagic != WAVE) ) { |
445 SDL_SetError("Unrecognized file type (not WAVE)"); | 446 SDL_SetError("Unrecognized file type (not WAVE)"); |
446 was_error = 1; | 447 was_error = 1; |
447 goto done; | 448 goto done; |
448 } | 449 } |
450 headerDiff += sizeof(Uint32); // for WAVE | |
449 | 451 |
450 /* Read the audio data format chunk */ | 452 /* Read the audio data format chunk */ |
451 chunk.data = NULL; | 453 chunk.data = NULL; |
452 do { | 454 do { |
453 if ( chunk.data != NULL ) { | 455 if ( chunk.data != NULL ) { |
456 lenread = ReadChunk(src, &chunk); | 458 lenread = ReadChunk(src, &chunk); |
457 if ( lenread < 0 ) { | 459 if ( lenread < 0 ) { |
458 was_error = 1; | 460 was_error = 1; |
459 goto done; | 461 goto done; |
460 } | 462 } |
463 // 2 Uint32's for chunk header+len, plus the lenread | |
464 headerDiff += lenread + 2 * sizeof(Uint32); | |
461 } while ( (chunk.magic == FACT) || (chunk.magic == LIST) ); | 465 } while ( (chunk.magic == FACT) || (chunk.magic == LIST) ); |
462 | 466 |
463 /* Decode the audio data format */ | 467 /* Decode the audio data format */ |
464 format = (WaveFMT *)chunk.data; | 468 format = (WaveFMT *)chunk.data; |
465 if ( chunk.magic != FMT ) { | 469 if ( chunk.magic != FMT ) { |
533 was_error = 1; | 537 was_error = 1; |
534 goto done; | 538 goto done; |
535 } | 539 } |
536 *audio_len = lenread; | 540 *audio_len = lenread; |
537 *audio_buf = chunk.data; | 541 *audio_buf = chunk.data; |
542 if(chunk.magic != DATA) headerDiff += lenread + 2 * sizeof(Uint32); | |
538 } while ( chunk.magic != DATA ); | 543 } while ( chunk.magic != DATA ); |
544 headerDiff += 2 * sizeof(Uint32); // for the data chunk and len | |
539 | 545 |
540 if ( MS_ADPCM_encoded ) { | 546 if ( MS_ADPCM_encoded ) { |
541 if ( MS_ADPCM_decode(audio_buf, audio_len) < 0 ) { | 547 if ( MS_ADPCM_decode(audio_buf, audio_len) < 0 ) { |
542 was_error = 1; | 548 was_error = 1; |
543 goto done; | 549 goto done; |
558 if ( format != NULL ) { | 564 if ( format != NULL ) { |
559 free(format); | 565 free(format); |
560 } | 566 } |
561 if ( freesrc && src ) { | 567 if ( freesrc && src ) { |
562 SDL_RWclose(src); | 568 SDL_RWclose(src); |
569 } | |
570 else { | |
571 // seek to the end of the file (given by the RIFF chunk) | |
572 SDL_RWseek(src, wavelen - chunk.length - headerDiff, SEEK_CUR); | |
563 } | 573 } |
564 if ( was_error ) { | 574 if ( was_error ) { |
565 spec = NULL; | 575 spec = NULL; |
566 } | 576 } |
567 return(spec); | 577 return(spec); |