|
Atrinik Client 1.0
|
00001 --- mixer.c 2009-11-14 19:31:39 +0000 00002 +++ mixer.c 2010-07-19 21:28:05 +0100 00003 @@ -512,6 +512,24 @@ 00004 return(audio_opened); 00005 } 00006 00007 +/* Wrapper which calls the correct function to free the audio buffer, 00008 + depending on whether or not the buffer was allocated in the shared library. 00009 +*/ 00010 +void _Mix_FreeWAV(Mix_Chunk *chunk) 00011 +{ 00012 + /* Sanity check */ 00013 + if ( !chunk ) { 00014 + return; 00015 + } 00016 + 00017 + if ( chunk->shared ) { 00018 + SDL_FreeWAV(chunk->abuf); 00019 + } 00020 + else { 00021 + free(chunk->abuf); 00022 + } 00023 +} 00024 + 00025 00026 /* 00027 * !!! FIXME: Ideally, we want a Mix_LoadSample_RW(), which will handle the 00028 @@ -551,6 +569,7 @@ 00029 } 00030 return(NULL); 00031 } 00032 + chunk->shared = 0; 00033 00034 /* Find out what kind of audio file this is */ 00035 magic = SDL_ReadLE32(src); 00036 @@ -560,6 +579,7 @@ 00037 switch (magic) { 00038 case WAVE: 00039 case RIFF: 00040 + chunk->shared = 1; 00041 loaded = SDL_LoadWAV_RW(src, freesrc, &wavespec, 00042 (Uint8 **)&chunk->abuf, &chunk->alen); 00043 break; 00044 @@ -601,7 +621,7 @@ 00045 if ( SDL_BuildAudioCVT(&wavecvt, 00046 wavespec.format, wavespec.channels, wavespec.freq, 00047 mixer.format, mixer.channels, mixer.freq) < 0 ) { 00048 - SDL_FreeWAV(chunk->abuf); 00049 + _Mix_FreeWAV(chunk); 00050 free(chunk); 00051 return(NULL); 00052 } 00053 @@ -610,12 +630,12 @@ 00054 wavecvt.buf = (Uint8 *)malloc(wavecvt.len*wavecvt.len_mult); 00055 if ( wavecvt.buf == NULL ) { 00056 SDL_SetError("Out of memory"); 00057 - SDL_FreeWAV(chunk->abuf); 00058 + _Mix_FreeWAV(chunk); 00059 free(chunk); 00060 return(NULL); 00061 } 00062 memcpy(wavecvt.buf, chunk->abuf, chunk->alen); 00063 - SDL_FreeWAV(chunk->abuf); 00064 + _Mix_FreeWAV(chunk); 00065 00066 /* Run the audio converter */ 00067 if ( SDL_ConvertAudio(&wavecvt) < 0 ) { 00068 @@ -711,7 +731,7 @@ 00069 SDL_UnlockAudio(); 00070 /* Actually free the chunk */ 00071 if ( chunk->allocated ) { 00072 - free(chunk->abuf); 00073 + _Mix_FreeWAV(chunk); 00074 } 00075 free(chunk); 00076 } 00077 --- SDL_mixer.h 2009-11-16 04:40:54 +0000 00078 +++ SDL_mixer.h 2010-07-19 21:32:26 +0100 00079 @@ -104,6 +104,7 @@ 00080 Uint8 *abuf; 00081 Uint32 alen; 00082 Uint8 volume; /* Per-sample volume, 0-128 */ 00083 + int shared; 00084 } Mix_Chunk; 00085 00086 /* The different fading types supported */
1.7.4