Mercurial > SDL_sound_CoreAudio
comparison SDL_sound.c @ 485:137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 27 Feb 2005 19:53:25 +0000 |
parents | 3e705c9180e5 |
children | c00e26a7e0b6 |
comparison
equal
deleted
inserted
replaced
484:1c09756bc038 | 485:137c0b00ea4c |
---|---|
448 * to be filled in later, by a decoder, will be initialized to zero. | 448 * to be filled in later, by a decoder, will be initialized to zero. |
449 */ | 449 */ |
450 static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired, | 450 static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired, |
451 Uint32 bufferSize) | 451 Uint32 bufferSize) |
452 { | 452 { |
453 /* | |
454 * !!! FIXME: We're going to need to pool samples, since the mixer | |
455 * !!! FIXME: might be allocating tons of these on a regular basis. | |
456 */ | |
453 Sound_Sample *retval = malloc(sizeof (Sound_Sample)); | 457 Sound_Sample *retval = malloc(sizeof (Sound_Sample)); |
454 Sound_SampleInternal *internal = malloc(sizeof (Sound_SampleInternal)); | 458 Sound_SampleInternal *internal = malloc(sizeof (Sound_SampleInternal)); |
455 if ((retval == NULL) || (internal == NULL)) | 459 if ((retval == NULL) || (internal == NULL)) |
456 { | 460 { |
457 __Sound_SetError(ERR_OUT_OF_MEMORY); | 461 __Sound_SetError(ERR_OUT_OF_MEMORY); |
691 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); | 695 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); |
692 BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL); | 696 BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL); |
693 | 697 |
694 ext = strrchr(filename, '.'); | 698 ext = strrchr(filename, '.'); |
695 rw = SDL_RWFromFile(filename, "rb"); | 699 rw = SDL_RWFromFile(filename, "rb"); |
700 /* !!! FIXME: rw = RWops_FromFile(filename, "rb");*/ | |
696 BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL); | 701 BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL); |
697 | 702 |
698 if (ext != NULL) | 703 if (ext != NULL) |
699 ext++; | 704 ext++; |
700 | 705 |
701 return(Sound_NewSample(rw, ext, desired, bufferSize)); | 706 return(Sound_NewSample(rw, ext, desired, bufferSize)); |
702 } /* Sound_NewSampleFromFile */ | 707 } /* Sound_NewSampleFromFile */ |
708 | |
709 | |
710 Sound_Sample *Sound_NewSampleFromMem(const Uint8 *data, | |
711 Uint32 size, | |
712 const char *ext, | |
713 Sound_AudioInfo *desired, | |
714 Uint32 bufferSize); | |
715 { | |
716 SDL_RWops *rw; | |
717 | |
718 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); | |
719 BAIL_IF_MACRO(data == NULL, ERR_INVALID_ARGUMENT, NULL); | |
720 BAIL_IF_MACRO(size == 0, ERR_INVALID_ARGUMENT, NULL); | |
721 | |
722 rw = SDL_RWFromMem(data, size); | |
723 /* !!! FIXME: rw = RWops_FromMem(data, size);*/ | |
724 BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL); | |
725 | |
726 return(Sound_NewSample(rw, ext, desired, bufferSize)); | |
727 } /* Sound_NewSampleFromMem */ | |
703 | 728 |
704 | 729 |
705 void Sound_FreeSample(Sound_Sample *sample) | 730 void Sound_FreeSample(Sound_Sample *sample) |
706 { | 731 { |
707 Sound_SampleInternal *internal; | 732 Sound_SampleInternal *internal; |