From f191a1d824c9af1dda647684aad0e68dfa77360b Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 4 Jun 2013 16:40:30 +0100 Subject: [PATCH] [Fix] [Phase 3] Sound is enabled by default again. --- src/conf.c | 2 +- src/sound.c | 32 +++++++++++--------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/conf.c b/src/conf.c index cc65ab8..af4df80 100644 --- a/src/conf.c +++ b/src/conf.c @@ -84,7 +84,7 @@ void conf_setDefaults(void) { gl_screen.h = 600; gl_screen.flags = 0; // Openal. - nosound = 1; // TODO: make sound default when it's sane again. + nosound = 0; // Joystick. indjoystick = -1; namjoystick = NULL; diff --git a/src/sound.c b/src/sound.c index 39ecd8e..3a99a18 100644 --- a/src/sound.c +++ b/src/sound.c @@ -78,11 +78,8 @@ static SDL_Thread* music_player = NULL; static alSound* sound_list = NULL; static int nsound_list = 0; -typedef struct VoiceSource_ { - ALuint source; // Allocated source. - ALuint voice; // Voice id. -} VoiceSource; -static VoiceSource* source_stack = NULL; // And it's stack. +// Struct to hold all the sources and currently attached voice. +static ALuint* source_stack = NULL; // And it's stack. static int source_nstack = 0; // Virtual voice. @@ -162,7 +159,6 @@ int sound_init(void) { // Start the music server. music_init(); -#if 0 // Start allocating the sources - music has already taken this. alGetError(); // Another error clear. mem = 0; @@ -170,16 +166,14 @@ int sound_init(void) { if(mem < source_nstack+1) { // Allocate more memory. mem += 32; - source_stack = realloc(source_stack, sizeof(VoiceSource) * mem); + source_stack = realloc(source_stack, sizeof(ALuint) * mem); } - alGenSources(1, &source_stack[source_nstack].source); - source_stack[source_nstack].voice = 0; + alGenSources(1, &source_stack[source_nstack]); source_nstack++; } // Use minimal ram. - source_stack = realloc(source_stack, sizeof(VoiceSource) * source_nstack); -#endif + source_stack = realloc(source_stack, sizeof(ALuint) * source_nstack); // Debug magic. DEBUG("OpenAL: %s", device); @@ -379,8 +373,7 @@ void sound_update(void) { if(stat == AL_PLAYING) alSourceStop(voice->source); // Clear it and get rid of it. - alDeleteSources(1, &voice->source); - voice->source = 0; + source_stack[source_nstack++] == voice->source; // throw it back. } // Delete from linked list. @@ -417,14 +410,10 @@ static int voice_getSource(alVoice* voc) { SDL_mutexP(sound_lock); // Try and grab a source. - voc->source = 0; - alGenSources(1, &voc->source); - err = alGetError(); + if(source_nstack > 0) { // We have the source. + // We must pull it from the free source vector. + voc->source = source_stack[--source_nstack]; - if(err != AL_NO_ERROR) { - voc->source = 0; - ret = 1; - } else { // Set the properties. alSourcei(voc->source, AL_BUFFER, voc->buffer); @@ -447,7 +436,8 @@ static int voice_getSource(alVoice* voc) { err = alGetError(); if(err == AL_NO_ERROR) voice_set(voc, VOICE_PLAYING); else ret = 2; - } + } else + voc->source = 0; SDL_mutexV(sound_lock); return ret;