[Fix] Fixed a few sound issues that have been around for some time.
This commit is contained in:
		
							parent
							
								
									1c0fb97b7f
								
							
						
					
					
						commit
						fc1215e4ad
					
				
							
								
								
									
										29
									
								
								src/sound.c
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								src/sound.c
									
									
									
									
									
								
							| @ -233,8 +233,6 @@ int sound_play(int sound) { | ||||
|   if((sound < 0) || (sound > sound_nlist)) | ||||
|     return -1; | ||||
| 
 | ||||
|   SDL_mutexP(voice_lock); | ||||
| 
 | ||||
|   v->channel = Mix_PlayChannel(-1, sound_list[sound].buffer, 0); | ||||
| 
 | ||||
|   if(v->channel < 0) | ||||
| @ -259,6 +257,7 @@ int sound_playPos(int sound, double x, double y) { | ||||
|   alVoice* v; | ||||
|   double angle, dist; | ||||
|   double px, py; | ||||
|   int idist; | ||||
| 
 | ||||
|   if(sound_disabled) return 0; | ||||
| 
 | ||||
| @ -284,7 +283,10 @@ int sound_playPos(int sound, double x, double y) { | ||||
|     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()); | ||||
|     return -1; | ||||
|   } | ||||
| @ -312,7 +314,6 @@ int sound_updatePos(int voice, double x, double y) { | ||||
| 
 | ||||
|   if(sound_disabled) return 0; | ||||
| 
 | ||||
|   SDL_mutexP(voice_lock); | ||||
| 
 | ||||
|   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) { | ||||
|       WARN("Unable to set sound position: %s", Mix_GetError()); | ||||
|       SDL_mutexV(voice_lock); | ||||
|       return -1; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   SDL_mutexV(voice_lock); | ||||
| 
 | ||||
|   return 0; | ||||
| } | ||||
| 
 | ||||
| @ -351,8 +349,6 @@ int sound_update(void) { | ||||
| 
 | ||||
|   if(voice_active == NULL) return 0; | ||||
| 
 | ||||
|   SDL_mutexP(voice_lock); | ||||
| 
 | ||||
|   /* The actualy control loop. */ | ||||
|   for(v = voice_active; v != NULL; v = v->next) { | ||||
|     /* Destroy and toss into pool. */ | ||||
| @ -383,8 +379,6 @@ int sound_update(void) { | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   SDL_mutexV(voice_lock); | ||||
| 
 | ||||
|   return 0; | ||||
| } | ||||
| 
 | ||||
| @ -399,15 +393,11 @@ void sound_stop(int voice) { | ||||
|    | ||||
|   if(sound_disabled) return; | ||||
| 
 | ||||
|   SDL_mutexP(voice_lock); | ||||
| 
 | ||||
|   v = voice_get(voice); | ||||
|   if(v != NULL) { | ||||
|     Mix_HaltChannel(v->channel); | ||||
|     v->state = VOICE_STOPPED; | ||||
|   } | ||||
| 
 | ||||
|   SDL_mutexV(voice_lock); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
| @ -642,15 +632,11 @@ void sound_stopGroup(int group) { | ||||
| static void voice_markStopped(int channel) { | ||||
|   alVoice* v; | ||||
| 
 | ||||
|   SDL_mutexP(voice_lock); | ||||
| 
 | ||||
|   for(v = voice_active; v != NULL; v = v->next) | ||||
|     if(v->channel == channel) { | ||||
|       v->state = VOICE_STOPPED; | ||||
|       break; | ||||
|     } | ||||
| 
 | ||||
|   SDL_mutexV(voice_lock); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
| @ -697,9 +683,9 @@ static int voice_add(alVoice* v) { | ||||
| 
 | ||||
|   /* Insert to the front of active voices. */ | ||||
|   tv = voice_active; | ||||
|   voice_active = v; | ||||
|   v->next = tv; | ||||
|   v->prev = NULL; | ||||
|   voice_active = v; | ||||
|   if(tv != NULL) | ||||
|     tv->prev = v; | ||||
|   return 0; | ||||
| @ -718,8 +704,9 @@ static alVoice* voice_get(int id) { | ||||
|   if(voice_active == NULL) return NULL; | ||||
| 
 | ||||
|   for(v = voice_active; v != NULL; v = v->next) | ||||
|     if(v->id == id) | ||||
|     if(v->id == id) { | ||||
|       return v; | ||||
|     } | ||||
|   return NULL; | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Allanis
						Allanis