- Timestamp:
- Apr 29, 2011, 1:15:09 AM (12 years ago)
- Location:
- abuse/trunk/src
- Files:
-
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/Makefile.am
r541 r552 18 18 dprint.cpp dprint.h \ 19 19 status.cpp status.h \ 20 readwav.cpp readwav.h \21 20 pmenu.cpp pmenu.h \ 22 21 scroller.cpp scroller.h \ -
abuse/trunk/src/sdlport/sound.cpp
r551 r552 28 28 #include "sound.h" 29 29 #include "hmi.h" 30 #include "readwav.h"31 30 #include "specs.h" 32 31 #include "setup.h" … … 92 91 void sound_uninit() 93 92 { 94 if ( sound_enabled)95 {96 Mix_CloseAudio(); 97 }93 if (!sound_enabled) 94 return; 95 96 Mix_CloseAudio(); 98 97 } 99 98 … … 103 102 // Read in the requested .wav file. 104 103 // 105 sound_effect::sound_effect( char * filename ) 106 { 107 if( sound_enabled ) 108 { 109 int sample_speed; 110 111 void* temp_data = (void *)read_wav( filename, sample_speed, size ); 112 113 SDL_AudioCVT audiocvt; 114 115 SDL_BuildAudioCVT( &audiocvt, AUDIO_U8, 1, 11025, audioObtained.format, audioObtained.channels, audioObtained.freq ); 116 data = malloc( size * audiocvt.len_mult ); 117 118 memcpy( data, temp_data, size ); 119 audiocvt.buf = (Uint8*)data; 120 audiocvt.len = size; 121 SDL_ConvertAudio( &audiocvt ); 122 size = (Uint32)((double)size * audiocvt.len_ratio); 123 124 free(temp_data); 125 126 this->chunk = Mix_QuickLoad_RAW((Uint8*)data, size); 127 } 104 sound_effect::sound_effect(char const *filename) 105 { 106 if (!sound_enabled) 107 return; 108 109 jFILE fp(filename, "rb"); 110 if (fp.open_failure()) 111 return; 112 113 void *temp_data = malloc(fp.file_size()); 114 fp.read(temp_data, fp.file_size()); 115 SDL_RWops *rw = SDL_RWFromMem(temp_data, fp.file_size()); 116 m_chunk = Mix_LoadWAV_RW(rw, 1); 117 free(temp_data); 128 118 } 129 119 … … 135 125 sound_effect::~sound_effect() 136 126 { 137 if( sound_enabled ) 138 { 139 // Sound effect deletion only happens on level load, so there 140 // is no problem in stopping everything. But the original playing 141 // code handles the sound effects and the "playlist" differently. 142 // Therefore with SDL_mixer, a sound that has not finished playing 143 // on a level load will cut off in the middle. This is most noticable 144 // for the button sound of the load savegame dialog. 145 Mix_FadeOutGroup(-1, 100); 146 while (Mix_Playing(-1)) 147 SDL_Delay(10); 148 Mix_FreeChunk(this->chunk); 149 150 if( data ) 151 { 152 free( data ); 153 } 154 } 127 if(!sound_enabled) 128 return; 129 130 // Sound effect deletion only happens on level load, so there 131 // is no problem in stopping everything. But the original playing 132 // code handles the sound effects and the "playlist" differently. 133 // Therefore with SDL_mixer, a sound that has not finished playing 134 // on a level load will cut off in the middle. This is most noticable 135 // for the button sound of the load savegame dialog. 136 Mix_FadeOutGroup(-1, 100); 137 while (Mix_Playing(-1)) 138 SDL_Delay(10); 139 Mix_FreeChunk(m_chunk); 155 140 } 156 141 … … 164 149 // 255 - Completely to the left. 165 150 // 166 void sound_effect::play( int volume, int pitch, int panpot)167 { 168 if ( sound_enabled)169 {170 int channel = Mix_PlayChannel(-1, this->chunk, 0); 171 if (channel > -1)172 {173 Mix_Volume(channel, volume);174 Mix_SetPanning(channel, panpot, 255 - panpot);175 }151 void sound_effect::play(int volume, int pitch, int panpot) 152 { 153 if (!sound_enabled) 154 return; 155 156 int channel = Mix_PlayChannel(-1, m_chunk, 0); 157 if (channel > -1) 158 { 159 Mix_Volume(channel, volume); 160 Mix_SetPanning(channel, panpot, 255 - panpot); 176 161 } 177 162 } -
abuse/trunk/src/sdlport/sound.h
r551 r552 26 26 { 27 27 public: 28 sound_effect(char *filename); 29 void play(int volume = 127, int pitch = 128, int panpot = 128); 28 sound_effect(char const *filename); 30 29 ~sound_effect(); 31 30 31 void play(int volume = 127, int pitch = 128, int panpot = 128); 32 32 33 private: 33 void *data; 34 Mix_Chunk* chunk; 35 int size; 34 Mix_Chunk* m_chunk; 36 35 }; 37 36
Note: See TracChangeset
for help on using the changeset viewer.