comparison SDL_sound.c @ 172:705dcbf94639

Sound_DecodeAll() is now more robust.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 01 Dec 2001 01:12:58 +0000
parents 82acaa7107c2
children 47cc2de2ae36
comparison
equal deleted inserted replaced
171:697fabe1453e 172:705dcbf94639
636 636
637 Uint32 Sound_DecodeAll(Sound_Sample *sample) 637 Uint32 Sound_DecodeAll(Sound_Sample *sample)
638 { 638 {
639 Sound_SampleInternal *internal = NULL; 639 Sound_SampleInternal *internal = NULL;
640 void *buf = NULL; 640 void *buf = NULL;
641 void *ptr;
642 Uint32 newBufSize = 0; 641 Uint32 newBufSize = 0;
643 642
644 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); 643 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
644 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_PREV_EOF, 0);
645 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREV_ERROR, 0);
645 646
646 internal = (Sound_SampleInternal *) sample->opaque; 647 internal = (Sound_SampleInternal *) sample->opaque;
647 648
648 while ( ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) && 649 while ( ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) &&
649 ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) ) 650 ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) )
650 { 651 {
651 ptr = realloc(buf, newBufSize + sample->buffer_size); 652 Uint32 br = Sound_Decode(sample);
653 void *ptr = realloc(buf, newBufSize + br);
652 if (ptr == NULL) 654 if (ptr == NULL)
653 { 655 {
654 sample->flags |= SOUND_SAMPLEFLAG_ERROR; 656 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
655 Sound_SetError(ERR_OUT_OF_MEMORY); 657 Sound_SetError(ERR_OUT_OF_MEMORY);
656 } /* if */ 658 } /* if */
657 else 659 else
658 { 660 {
659 Uint32 br;
660 buf = ptr; 661 buf = ptr;
661 br = Sound_Decode(sample);
662 memcpy( ((char *) buf) + newBufSize, sample->buffer, br ); 662 memcpy( ((char *) buf) + newBufSize, sample->buffer, br );
663 newBufSize += br; 663 newBufSize += br;
664 } /* else */ 664 } /* else */
665 } /* while */ 665 } /* while */
666 666
667 if (buf == NULL) /* ...in case first call to realloc() fails... */
668 return(sample->buffer_size);
669
667 if (internal->buffer != sample->buffer) 670 if (internal->buffer != sample->buffer)
668 free(internal->buffer); 671 free(internal->buffer);
669 672
670 free(sample->buffer); 673 free(sample->buffer);
671 674