[Fix] Fixed a few sound issues that have been around for some time.

This commit is contained in:
Allanis 2013-12-01 23:42:18 +00:00
parent 1c0fb97b7f
commit fc1215e4ad

View File

@ -233,8 +233,6 @@ int sound_play(int sound) {
if((sound < 0) || (sound > sound_nlist)) if((sound < 0) || (sound > sound_nlist))
return -1; return -1;
SDL_mutexP(voice_lock);
v->channel = Mix_PlayChannel(-1, sound_list[sound].buffer, 0); v->channel = Mix_PlayChannel(-1, sound_list[sound].buffer, 0);
if(v->channel < 0) if(v->channel < 0)
@ -259,6 +257,7 @@ int sound_playPos(int sound, double x, double y) {
alVoice* v; alVoice* v;
double angle, dist; double angle, dist;
double px, py; double px, py;
int idist;
if(sound_disabled) return 0; if(sound_disabled) return 0;
@ -284,7 +283,10 @@ int sound_playPos(int sound, double x, double y) {
return -1; return -1;
} }
if(Mix_SetPosition(v->channel, (int)angle, (int)dist/10) < 0) { /* Need to make sure distance doesn't overflow. */
idist = dist / 4;
if(idist > 255) idist == 255;
if(Mix_SetPosition(v->channel, (int)angle, idist) < 0) {
WARN("Unable to set sound position: %s", Mix_GetError()); WARN("Unable to set sound position: %s", Mix_GetError());
return -1; return -1;
} }
@ -312,7 +314,6 @@ int sound_updatePos(int voice, double x, double y) {
if(sound_disabled) return 0; if(sound_disabled) return 0;
SDL_mutexP(voice_lock);
v = voice_get(voice); v = voice_get(voice);
@ -328,13 +329,10 @@ int sound_updatePos(int voice, double x, double y) {
if(Mix_SetPosition(v->channel, (int)angle, (int)dist/10) < 0) { if(Mix_SetPosition(v->channel, (int)angle, (int)dist/10) < 0) {
WARN("Unable to set sound position: %s", Mix_GetError()); WARN("Unable to set sound position: %s", Mix_GetError());
SDL_mutexV(voice_lock);
return -1; return -1;
} }
} }
SDL_mutexV(voice_lock);
return 0; return 0;
} }
@ -351,8 +349,6 @@ int sound_update(void) {
if(voice_active == NULL) return 0; if(voice_active == NULL) return 0;
SDL_mutexP(voice_lock);
/* The actualy control loop. */ /* The actualy control loop. */
for(v = voice_active; v != NULL; v = v->next) { for(v = voice_active; v != NULL; v = v->next) {
/* Destroy and toss into pool. */ /* Destroy and toss into pool. */
@ -383,8 +379,6 @@ int sound_update(void) {
} }
} }
SDL_mutexV(voice_lock);
return 0; return 0;
} }
@ -399,15 +393,11 @@ void sound_stop(int voice) {
if(sound_disabled) return; if(sound_disabled) return;
SDL_mutexP(voice_lock);
v = voice_get(voice); v = voice_get(voice);
if(v != NULL) { if(v != NULL) {
Mix_HaltChannel(v->channel); Mix_HaltChannel(v->channel);
v->state = VOICE_STOPPED; v->state = VOICE_STOPPED;
} }
SDL_mutexV(voice_lock);
} }
/** /**
@ -642,15 +632,11 @@ void sound_stopGroup(int group) {
static void voice_markStopped(int channel) { static void voice_markStopped(int channel) {
alVoice* v; alVoice* v;
SDL_mutexP(voice_lock);
for(v = voice_active; v != NULL; v = v->next) for(v = voice_active; v != NULL; v = v->next)
if(v->channel == channel) { if(v->channel == channel) {
v->state = VOICE_STOPPED; v->state = VOICE_STOPPED;
break; break;
} }
SDL_mutexV(voice_lock);
} }
/** /**
@ -697,9 +683,9 @@ static int voice_add(alVoice* v) {
/* Insert to the front of active voices. */ /* Insert to the front of active voices. */
tv = voice_active; tv = voice_active;
voice_active = v;
v->next = tv; v->next = tv;
v->prev = NULL; v->prev = NULL;
voice_active = v;
if(tv != NULL) if(tv != NULL)
tv->prev = v; tv->prev = v;
return 0; return 0;
@ -718,8 +704,9 @@ static alVoice* voice_get(int id) {
if(voice_active == NULL) return NULL; if(voice_active == NULL) return NULL;
for(v = voice_active; v != NULL; v = v->next) for(v = voice_active; v != NULL; v = v->next)
if(v->id == id) if(v->id == id) {
return v; return v;
}
return NULL; return NULL;
} }