Changeset 479
- Timestamp:
- Apr 17, 2011, 10:27:50 AM (11 years ago)
- Location:
- abuse/trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/configure.ac
r478 r479 46 46 CFLAGS="$CFLAGS $SDL_CFLAGS" 47 47 LIBS="$LIBS $SDL_LIBS $X_LIBS" 48 49 # Add SDL_Mixer 50 LIBS="$LIBS -lSDL_mixer" 51 CFLAGS="${CFLAGS} -DUSE_SDL_MIXER" 52 CPPFLAGS="${CPPFLAGS} -DUSE_SDL_MIXER" 48 53 49 54 if test "${enable_debug}" = "yes"; then -
abuse/trunk/src/sdlport/Makefile.am
r130 r479 13 13 joystick.cpp joy.hpp \ 14 14 setup.cpp setup.h \ 15 hmi.cpp hmi.h \ 15 16 $(NULL) 16 17 libsdlport_a_LIBADD = -
abuse/trunk/src/sdlport/sound.cpp
r131 r479 23 23 24 24 #include <SDL.h> 25 #ifdef USE_SDL_MIXER 26 #include <SDL/SDL_mixer.h> 27 #include "hmi.hpp" 28 #endif 25 29 26 30 #include "sound.hpp" … … 77 81 void mix_audio(void *udata, Uint8 *stream, int len) 78 82 { 83 #ifndef USE_SDL_MIXER 79 84 effect_handle *handle = fx_list; 80 85 … … 106 111 } 107 112 } 113 #endif 108 114 } 109 115 … … 138 144 free( sfxdir ); 139 145 146 #ifdef USE_SDL_MIXER 147 if (Mix_OpenAudio(11025, AUDIO_U8, 2, 128) < 0) 148 { 149 printf( "Sound : Unable to open audio - %s\nSound : Disabled (error)\n", SDL_GetError() ); 150 return 0; 151 } 152 153 Mix_AllocateChannels(50); 154 155 int tempChannels = 0; 156 Mix_QuerySpec(&audioObtained.freq, &audioObtained.format, &tempChannels); 157 audioObtained.channels = tempChannels & 0xFF; 158 159 sound_enabled = SFX_INITIALIZED | MUSIC_INITIALIZED; 160 #else 140 161 audioWanted.freq = 11025; 141 162 audioWanted.format = AUDIO_U8; … … 152 173 } 153 174 154 sound_enabled = 1; 175 SDL_PauseAudio( 0 ); 176 177 sound_enabled = SFX_INITIALIZED; 178 #endif 179 155 180 printf( "Sound : Enabled\n" ); 156 157 SDL_PauseAudio( 0 );158 181 159 182 // It's all good … … 170 193 if( sound_enabled ) 171 194 { 195 #ifdef USE_SDL_MIXER 196 Mix_CloseAudio(); 197 #else 172 198 SDL_PauseAudio( 1 ); 173 199 while( fx_list ) … … 178 204 } 179 205 SDL_CloseAudio(); 206 #endif 180 207 } 181 208 } … … 191 218 { 192 219 long sample_speed; 220 221 #ifdef USE_SDL_MIXER 222 void* temp_data = (void *)read_wav( filename, sample_speed, size ); 223 224 SDL_AudioCVT audiocvt; 225 226 SDL_BuildAudioCVT( &audiocvt, AUDIO_U8, 1, 11025, audioObtained.format, audioObtained.channels, audioObtained.freq ); 227 data = malloc( size * audiocvt.len_mult ); 228 229 memcpy( data, temp_data, size ); 230 audiocvt.buf = (Uint8*)data; 231 audiocvt.len = size; 232 SDL_ConvertAudio( &audiocvt ); 233 size = (Uint32)((double)size * audiocvt.len_ratio); 234 235 free(temp_data); 236 237 this->chunk = Mix_QuickLoad_RAW((Uint8*)data, size); 238 #else 193 239 data = (void *)read_wav( filename, sample_speed, size ); 240 #endif 194 241 } 195 242 } … … 204 251 if( sound_enabled ) 205 252 { 253 #ifdef USE_SDL_MIXER 254 // Sound effect deletion only happens on level load, so there 255 // is no problem in stopping everything. But the original playing 256 // code handles the sound effects and the "playlist" differently. 257 // Therefore with SDL_mixer, a sound that has not finished playing 258 // on a level load will cut off in the middle. This is most noticable 259 // for the button sound of the load savegame dialog. 260 Mix_FadeOutGroup(-1, 100); 261 while (Mix_Playing(-1)) 262 SDL_Delay(10); 263 Mix_FreeChunk(this->chunk); 264 #endif 265 206 266 if( data ) 207 267 { … … 225 285 if( sound_enabled ) 226 286 { 287 #ifdef USE_SDL_MIXER 288 int channel = Mix_PlayChannel(-1, this->chunk, 0); 289 if (channel > -1) 290 { 291 Mix_Volume(channel, volume); 292 Mix_SetPanning(channel, panpot, 255 - panpot); 293 } 294 #else 227 295 SDL_LockAudio(); 228 296 … … 285 353 } 286 354 SDL_UnlockAudio(); 287 } 288 } 289 290 291 // 292 // We don't handle songs. These are just stubs to basically do nothing. 293 // I tried using SDL_mixer to do this, but with no success. 294 // 355 #endif 356 } 357 } 358 359 360 // Play music using SDL_Mixer 295 361 296 362 song::song( char const * filename ) … … 299 365 Name = strdup(filename); 300 366 song_id = 0; 367 368 #ifdef USE_SDL_MIXER 369 rw = NULL; 370 music = NULL; 371 372 char realname[255]; 373 strcpy(realname, get_filename_prefix()); 374 strcat(realname, filename); 375 376 unsigned int data_size; 377 data = load_hmi(realname, data_size); 378 379 if (data) 380 { 381 rw = SDL_RWFromMem(data, data_size); 382 music = Mix_LoadMUS_RW(rw); 383 } 384 #endif 301 385 } 302 386 … … 312 396 } 313 397 free( Name ); 398 399 #ifdef USE_SDL_MIXER 400 Mix_FreeMusic(this->music); 401 SDL_FreeRW(this->rw); 402 #endif 314 403 } 315 404 … … 317 406 { 318 407 song_id = 1; 408 409 #ifdef USE_SDL_MIXER 410 Mix_PlayMusic(this->music, 0); 411 Mix_VolumeMusic(volume); 412 #endif 319 413 } 320 414 … … 322 416 { 323 417 song_id = 0; 418 419 #ifdef USE_SDL_MIXER 420 Mix_FadeOutMusic(100); 421 #endif 324 422 } 325 423 326 424 int song::playing() 327 425 { 426 #ifdef USE_SDL_MIXER 427 return Mix_PlayingMusic(); 428 #else 328 429 return song_id; 430 #endif 329 431 } 330 432 331 433 void song::set_volume( int volume ) 332 434 { 333 // do nothing... 334 } 435 #ifdef USE_SDL_MIXER 436 Mix_VolumeMusic(volume); 437 #else 438 // do nothing... 439 #endif 440 } -
abuse/trunk/src/sdlport/sound.hpp
r124 r479 10 10 #ifndef __SOUND_HPP_ 11 11 #define __SOUND_HPP_ 12 13 #ifdef USE_SDL_MIXER 14 #include <SDL/SDL_mixer.h> 15 #endif 12 16 13 17 /* options are passed via command line */ … … 24 28 long size; 25 29 void *data; 30 #ifdef USE_SDL_MIXER 31 Mix_Chunk* chunk; 32 #endif 26 33 public : 27 34 sound_effect(char *filename); … … 36 43 unsigned char *data; 37 44 unsigned long song_id; 45 #ifdef USE_SDL_MIXER 46 Mix_Music* music; 47 SDL_RWops* rw; 48 #endif 38 49 public : 39 50 char const *name() { return Name; }
Note: See TracChangeset
for help on using the changeset viewer.