[Fix] [Phase 3] Sound is enabled by default again.

This commit is contained in:
Allanis 2013-06-04 16:40:30 +01:00
parent 2ac26a5aed
commit f191a1d824
2 changed files with 12 additions and 22 deletions

View File

@ -84,7 +84,7 @@ void conf_setDefaults(void) {
gl_screen.h = 600; gl_screen.h = 600;
gl_screen.flags = 0; gl_screen.flags = 0;
// Openal. // Openal.
nosound = 1; // TODO: make sound default when it's sane again. nosound = 0;
// Joystick. // Joystick.
indjoystick = -1; indjoystick = -1;
namjoystick = NULL; namjoystick = NULL;

View File

@ -78,11 +78,8 @@ static SDL_Thread* music_player = NULL;
static alSound* sound_list = NULL; static alSound* sound_list = NULL;
static int nsound_list = 0; static int nsound_list = 0;
typedef struct VoiceSource_ { // Struct to hold all the sources and currently attached voice.
ALuint source; // Allocated source. static ALuint* source_stack = NULL; // And it's stack.
ALuint voice; // Voice id.
} VoiceSource;
static VoiceSource* source_stack = NULL; // And it's stack.
static int source_nstack = 0; static int source_nstack = 0;
// Virtual voice. // Virtual voice.
@ -162,7 +159,6 @@ int sound_init(void) {
// Start the music server. // Start the music server.
music_init(); music_init();
#if 0
// Start allocating the sources - music has already taken this. // Start allocating the sources - music has already taken this.
alGetError(); // Another error clear. alGetError(); // Another error clear.
mem = 0; mem = 0;
@ -170,16 +166,14 @@ int sound_init(void) {
if(mem < source_nstack+1) { if(mem < source_nstack+1) {
// Allocate more memory. // Allocate more memory.
mem += 32; 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); alGenSources(1, &source_stack[source_nstack]);
source_stack[source_nstack].voice = 0;
source_nstack++; source_nstack++;
} }
// Use minimal ram. // Use minimal ram.
source_stack = realloc(source_stack, sizeof(VoiceSource) * source_nstack); source_stack = realloc(source_stack, sizeof(ALuint) * source_nstack);
#endif
// Debug magic. // Debug magic.
DEBUG("OpenAL: %s", device); DEBUG("OpenAL: %s", device);
@ -379,8 +373,7 @@ void sound_update(void) {
if(stat == AL_PLAYING) alSourceStop(voice->source); if(stat == AL_PLAYING) alSourceStop(voice->source);
// Clear it and get rid of it. // Clear it and get rid of it.
alDeleteSources(1, &voice->source); source_stack[source_nstack++] == voice->source; // throw it back.
voice->source = 0;
} }
// Delete from linked list. // Delete from linked list.
@ -417,14 +410,10 @@ static int voice_getSource(alVoice* voc) {
SDL_mutexP(sound_lock); SDL_mutexP(sound_lock);
// Try and grab a source. // Try and grab a source.
voc->source = 0; if(source_nstack > 0) { // We have the source.
alGenSources(1, &voc->source); // We must pull it from the free source vector.
err = alGetError(); voc->source = source_stack[--source_nstack];
if(err != AL_NO_ERROR) {
voc->source = 0;
ret = 1;
} else {
// Set the properties. // Set the properties.
alSourcei(voc->source, AL_BUFFER, voc->buffer); alSourcei(voc->source, AL_BUFFER, voc->buffer);
@ -447,7 +436,8 @@ static int voice_getSource(alVoice* voc) {
err = alGetError(); err = alGetError();
if(err == AL_NO_ERROR) voice_set(voc, VOICE_PLAYING); if(err == AL_NO_ERROR) voice_set(voc, VOICE_PLAYING);
else ret = 2; else ret = 2;
} } else
voc->source = 0;
SDL_mutexV(sound_lock); SDL_mutexV(sound_lock);
return ret; return ret;