diff --git a/snd/sounds/afterburner.wav b/snd/sounds/afterburner.wav new file mode 100644 index 0000000..4b6accc Binary files /dev/null and b/snd/sounds/afterburner.wav differ diff --git a/snd/sounds/engine.wav b/snd/sounds/engine.wav index 7727f09..282b36d 100644 Binary files a/snd/sounds/engine.wav and b/snd/sounds/engine.wav differ diff --git a/snd/sounds/mass.wav b/snd/sounds/mass.wav new file mode 100644 index 0000000..affeacf Binary files /dev/null and b/snd/sounds/mass.wav differ diff --git a/snd/sounds/neutron.wav b/snd/sounds/neutron.wav new file mode 100644 index 0000000..9a2b62e Binary files /dev/null and b/snd/sounds/neutron.wav differ diff --git a/src/sound.c b/src/sound.c index 3a99a18..c7b79f3 100644 --- a/src/sound.c +++ b/src/sound.c @@ -86,7 +86,7 @@ static int source_nstack = 0; struct alVoice { alVoice* next; // Yes it's a linked list. - ALuint id; // Unique id for the voice. + //ALuint id; // Unique id for the voice. ALuint source; // Source itself, 0 if not set. ALuint buffer; // Buffer. @@ -94,7 +94,7 @@ struct alVoice { int priority; // Base priority. double px, py; // Position. - double vx, vy; // Velocity. + //double vx, vy; // Velocity. unsigned int start; // time started in ms. unsigned int flags; // Flags to set properties. @@ -105,10 +105,11 @@ static alVoice* voice_end = NULL; // Volume. static ALfloat svolume = 0.3; -static int sound_makeList(void); -static int sound_load(ALuint* buffer, char* filename); +static int sound_makeList(void); +static int sound_load(ALuint* buffer, char* filename); static void sound_free(alSound* snd); -static int voice_getSource(alVoice* voc); +static int voice_getSource(alVoice* voc); +static void voice_rm(alVoice* prev, alVoice* voice); int sound_init(void) { int mem, ret = 0; @@ -224,6 +225,14 @@ void sound_exit(void) { music_exit(); } + // Clean up the voices. + while(voice_start != NULL) + voice_rm(NULL, voice_start); + + // Clean up the sources. + if(source_stack) + alDeleteSources(source_nstack, source_stack); + if(sound_lock) { SDL_mutexP(sound_lock); @@ -296,7 +305,7 @@ static int sound_makeList(void) { free(files[i]); free(files); - DEBUG("Loaded %d sound%s", nsound_list, (nsound_list==1)?"":'s'); + DEBUG("Loaded %d sound%s", nsound_list, (nsound_list==1)?"":"s"); return 0; } @@ -345,7 +354,6 @@ static void sound_free(alSound* snd) { // Update the sounds and prioritize them. void sound_update(void) { - ALint stat; alVoice* voice, *prev, *next; if(sound_lock == NULL) return; // Sound system is off. @@ -364,34 +372,38 @@ void sound_update(void) { voice->px, voice->py, 0.); /*alSource3f(voice->source, AL_VELOCITY, voice->vx, voice->vy, 0.);*/ - } else { // Delete them. - if(voice->source != 0) { - // Sources must exist. - - // Stop it if playing. - alGetSourcei(voice->source, AL_SOURCE_STATE, &stat); - if(stat == AL_PLAYING) alSourceStop(voice->source); - - // Clear it and get rid of it. - source_stack[source_nstack++] == voice->source; // throw it back. - } - - // Delete from linked list. - if(prev == NULL) - voice_start = voice->next; - else // Not first member. - prev->next = voice->next; - if(voice_end == voice) - voice_end = prev; - free(voice); - } - prev = voice; + prev = voice; // Only case where voice will stay. + } else // Delete them. + voice_rm(prev, voice); voice = next; } while(voice != NULL); SDL_mutexV(sound_lock); } +// Remove a voice. +static void voice_rm(alVoice* prev, alVoice* voice) { + ALint stat; + + if(voice->source != 0) { // Source must exist. + // Stop it if playing. + alGetSourcei(voice->source, AL_SOURCE_STATE, &stat); + if(stat == AL_PLAYING) alSourceStop(voice->source); + + // Clear it and get rid of it. + source_stack[source_nstack++] = voice->source; // Throw it back. + } + + // Delete from linked list. + if(prev == NULL) // Was the first member. + voice_start = voice->next; + else // Not first memmber. + prev->next = voice->next; + if(voice_end == voice) // Last voice in linked list. + voice_end = prev; + free(voice); +} + // Set all the sounds volume to vol. void sound_volume(const double vol) { if(sound_lock == NULL) return;