Changeset 551
- Timestamp:
- Apr 29, 2011, 1:15:05 AM (12 years ago)
- Location:
- abuse/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/configure.ac
r537 r551 51 51 save_CPPFLAGS="${CPPFLAGS}" 52 52 CPPFLAGS="${CPPFLAGS} ${SDL_CFLAGS}" 53 AC_CHECK_HEADERS(SDL/SDL_mixer.h, [ac_cv_my_have_sdl ="yes"])53 AC_CHECK_HEADERS(SDL/SDL_mixer.h, [ac_cv_my_have_sdl_mixer="yes"]) 54 54 CPPFLAGS="${save_CPPFLAGS}" 55 if test "${ac_cv_my_have_sdl}" != "no"; then 56 AC_DEFINE(USE_SDL_MIXER, 1, Define to 1 to use SDL_Mixer) 57 LIBS="$LIBS -lSDL_mixer" 55 if test "${ac_cv_my_have_sdl_mixer}" = "no"; then 56 AC_MSG_ERROR([*** SDL_mixer not found!]) 58 57 fi 58 LIBS="$LIBS -lSDL_mixer" 59 59 60 60 if test "${enable_debug}" = "yes"; then -
abuse/trunk/src/sdlport/sound.cpp
r536 r551 21 21 #include "config.h" 22 22 23 #include < string.h>23 #include <cstring> 24 24 25 25 #include <SDL.h> 26 #ifdef USE_SDL_MIXER27 26 #include <SDL/SDL_mixer.h> 27 28 #include "sound.h" 28 29 #include "hmi.h" 29 #endif30 31 #include "sound.h"32 30 #include "readwav.h" 33 31 #include "specs.h" 34 32 #include "setup.h" 35 33 36 class effect_handle37 {38 public:39 effect_handle *prev; // Handle to the previous effect40 effect_handle *next; // Handle to the next effect41 Uint8 *data; // Audio data42 Uint8 *pos; // current playing position in the data43 Uint32 length; // Length of the data44 Uint32 volume; // Volume for this effect.45 46 effect_handle( effect_handle *Next )47 {48 next = Next;49 if( next )50 {51 next->prev = this;52 }53 prev = NULL;54 data = NULL;55 pos = NULL;56 }57 58 ~effect_handle()59 {60 if( next )61 {62 next->prev = prev;63 }64 if( prev )65 {66 prev->next = next;67 }68 }69 };70 71 #ifndef USE_SDL_MIXER72 static effect_handle * fx_list = NULL;73 #endif74 34 extern flags_struct flags; 75 35 static int sound_enabled = 0; 76 36 static SDL_AudioSpec audioObtained; 77 78 //79 // mix_audio80 //81 // Do the actual playing of the audio by looping through our effects list82 // and mixing each sample.83 //84 void mix_audio(void *udata, Uint8 *stream, int len)85 {86 #ifndef USE_SDL_MIXER87 effect_handle *handle = fx_list;88 89 while( handle )90 {91 if( handle->length > 0 && handle->pos )92 {93 len = ( len > (int)handle->length ? handle->length : len );94 SDL_MixAudio( stream, handle->pos, len, handle->volume );95 handle->pos += len;96 handle->length -= len;97 handle = handle->next;98 }99 else100 {101 // update the list pointer if we're deleting the first node102 if( fx_list == handle )103 {104 fx_list = handle->next;105 }106 effect_handle *tmp = handle->next;107 if( !flags.mono )108 {109 // delete the audio buffer110 free( handle->data );111 }112 delete handle;113 handle = tmp;114 }115 }116 #endif117 }118 37 119 38 // … … 146 65 free( sfxdir ); 147 66 148 #ifdef USE_SDL_MIXER149 67 if (Mix_OpenAudio(11025, AUDIO_U8, 2, 128) < 0) 150 68 { … … 161 79 sound_enabled = SFX_INITIALIZED | MUSIC_INITIALIZED; 162 80 163 printf( "Music: Enabled\n" );164 #else165 SDL_AudioSpec audioWanted;166 audioWanted.freq = 11025;167 audioWanted.format = AUDIO_U8;168 audioWanted.channels = 2 - flags.mono;169 audioWanted.samples = 128;170 audioWanted.callback = mix_audio;171 audioWanted.userdata = NULL;172 173 // Now open the audio device174 if( SDL_OpenAudio( &audioWanted, &audioObtained ) < 0 )175 {176 printf( "Sound: Unable to open audio - %s\nSound: Disabled (error)\n", SDL_GetError() );177 return 0;178 }179 180 SDL_PauseAudio( 0 );181 182 sound_enabled = SFX_INITIALIZED;183 #endif184 185 81 printf( "Sound: Enabled\n" ); 186 82 … … 196 92 void sound_uninit() 197 93 { 94 if (sound_enabled) 95 { 96 Mix_CloseAudio(); 97 } 98 } 99 100 // 101 // sound_effect constructor 102 // 103 // Read in the requested .wav file. 104 // 105 sound_effect::sound_effect( char * filename ) 106 { 198 107 if( sound_enabled ) 199 108 { 200 #ifdef USE_SDL_MIXER201 Mix_CloseAudio();202 #else203 SDL_PauseAudio( 1 );204 while( fx_list )205 {206 effect_handle *last = fx_list;207 fx_list = fx_list->next;208 free( last );209 }210 SDL_CloseAudio();211 #endif212 }213 }214 215 //216 // sound_effect constructor217 //218 // Read in the requested .wav file.219 //220 sound_effect::sound_effect( char * filename )221 {222 if( sound_enabled )223 {224 109 int sample_speed; 225 110 226 #ifdef USE_SDL_MIXER227 111 void* temp_data = (void *)read_wav( filename, sample_speed, size ); 228 112 … … 241 125 242 126 this->chunk = Mix_QuickLoad_RAW((Uint8*)data, size); 243 #else244 data = (void *)read_wav( filename, sample_speed, size );245 #endif246 127 } 247 128 } … … 256 137 if( sound_enabled ) 257 138 { 258 #ifdef USE_SDL_MIXER259 139 // Sound effect deletion only happens on level load, so there 260 140 // is no problem in stopping everything. But the original playing … … 267 147 SDL_Delay(10); 268 148 Mix_FreeChunk(this->chunk); 269 #endif270 149 271 150 if( data ) … … 279 158 // sound_effect::play 280 159 // 281 // Insert a new effect_handle into the list and modify the audio 282 // if we're doing stereo. 160 // Add a new sample for playing. 283 161 // panpot defines the pan position for the sound effect. 284 162 // 0 - Completely to the right. … … 288 166 void sound_effect::play( int volume, int pitch, int panpot ) 289 167 { 290 if( sound_enabled ) 291 { 292 #ifdef USE_SDL_MIXER 168 if (sound_enabled) 169 { 293 170 int channel = Mix_PlayChannel(-1, this->chunk, 0); 294 171 if (channel > -1) … … 297 174 Mix_SetPanning(channel, panpot, 255 - panpot); 298 175 } 299 #else300 SDL_LockAudio();301 302 fx_list = new effect_handle( fx_list );303 if( fx_list == NULL )304 {305 printf( "Sound: ERROR - Failed to create new effect.\n" );306 SDL_UnlockAudio();307 return;308 }309 310 if( !flags.mono )311 {312 unsigned int i;313 Uint32 cvtBufferSize;314 SDL_AudioCVT audiocvt;315 316 // Do some audio conversion317 SDL_BuildAudioCVT( &audiocvt, AUDIO_U8, 1, 11025, audioObtained.format, audioObtained.channels, audioObtained.freq );318 audiocvt.buf = (Uint8 *)malloc( size * audiocvt.len_mult );319 audiocvt.len = size;320 memcpy( audiocvt.buf, data, size );321 SDL_ConvertAudio( &audiocvt );322 cvtBufferSize = (Uint32)((double)size * audiocvt.len_ratio);323 324 // Adjust for requested pan position325 if( panpot != 128 )326 {327 if( panpot > 128 )328 {329 // Pan to the left330 panpot = (panpot - 255) * -1;331 for( i = 1 ; i <= cvtBufferSize; i += 2 )332 {333 audiocvt.buf[i] = (((audiocvt.buf[i] - 128) * panpot) / 128) + 128;334 }335 }336 else337 {338 // Pan to the right339 for( i = 0 ; i < cvtBufferSize; i += 2 )340 {341 audiocvt.buf[i] = (((audiocvt.buf[i] - 128) * panpot) / 128) + 128;342 }343 }344 }345 346 fx_list->data = audiocvt.buf;347 fx_list->pos = audiocvt.buf;348 fx_list->length = cvtBufferSize;349 fx_list->volume = volume;350 }351 else352 {353 // Only doing mono so don't mess with the audio data.354 fx_list->data = (Uint8 *)data;355 fx_list->pos = (Uint8 *)data;356 fx_list->length = size;357 fx_list->volume = volume;358 }359 SDL_UnlockAudio();360 #endif361 176 } 362 177 } … … 371 186 song_id = 0; 372 187 373 #ifdef USE_SDL_MIXER374 188 rw = NULL; 375 189 music = NULL; … … 384 198 if (!data) 385 199 { 386 printf(" Music: ERROR - could not load %s\n", realname);200 printf("Sound: ERROR - could not load %s\n", realname); 387 201 return; 388 202 } … … 393 207 if (!music) 394 208 { 395 printf(" Music: ERROR - %s while loading %s\n",209 printf("Sound: ERROR - %s while loading %s\n", 396 210 Mix_GetError(), realname); 397 211 return; 398 212 } 399 #endif400 213 } 401 214 … … 407 220 free(Name); 408 221 409 #ifdef USE_SDL_MIXER410 222 Mix_FreeMusic(music); 411 223 SDL_FreeRW(rw); 412 #endif413 224 } 414 225 … … 417 228 song_id = 1; 418 229 419 #ifdef USE_SDL_MIXER420 230 Mix_PlayMusic(this->music, 0); 421 231 Mix_VolumeMusic(volume); 422 #endif423 232 } 424 233 … … 427 236 song_id = 0; 428 237 429 #ifdef USE_SDL_MIXER430 238 Mix_FadeOutMusic(100); 431 #endif432 239 } 433 240 434 241 int song::playing() 435 242 { 436 #ifdef USE_SDL_MIXER437 243 return Mix_PlayingMusic(); 438 #else439 return song_id;440 #endif441 244 } 442 245 443 246 void song::set_volume( int volume ) 444 247 { 445 #ifdef USE_SDL_MIXER446 248 Mix_VolumeMusic(volume); 447 #else 448 // do nothing... 449 #endif 450 } 249 } 250 -
abuse/trunk/src/sdlport/sound.h
r534 r551 12 12 #define __SOUND_H__ 13 13 14 #ifdef USE_SDL_MIXER 15 # include <SDL/SDL_mixer.h> 16 #endif 14 #include <SDL/SDL_mixer.h> 17 15 18 16 /* options are passed via command line */ … … 34 32 private: 35 33 void *data; 36 #ifdef USE_SDL_MIXER37 34 Mix_Chunk* chunk; 38 #endif39 35 int size; 40 36 }; … … 55 51 unsigned char *data; 56 52 unsigned long song_id; 57 #ifdef USE_SDL_MIXER58 53 Mix_Music* music; 59 54 SDL_RWops* rw; 60 #endif61 55 }; 62 56
Note: See TracChangeset
for help on using the changeset viewer.