mixer.c
changeset 621 944412baab72
parent 617 87116a42526e
child 625 1d489d8ec2e0
equal deleted inserted replaced
620:e178da4a838c 621:944412baab72
   124     return(chunk_decoders[index]);
   124     return(chunk_decoders[index]);
   125 }
   125 }
   126 
   126 
   127 static void add_chunk_decoder(const char *decoder)
   127 static void add_chunk_decoder(const char *decoder)
   128 {
   128 {
   129     void *ptr = SDL_realloc(chunk_decoders, (num_decoders + 1) * sizeof (const char **));
   129     void *ptr = SDL_realloc((void *)chunk_decoders, (num_decoders + 1) * sizeof (const char **));
   130     if (ptr == NULL) {
   130     if (ptr == NULL) {
   131         return;  /* oh well, go on without it. */
   131         return;  /* oh well, go on without it. */
   132     }
   132     }
   133     chunk_decoders = (const char **) ptr;
   133     chunk_decoders = (const char **) ptr;
   134     chunk_decoders[num_decoders++] = decoder;
   134     chunk_decoders[num_decoders++] = decoder;
   265         if (!posteffect) {
   265         if (!posteffect) {
   266             buf = SDL_malloc(len);
   266             buf = SDL_malloc(len);
   267             if (buf == NULL) {
   267             if (buf == NULL) {
   268                 return(snd);
   268                 return(snd);
   269             }
   269             }
   270             memcpy(buf, snd, len);
   270             SDL_memcpy(buf, snd, len);
   271         }
   271         }
   272 
   272 
   273         for (; e != NULL; e = e->next) {
   273         for (; e != NULL; e = e->next) {
   274             if (e->callback != NULL) {
   274             if (e->callback != NULL) {
   275                 e->callback(chan, buf, len, e->udata);
   275                 e->callback(chan, buf, len, e->udata);
   289     int i, mixable, volume = SDL_MIX_MAXVOLUME;
   289     int i, mixable, volume = SDL_MIX_MAXVOLUME;
   290     Uint32 sdl_ticks;
   290     Uint32 sdl_ticks;
   291 
   291 
   292 #if SDL_VERSION_ATLEAST(1, 3, 0)
   292 #if SDL_VERSION_ATLEAST(1, 3, 0)
   293     /* Need to initialize the stream in SDL 1.3+ */
   293     /* Need to initialize the stream in SDL 1.3+ */
   294     memset(stream, mixer.silence, len);
   294     SDL_memset(stream, mixer.silence, len);
   295 #endif
   295 #endif
   296 
   296 
   297     /* Mix the music (must be done before the channels are added) */
   297     /* Mix the music (must be done before the channels are added) */
   298     if ( music_active || (mix_music != music_mixer) ) {
   298     if ( music_active || (mix_music != music_mixer) ) {
   299         mix_music(music_data, stream, len);
   299         mix_music(music_data, stream, len);
   645             SDL_SetError("Out of memory");
   645             SDL_SetError("Out of memory");
   646             SDL_free(chunk->abuf);
   646             SDL_free(chunk->abuf);
   647             SDL_free(chunk);
   647             SDL_free(chunk);
   648             return(NULL);
   648             return(NULL);
   649         }
   649         }
   650         memcpy(wavecvt.buf, chunk->abuf, chunk->alen);
   650         SDL_memcpy(wavecvt.buf, chunk->abuf, chunk->alen);
   651         SDL_free(chunk->abuf);
   651         SDL_free(chunk->abuf);
   652 
   652 
   653         /* Run the audio converter */
   653         /* Run the audio converter */
   654         if ( SDL_ConvertAudio(&wavecvt) < 0 ) {
   654         if ( SDL_ConvertAudio(&wavecvt) < 0 ) {
   655             SDL_free(wavecvt.buf);
   655             SDL_free(wavecvt.buf);
   688 
   688 
   689     /* Essentially just skip to the audio data (no error checking - fast) */
   689     /* Essentially just skip to the audio data (no error checking - fast) */
   690     chunk->allocated = 0;
   690     chunk->allocated = 0;
   691     mem += 12; /* WAV header */
   691     mem += 12; /* WAV header */
   692     do {
   692     do {
   693         memcpy(magic, mem, 4);
   693         SDL_memcpy(magic, mem, 4);
   694         mem += 4;
   694         mem += 4;
   695         chunk->alen = ((mem[3]<<24)|(mem[2]<<16)|(mem[1]<<8)|(mem[0]));
   695         chunk->alen = ((mem[3]<<24)|(mem[2]<<16)|(mem[1]<<8)|(mem[0]));
   696         mem += 4;
   696         mem += 4;
   697         chunk->abuf = mem;
   697         chunk->abuf = mem;
   698         mem += chunk->alen;
   698         mem += chunk->alen;
  1140             SDL_CloseAudio();
  1140             SDL_CloseAudio();
  1141             SDL_free(mix_channel);
  1141             SDL_free(mix_channel);
  1142             mix_channel = NULL;
  1142             mix_channel = NULL;
  1143 
  1143 
  1144             /* rcg06042009 report available decoders at runtime. */
  1144             /* rcg06042009 report available decoders at runtime. */
  1145             SDL_free(chunk_decoders);
  1145             SDL_free((void *)chunk_decoders);
  1146             chunk_decoders = NULL;
  1146             chunk_decoders = NULL;
  1147             num_decoders = 0;
  1147             num_decoders = 0;
  1148         }
  1148         }
  1149         --audio_opened;
  1149         --audio_opened;
  1150     }
  1150     }