From cd36be16a14ad104f12131e27f97ec238fd1da16 Mon Sep 17 00:00:00 2001
From: jsalmon3 <>
Date: Wed, 1 Oct 2003 22:56:21 +0000
Subject: [PATCH] Cleanup

---
 src/sound/oss_audio.cpp    |  70 +++---
 src/sound/sdl_audio.cpp    |   8 +-
 src/sound/sound.cpp        | 188 ++++++++-------
 src/sound/sound_id.cpp     |  28 +--
 src/sound/sound_server.cpp | 455 +++++++++++++++++++------------------
 5 files changed, 373 insertions(+), 376 deletions(-)

diff --git a/src/sound/oss_audio.cpp b/src/sound/oss_audio.cpp
index 69085adba..40066c92b 100644
--- a/src/sound/oss_audio.cpp
+++ b/src/sound/oss_audio.cpp
@@ -10,7 +10,7 @@
 //
 /**@name oss_audio.c		-	Oss hardware support */
 //
-//	(c) Copyright 2002 by Lutz Sammer and Fabrice Rossi
+//	(c) Copyright 2002-2003 by Lutz Sammer and Fabrice Rossi
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -68,44 +68,44 @@
 **
 **	@return		True if failure, false if everything ok.
 */
-global int InitOssSound(const char* dev,int freq,int size,int wait)
+global int InitOssSound(const char* dev, int freq, int size, int wait)
 {
     int dummy;
 
     //
     //	Open dsp device, 8bit samples, stereo.
     //
-    if( wait ) {
-	SoundFildes=open(dev,O_WRONLY);
+    if (wait) {
+	SoundFildes = open(dev, O_WRONLY);
     } else {
-	SoundFildes=open(dev,O_WRONLY|O_NDELAY);
+	SoundFildes = open(dev, O_WRONLY | O_NDELAY);
     }
-    if( SoundFildes==-1 ) {
-	fprintf(stderr,"Can't open audio device `%s'\n",dev);
+    if (SoundFildes == -1) {
+	fprintf(stderr, "Can't open audio device `%s'\n", dev);
 	return 1;
     }
-    dummy=size;
-    if( ioctl(SoundFildes,SNDCTL_DSP_SAMPLESIZE,&dummy)==-1 ) {
+    dummy = size;
+    if (ioctl(SoundFildes, SNDCTL_DSP_SAMPLESIZE, &dummy) == -1) {
 	PrintFunction();
-	fprintf(stdout,"%s - ioctl(SNDCTL_DSP_SAMPLESIZE)", strerror(errno));
+	fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SAMPLESIZE)", strerror(errno));
 	close(SoundFildes);
-	SoundFildes=-1;
+	SoundFildes = -1;
 	return 1;
     }
-    dummy=1;
-    if( ioctl(SoundFildes,SNDCTL_DSP_STEREO,&dummy)==-1 ) {
+    dummy = 1;
+    if (ioctl(SoundFildes, SNDCTL_DSP_STEREO, &dummy) == -1) {
 	PrintFunction();
-	fprintf(stdout,"%s - ioctl(SNDCTL_DSP_STEREO)", strerror(errno));
+	fprintf(stdout, "%s - ioctl(SNDCTL_DSP_STEREO)", strerror(errno));
 	close(SoundFildes);
-	SoundFildes=-1;
+	SoundFildes = -1;
 	return 1;
     }
-    dummy=freq;
-    if( ioctl(SoundFildes,SNDCTL_DSP_SPEED,&dummy)==-1 ) {
+    dummy = freq;
+    if (ioctl(SoundFildes, SNDCTL_DSP_SPEED, &dummy) == -1) {
 	PrintFunction();
-	fprintf(stdout,"%s - ioctl(SNDCTL_DSP_SPEED)", strerror(errno));
+	fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SPEED)", strerror(errno));
 	close(SoundFildes);
-	SoundFildes=-1;
+	SoundFildes = -1;
 	return 1;
     }
     //
@@ -113,52 +113,52 @@ global int InitOssSound(const char* dev,int freq,int size,int wait)
     //
     // FIXME: higher speed more buffers!!
 
-    switch( freq ) {
+    switch (freq) {
 	case 11025:
-	    dummy=((8<<16) |  8);   // 8 Buffers of  256 Bytes
+	    dummy=((8 << 16) |  8);   // 8 Buffers of  256 Bytes
 	    break;
 	case 22050:
-	    dummy=((8<<16) |  9);   // 8 Buffers of  512 Bytes
+	    dummy=((8 << 16) |  9);   // 8 Buffers of  512 Bytes
 	    break;
 	default:
 	    DebugLevel0Fn("Unexpected sample frequency %d\n" _C_ freq);
 	    // FALL THROUGH
 	case 44100:
-	    dummy=((8<<16) | 10);   // 8 Buffers of 1024 Bytes
+	    dummy=((8 << 16) | 10);   // 8 Buffers of 1024 Bytes
 	    break;
     }
-    if( size==16 ) {			//  8 bit
+    if (size == 16) {			//  8 bit
 	++dummy;			// double buffer size
     }
 
     DebugLevel0Fn("%d bytes %d ms buffer\n" _C_ freq*size/8 _C_ 
-	((dummy>>16)*(1<<(dummy&0xFFFF))*1000)/(freq*size/8));
+	((dummy >> 16) * (1 << (dummy & 0xFFFF)) * 1000) / (freq * size / 8));
 
-    if( ioctl(SoundFildes,SNDCTL_DSP_SETFRAGMENT,&dummy)==-1 ) {
+    if (ioctl(SoundFildes, SNDCTL_DSP_SETFRAGMENT, &dummy) == -1) {
 	PrintFunction();
-	fprintf(stdout,"%s - ioctl(SNDCTL_DSP_SETFRAGMENT)", strerror(errno));
+	fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SETFRAGMENT)", strerror(errno));
 	close(SoundFildes);
-	SoundFildes=-1;
+	SoundFildes = -1;
 	return 1;
     }
 
 #if 0
-    dummy=4;
-    if( ioctl(SoundFildes,SNDCTL_DSP_SUBDIVIDE,&dummy)==-1 ) {
+    dummy = 4;
+    if (ioctl(SoundFildes, SNDCTL_DSP_SUBDIVIDE, &dummy) == -1) {
 	PrintFunction();
-	fprintf(stdout,"%s - ioctl(SNDCTL_DSP_SUBDIVIDE)", strerror(errno));
+	fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SUBDIVIDE)", strerror(errno));
 	close(SoundFildes);
-	SoundFildes=-1;
+	SoundFildes = -1;
 	return;
     }
 #endif
 
 #ifdef DEBUG
-    if( ioctl(SoundFildes,SNDCTL_DSP_GETBLKSIZE,&dummy)==-1 ) {
+    if (ioctl(SoundFildes, SNDCTL_DSP_GETBLKSIZE, &dummy) == -1) {
 	PrintFunction();
-	fprintf(stdout,"%s - ioctl(SNDCTL_DSP_GETBLKSIZE)", strerror(errno));
+	fprintf(stdout, "%s - ioctl(SNDCTL_DSP_GETBLKSIZE)", strerror(errno));
 	close(SoundFildes);
-	SoundFildes=-1;
+	SoundFildes = -1;
 	return 1;
     }
 
diff --git a/src/sound/sdl_audio.cpp b/src/sound/sdl_audio.cpp
index e7c5d944e..4d7ae9915 100644
--- a/src/sound/sdl_audio.cpp
+++ b/src/sound/sdl_audio.cpp
@@ -10,7 +10,7 @@
 //
 /**@name sdl_audio.c		-	SDL hardware support */
 //
-//	(c) Copyright 2002 by Lutz Sammer and Fabrice Rossi
+//	(c) Copyright 2002-2003 by Lutz Sammer and Fabrice Rossi
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -48,8 +48,8 @@
 ----------------------------------------------------------------------------*/
 
     /// FIXME: move function to here.
-extern void FillAudio(void* udata __attribute__((unused)),Uint8* stream,
-	int len);
+extern void FillAudio(void* udata __attribute__((unused)), Uint8* stream,
+    int len);
 
 /**
 **	Initialize sound card hardware part with SDL.
@@ -62,7 +62,7 @@ extern void FillAudio(void* udata __attribute__((unused)),Uint8* stream,
 **	@return		True if failure, false if everything ok.
 */
 global int InitSdlSound(const char* dev __attribute__((unused)), int freq,
-	int size, int wait __attribute__((unused)))
+    int size, int wait __attribute__((unused)))
 {
     SDL_AudioSpec wanted;
 
diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp
index 7a5b4e09a..7811852cd 100644
--- a/src/sound/sound.cpp
+++ b/src/sound/sound.cpp
@@ -108,43 +108,43 @@ global GameSound GameSounds
 **	@param volume	FIXME: docu
 **	@param stereo	FIXME: docu
 */
-local void InsertSoundRequest(const Unit* unit,unsigned id,unsigned char power,
-			      SoundId sound,unsigned char fight,
-			      unsigned char selection,unsigned char volume,
-			      char stereo) 
+local void InsertSoundRequest(const Unit* unit, unsigned id,
+    unsigned char power, SoundId sound, unsigned char fight,
+    unsigned char selection, unsigned char volume, char stereo) 
 {
 #ifdef USE_SDLA
     SDL_LockAudio();
 #endif
     //FIXME: valid only in a shared memory context...
-    if( !SoundOff && sound != NO_SOUND ) {
+    if (!SoundOff && sound != NO_SOUND) {
 	if (SoundRequests[NextSoundRequestIn].Used) {
 	    DebugLevel0("***** NO FREE SLOT IN SOUND FIFO *****\n");
 	} else {
-	    SoundRequests[NextSoundRequestIn].Used=1;
-	    SoundRequests[NextSoundRequestIn].Source.Base=unit;
-	    SoundRequests[NextSoundRequestIn].Source.Id=id;
-	    SoundRequests[NextSoundRequestIn].Sound=sound;
-	    SoundRequests[NextSoundRequestIn].Power=power;
-	    SoundRequests[NextSoundRequestIn].Fight=(fight)?1:0;
-	    SoundRequests[NextSoundRequestIn].Selection=(selection)?1:0;
-	    SoundRequests[NextSoundRequestIn].IsVolume=(volume)?1:0;
-	    SoundRequests[NextSoundRequestIn].Stereo=stereo;
+	    SoundRequests[NextSoundRequestIn].Used = 1;
+	    SoundRequests[NextSoundRequestIn].Source.Base = unit;
+	    SoundRequests[NextSoundRequestIn].Source.Id = id;
+	    SoundRequests[NextSoundRequestIn].Sound = sound;
+	    SoundRequests[NextSoundRequestIn].Power = power;
+	    SoundRequests[NextSoundRequestIn].Fight = fight ? 1 : 0;
+	    SoundRequests[NextSoundRequestIn].Selection = selection ? 1 : 0;
+	    SoundRequests[NextSoundRequestIn].IsVolume = volume ? 1 : 0;
+	    SoundRequests[NextSoundRequestIn].Stereo = stereo;
 	    DebugLevel3("Source[%p,%s]: registering request %p at slot %d=%d\n" _C_
-			unit _C_ unit ? unit->Type->Ident : ""
-			_C_ sound _C_ NextSoundRequestIn _C_ power);
+		unit _C_ unit ? unit->Type->Ident : "" _C_
+		sound _C_ NextSoundRequestIn _C_ power);
 #ifdef USE_THREAD
 	    // increment semaphore
 	    if (SoundThreadRunning) {
-		if(sem_post(&SoundThreadChannelSemaphore)) {
+		if (sem_post(&SoundThreadChannelSemaphore)) {
 		    DebugLevel0("Cannot increment semaphore!\n");
 		    //FIXME: need to quit?
 		}
 	    }
 #endif
-	    NextSoundRequestIn++;
-	    if (NextSoundRequestIn>=MAX_SOUND_REQUESTS)
-		NextSoundRequestIn=0;
+	    ++NextSoundRequestIn;
+	    if (NextSoundRequestIn >= MAX_SOUND_REQUESTS) {
+		NextSoundRequestIn = 0;
+	    }
 	}
     }
 #ifdef USE_SDLA
@@ -162,31 +162,31 @@ local void InsertSoundRequest(const Unit* unit,unsigned id,unsigned char power,
 **
 **	@todo FIXME: The work completed sounds only supports two races.
 */
-local SoundId ChooseUnitVoiceSoundId(const Unit *unit,UnitVoiceGroup voice)
+local SoundId ChooseUnitVoiceSoundId(const Unit* unit, UnitVoiceGroup voice)
 {
     switch (voice) {
-    case VoiceAcknowledging:
-	return unit->Type->Sound.Acknowledgement.Sound;
-    case VoiceReady:
-	return unit->Type->Sound.Ready.Sound;
-    case VoiceSelected:
-	return unit->Type->Sound.Selected.Sound;
-    case VoiceAttacking:
-	return unit->Type->Weapon.Attack.Sound;
-    case VoiceHelpMe:
-	return unit->Type->Sound.Help.Sound;
-    case VoiceDying:
-	return unit->Type->Sound.Dead.Sound;
-    case VoiceTreeChopping:
-	return GameSounds.TreeChopping.Sound;
-    case VoiceWorkCompleted:
-	return GameSounds.WorkComplete[ThisPlayer->Race].Sound;
-    case VoiceBuilding:
-	return GameSounds.BuildingConstruction.Sound;
-    case VoiceDocking:
-	return GameSounds.Docking.Sound;
-    case VoiceRepair:
-	return GameSounds.Repair.Sound;
+	case VoiceAcknowledging:
+	    return unit->Type->Sound.Acknowledgement.Sound;
+	case VoiceReady:
+	    return unit->Type->Sound.Ready.Sound;
+	case VoiceSelected:
+	    return unit->Type->Sound.Selected.Sound;
+	case VoiceAttacking:
+	    return unit->Type->Weapon.Attack.Sound;
+	case VoiceHelpMe:
+	    return unit->Type->Sound.Help.Sound;
+	case VoiceDying:
+	    return unit->Type->Sound.Dead.Sound;
+	case VoiceTreeChopping:
+	    return GameSounds.TreeChopping.Sound;
+	case VoiceWorkCompleted:
+	    return GameSounds.WorkComplete[ThisPlayer->Race].Sound;
+	case VoiceBuilding:
+	    return GameSounds.BuildingConstruction.Sound;
+	case VoiceDocking:
+	    return GameSounds.Docking.Sound;
+	case VoiceRepair:
+	    return GameSounds.Repair.Sound;
     }
     return NULL;
 }
@@ -203,9 +203,9 @@ global void PlayUnitSound(const Unit* unit, UnitVoiceGroup voice)
 {
     int stereo;
 
-    stereo = ((unit->X * TileSizeX + unit->Type->TileWidth * TileSizeX / 2
-	    + unit->IX - TheUI.SelectedViewport->MapX * TileSizeX) * 256
-		/ ((TheUI.SelectedViewport->MapWidth - 1) * TileSizeX)) - 128;
+    stereo = ((unit->X * TileSizeX + unit->Type->TileWidth * TileSizeX / 2 +
+	unit->IX - TheUI.SelectedViewport->MapX * TileSizeX) * 256 /
+	((TheUI.SelectedViewport->MapWidth - 1) * TileSizeX)) - 128;
     if (stereo < -128) {
 	stereo = -128;
     } else if (stereo > 127) {
@@ -227,9 +227,9 @@ global void PlayMissileSound(const Missile* missile, SoundId sound)
 {
     int stereo;
 
-    stereo = ((missile->X + missile->Type->Width / 2
-	    - TheUI.SelectedViewport->MapX * TileSizeX) * 256
-		/ ((TheUI.SelectedViewport->MapWidth - 1) * TileSizeX)) - 128;
+    stereo = ((missile->X + missile->Type->Width / 2 -
+	TheUI.SelectedViewport->MapX * TileSizeX) * 256 /
+	((TheUI.SelectedViewport->MapWidth - 1) * TileSizeX)) - 128;
     if (stereo < -128) {
 	stereo = -128;
     } else if (stereo > 127) {
@@ -243,17 +243,10 @@ global void PlayMissileSound(const Missile* missile, SoundId sound)
 /**
 **	FIXME: docu
 */
-global void PlayGameSound(SoundId sound,unsigned char volume)
+global void PlayGameSound(SoundId sound, unsigned char volume)
 {
     DebugLevel3("Playing %p at volume %u\n" _C_ sound _C_ volume);
-    InsertSoundRequest(NULL,
-		       0,
-		       volume,
-		       sound,
-		       0,
-		       0,
-		       1,
-		       0);
+    InsertSoundRequest(NULL, 0, volume, sound, 0, 0, 1, 0);
 }
 
 /**
@@ -268,12 +261,12 @@ global void SetGlobalVolume(int volume)
     //FIXME: we use here the fact that we are in a shared memory context. This
     // should send a message to the sound server
     // silently discard out of range values
-    if ( volume<0 ) {
-	GlobalVolume=0;
-    } else if ( volume>MaxVolume ) {
-	GlobalVolume=MaxVolume;
+    if (volume < 0) {
+	GlobalVolume = 0;
+    } else if (volume > MaxVolume) {
+	GlobalVolume = MaxVolume;
     } else {
-	GlobalVolume=volume;
+	GlobalVolume = volume;
     }
 }
 
@@ -290,12 +283,12 @@ global void SetMusicVolume(int volume)
     // should send a message to the sound server
 
     // silently discard out of range values
-    if ( volume<0 ) {
-	MusicVolume=0;
-    } else if ( volume>MaxVolume ) {
-	MusicVolume=MaxVolume;
+    if (volume < 0) {
+	MusicVolume = 0;
+    } else if (volume > MaxVolume) {
+	MusicVolume = MaxVolume;
     } else {
-	MusicVolume=volume;
+	MusicVolume = volume;
     }
 }
 
@@ -306,48 +299,49 @@ global void InitSoundClient(void)
 {
     int i;
 
-    if( SoundFildes==-1 ) {		// No sound enabled
+    if (SoundFildes == -1) {		// No sound enabled
 	return;
     }
     // let's map game sounds, look if already setup in ccl.
 
-    if( !GameSounds.PlacementError.Sound ) {
-	GameSounds.PlacementError.Sound=
-		SoundIdForName(GameSounds.PlacementError.Name);
+    if (!GameSounds.PlacementError.Sound) {
+	GameSounds.PlacementError.Sound =
+	    SoundIdForName(GameSounds.PlacementError.Name);
     }
-    if( !GameSounds.PlacementSuccess.Sound ) {
-	GameSounds.PlacementSuccess.Sound=
-		SoundIdForName(GameSounds.PlacementSuccess.Name);
+    if (!GameSounds.PlacementSuccess.Sound) {
+	GameSounds.PlacementSuccess.Sound =
+	    SoundIdForName(GameSounds.PlacementSuccess.Name);
     }
-    if( !GameSounds.Click.Sound ) {
-	GameSounds.Click.Sound=SoundIdForName(GameSounds.Click.Name);
+    if (!GameSounds.Click.Sound) {
+	GameSounds.Click.Sound = SoundIdForName(GameSounds.Click.Name);
     }
-    if( !GameSounds.TreeChopping.Sound ) {
-	GameSounds.TreeChopping.Sound=
-		SoundIdForName(GameSounds.TreeChopping.Name);
+    if (!GameSounds.TreeChopping.Sound) {
+	GameSounds.TreeChopping.Sound =
+	    SoundIdForName(GameSounds.TreeChopping.Name);
     }
-    if( !GameSounds.Docking.Sound ) {
-	GameSounds.Docking.Sound=
-		SoundIdForName(GameSounds.Docking.Name);
+    if (!GameSounds.Docking.Sound) {
+	GameSounds.Docking.Sound =
+	    SoundIdForName(GameSounds.Docking.Name);
     }
-    if( !GameSounds.BuildingConstruction.Sound ) {
-	GameSounds.BuildingConstruction.Sound=
-		SoundIdForName(GameSounds.BuildingConstruction.Name);
+    if (!GameSounds.BuildingConstruction.Sound) {
+	GameSounds.BuildingConstruction.Sound =
+	    SoundIdForName(GameSounds.BuildingConstruction.Name);
     }
-    for( i=0; i<PlayerRaces.Count; ++i ) {
-	if( !GameSounds.WorkComplete[i].Sound && GameSounds.WorkComplete[i].Name ) {
-	    GameSounds.WorkComplete[i].Sound=
-		    SoundIdForName(GameSounds.WorkComplete[i].Name);
+    for (i = 0; i < PlayerRaces.Count; ++i) {
+	if (!GameSounds.WorkComplete[i].Sound &&
+		GameSounds.WorkComplete[i].Name) {
+	    GameSounds.WorkComplete[i].Sound =
+		SoundIdForName(GameSounds.WorkComplete[i].Name);
 	}
     }
-    if( !GameSounds.Repair.Sound ) {
-	GameSounds.Repair.Sound=
-		SoundIdForName(GameSounds.Repair.Name);
+    if (!GameSounds.Repair.Sound) {
+	GameSounds.Repair.Sound =
+	    SoundIdForName(GameSounds.Repair.Name);
     }
-    for( i=0; i<PlayerRaces.Count; ++i ) {
-	if( !GameSounds.Rescue[i].Sound && GameSounds.Rescue[i].Name ) {
-	    GameSounds.Rescue[i].Sound=
-		    SoundIdForName(GameSounds.Rescue[i].Name);
+    for (i = 0; i < PlayerRaces.Count; ++i) {
+	if (!GameSounds.Rescue[i].Sound && GameSounds.Rescue[i].Name) {
+	    GameSounds.Rescue[i].Sound =
+		SoundIdForName(GameSounds.Rescue[i].Name);
 	}
     }
 }
diff --git a/src/sound/sound_id.cpp b/src/sound/sound_id.cpp
index adf2fe1f7..c681fedd1 100644
--- a/src/sound/sound_id.cpp
+++ b/src/sound/sound_id.cpp
@@ -62,7 +62,7 @@ local int SoundIdHash[61];
 /**
 **	hash table used to store the mapping between sound name and sound id
 */
-local hashtable(int,61) SoundIdHash;
+local hashtable(int, 61) SoundIdHash;
 
 #endif
 
@@ -97,9 +97,9 @@ global void DisplaySoundHashTable(void)
 **	@param name	Name of the sound (now freed by caller!).
 **	@param id	Sound identifier.
 */
-global void MapSound(const char* name,const SoundId id)
+global void MapSound(const char* name, const SoundId id)
 {
-    *((SoundId*)hash_add(SoundIdHash,(char*)name))=id;
+    *((SoundId*)hash_add(SoundIdHash, (char*)name)) = id;
 }
 
 /**
@@ -113,9 +113,9 @@ global SoundId SoundIdForName(const char* name)
 {
     const SoundId* result;
 
-    DebugCheck( !name );
+    DebugCheck(!name);
 
-    if( (result=(const SoundId*)hash_find(SoundIdHash,(char*)name)) ) {
+    if ((result = (const SoundId*)hash_find(SoundIdHash, (char*)name))) {
 	return *result;
     }
     DebugLevel0("Can't find sound `%s' in sound table\n" _C_ name);
@@ -134,22 +134,22 @@ global SoundId SoundIdForName(const char* name)
 **
 **	@return the sound id of the created group
 */
-global SoundId MakeSound(const char* name,char* file[],int nb)
+global SoundId MakeSound(const char* name, char* file[], int nb)
 {
     SoundId id;
     const SoundId* result;
 
-    DebugCheck( nb>255 );
+    DebugCheck(nb > 255);
 
-    if ( (result=(const SoundId*)hash_find(SoundIdHash,(char*)name)) ) {
+    if ((result = (const SoundId*)hash_find(SoundIdHash, (char*)name))) {
 	DebugLevel0Fn("re-register sound `%s'\n" _C_ name);
 	return *result;
     }
 
     // ask the server to register the sound
-    id=RegisterSound(file,nb);
+    id = RegisterSound(file, nb);
     // save the mapping from name to id in the hash table.
-    MapSound(name,id);
+    MapSound(name, id);
     return id;
 }
 
@@ -166,18 +166,18 @@ global SoundId MakeSound(const char* name,char* file[],int nb)
 **
 **	@return		Registered sound identifier.
 */
-global SoundId MakeSoundGroup(const char* name,SoundId first,SoundId second)
+global SoundId MakeSoundGroup(const char* name, SoundId first, SoundId second)
 {
     SoundId sound;
     const SoundId* result;
 
-    if ( (result=(const SoundId*)hash_find(SoundIdHash,(char*)name)) ) {
+    if ((result = (const SoundId*)hash_find(SoundIdHash, (char*)name))) {
 	DebugLevel0Fn("re-register sound `%s'\n" _C_ name);
 	return *result;
     }
 
-    sound=RegisterTwoGroups(first,second);
-    MapSound(name,sound);
+    sound=RegisterTwoGroups(first, second);
+    MapSound(name, sound);
 
     return sound;
 }
diff --git a/src/sound/sound_server.cpp b/src/sound/sound_server.cpp
index 2531bb56f..71b3a5f78 100644
--- a/src/sound/sound_server.cpp
+++ b/src/sound/sound_server.cpp
@@ -115,8 +115,8 @@ global unsigned AllocatedSoundMemory;	/// memory used by sound
 global unsigned CompressedSoundMemory;	/// compressed memory used by sound
 #endif
 
-global int GlobalVolume=128;		/// global sound volume
-global int MusicVolume=128;		/// music volume
+global int GlobalVolume = 128;		/// global sound volume
+global int MusicVolume = 128;		/// music volume
 
 global int DistanceSilent;		/// silent distance
 
@@ -216,7 +216,7 @@ global void StopMusic(void)
 }
 
 /// Dummy functions if no music support is enabled
-#define MixMusicToStereo32(buffer,size)
+#define MixMusicToStereo32(buffer, size)
 
 #endif
 
@@ -243,7 +243,7 @@ global void StopMusic(void)
 **	@todo		Can combine stereo and volume for faster operation.
 */
 local int MixSampleToStereo32(Sample* sample,int index,unsigned char volume,
-			      char stereo,int* buffer,int size)
+    char stereo, int* buffer, int size)
 {
     int ri;				// read index
     int wi;				// write index
@@ -253,64 +253,64 @@ local int MixSampleToStereo32(Sample* sample,int index,unsigned char volume,
     unsigned char left;
     unsigned char right;
 
-    local_volume=((int)volume+1)*2*GlobalVolume/MaxVolume;
-    length=sample->Length-index;
-    if( stereo < 0 ) {
-	left=128;
-	right=128+stereo;
+    local_volume = ((int)volume + 1) * 2 * GlobalVolume / MaxVolume;
+    length = sample->Length - index;
+    if (stereo < 0) {
+	left = 128;
+	right = 128 + stereo;
     }
     else {
-	left=128-stereo;
-	right=128;
+	left = 128 - stereo;
+	right = 128;
     }
     DebugLevel3("Length %d\n" _C_ length);
 
     // FIXME: support other formats, stereo or 32 bit ...
 
-    if( sample->SampleSize==8 ) {
+    if (sample->SampleSize == 8) {
 	unsigned char* rp;
 
-	rp=sample->Data+index;
-	if( (size*sample->Frequency)/SoundFrequency/2>length ) {
-	    size=(length*SoundFrequency/sample->Frequency)*2;
+	rp = sample->Data + index;
+	if ((size * sample->Frequency) / SoundFrequency / 2 > length) {
+	    size = (length * SoundFrequency / sample->Frequency) * 2;
 	}
 
 	// mix mono, 8 bit sound to stereo, 32 bit
-	for( ri=wi=0; wi<size; ) {
-	    ri=(wi*sample->Frequency)/SoundFrequency;
-	    ri/=2;			// adjust for mono
+	for (ri = wi = 0; wi < size;) {
+	    ri = (wi * sample->Frequency) / SoundFrequency;
+	    ri /= 2;			// adjust for mono
 
 	    // FIXME: must interpolate samples!
-	    v=(rp[ri]-127)*local_volume;
+	    v = (rp[ri] - 127) * local_volume;
 
-	    buffer[wi++]+=v*left/128;
-	    buffer[wi++]+=v*right/128;	// left+right channel
+	    buffer[wi++] += v * left / 128;
+	    buffer[wi++] += v * right / 128;	// left+right channel
 	}
-	ri=(wi*sample->Frequency)/SoundFrequency;
-	ri/=2;				// adjust for mono
+	ri = (wi * sample->Frequency) / SoundFrequency;
+	ri /= 2;				// adjust for mono
 	DebugLevel3("Mixed %d bytes to %d\n" _C_ ri _C_ wi);
     } else {
 	short* rp;
 
-	DebugCheck( index&1 );
+	DebugCheck(index & 1);
 
-	rp=(short*)(sample->Data+index);
-	if( (size*sample->Frequency)/SoundFrequency>length ) {
-	    size=(length*SoundFrequency/sample->Frequency);
+	rp = (short*)(sample->Data + index);
+	if ((size * sample->Frequency) / SoundFrequency > length) {
+	    size = (length * SoundFrequency / sample->Frequency);
 	}
 
 	// mix mono, 16 bit sound to stereo, 32 bit
-	for( ri=wi=0; wi<size; ) {
-	    ri=(wi*sample->Frequency)/SoundFrequency;
-	    ri/=2;			// adjust for mono
+	for (ri = wi = 0; wi < size;) {
+	    ri = (wi * sample->Frequency) / SoundFrequency;
+	    ri /= 2;			// adjust for mono
 
 	    // FIXME: must interpolate samples!
-	    v=rp[ri]*local_volume/256;
+	    v = rp[ri] * local_volume / 256;
 
-	    buffer[wi++]+=v*left/128;
-	    buffer[wi++]+=v*right/128;
+	    buffer[wi++] += v * left / 128;
+	    buffer[wi++] += v * right / 128;
 	}
-	ri=(wi*sample->Frequency)/SoundFrequency;
+	ri = (wi * sample->Frequency) / SoundFrequency;
     }
 
     return ri;
@@ -329,7 +329,7 @@ local int MixSampleToStereo32(Sample* sample,int index,unsigned char volume,
 **
 **	@return		Number of bytes written in 'dest'
 */
-global int ConvertToStereo32(const char *src, char *dest, int frequency, 
+global int ConvertToStereo32(const char* src, char* dest, int frequency, 
     int chansize, int channels, int bytes)
 {
     int s;			// sample index
@@ -353,7 +353,7 @@ global int ConvertToStereo32(const char *src, char *dest, int frequency,
 	for (c = 0; c < 2; ++c) {
 	    offset = (((s / 4) / freqratio) * samplesize + (c / chanratio) * chansize);
 	    if (chansize == 2) {
-		*(short *)(dest + s + c*2) = *(short *)(src + offset);
+		*(short*)(dest + s + c * 2) = *(short*)(src + offset);
 	    } else {
 		*(dest + s + c * 2) = *(src + offset) + 128;
 		*(dest + s + c * 2 + 1) = *(src + offset) + 128;
@@ -386,7 +386,7 @@ SelectionHandling SelectionHandler;
 #ifdef USE_GLIB
 local GHashTable* UnitToChannel;
 #else
-//local hashtable(int,61) UnitToChannel;
+//local hashtable(int, 61) UnitToChannel;
 #endif
 
 /**
@@ -399,15 +399,16 @@ local int ViewPointOffset;
 */
 local int HowManyFree(void)
 {
-  int channel;
-  int nb;
-  nb=0;
-  channel=NextFreeChannel;
-  while(channel<MaxChannels) {
-      nb++;
-      channel=Channels[channel].Point;
-  }
-  return nb;
+    int channel;
+    int nb;
+
+    nb = 0;
+    channel = NextFreeChannel;
+    while(channel < MaxChannels) {
+	++nb;
+	channel = Channels[channel].Point;
+    }
+    return nb;
 }
 
 /*
@@ -417,14 +418,14 @@ local int KeepRequest(SoundRequest* sr) {
     //FIXME: take fight flag into account
     int channel;
 
-    if (sr->Sound==NO_SOUND) {
+    if (sr->Sound == NO_SOUND) {
 	return 0;
     }
 #ifdef USE_GLIB
-    if ( (channel=(int)(long)g_hash_table_lookup(UnitToChannel,
-				      (gpointer)(sr->Source.Base))) ) {
-	channel--;
-	if (Channels[channel].Source.Id==sr->Source.Id) {
+    if ((channel = (int)(long)g_hash_table_lookup(UnitToChannel,
+	    (gpointer)(sr->Source.Base)))) {
+	--channel;
+	if (Channels[channel].Source.Id == sr->Source.Id) {
 	    //FIXME: decision should take into account the sound
 	    return 0;
 	}
@@ -432,19 +433,19 @@ local int KeepRequest(SoundRequest* sr) {
     }
 #else
     {
-	const SoundChannel *theChannel;
+	const SoundChannel* theChannel;
 
 	// slow but working solution: we look for the source in the channels
-	theChannel=Channels;
-	for(channel=0;channel<MaxChannels;channel++) {
-	    if ((*theChannel).Command == ChannelPlay
-		    && (*theChannel).Source.Base==sr->Source.Base
-		    && (*theChannel).Sound==sr->Sound
-		    && (*theChannel).Source.Id==sr->Source.Id) {
+	theChannel = Channels;
+	for (channel = 0; channel < MaxChannels; ++channel) {
+	    if ((*theChannel).Command == ChannelPlay &&
+		    (*theChannel).Source.Base == sr->Source.Base &&
+		    (*theChannel).Sound == sr->Sound &&
+		    (*theChannel).Source.Id == sr->Source.Id) {
 		//FIXME: decision should take into account the sound
 		return 0;
 	    }
-	    theChannel++;
+	    ++theChannel;
 	}
     }
 #endif
@@ -454,21 +455,21 @@ local int KeepRequest(SoundRequest* sr) {
 /*
 ** Register the source of a request in the selection handling hash table.
 */
-local void RegisterSource(SoundRequest* sr,int channel)
+local void RegisterSource(SoundRequest* sr, int channel)
 {
     // always keep the last registered channel
     // use channel+1 to avoid inserting null values
     //FIXME: we should use here the unique identifier of the source, not only
     // the pointer
 #ifdef USE_GLIB
-    g_hash_table_insert(UnitToChannel,(gpointer)(long)(sr->Source.Base),
-			(gpointer)(channel+1));
+    g_hash_table_insert(UnitToChannel, (gpointer)(long)(sr->Source.Base),
+	(gpointer)(channel+1));
 #else
     int i;
     void* p;
 
-    i=channel;
-    p=sr;
+    i = channel;
+    p = sr;
     DebugLevel3Fn("FIXME: must write %p -> %d\n" _C_ sr _C_ channel);
 #endif
     DebugLevel3("Registering %p (channel %d)\n" _C_ sr->Source.Base _C_ channel);
@@ -479,20 +480,19 @@ local void RegisterSource(SoundRequest* sr,int channel)
 */
 local void UnRegisterSource(int channel) {
 #ifdef USE_GLIB
-    if ( (int)(long)g_hash_table_lookup(UnitToChannel,
-				  (gpointer)(Channels[channel].Source.Base))
-	 ==channel+1) {
+    if ((int)(long)g_hash_table_lookup(UnitToChannel,
+	    (gpointer)(Channels[channel].Source.Base)) == channel + 1) {
 	g_hash_table_remove(UnitToChannel,
-			    (gpointer)(long)(Channels[channel].Source.Base));
+	    (gpointer)(long)(Channels[channel].Source.Base));
     }
 #else
     int i;
 
-    i=channel;
+    i = channel;
     DebugLevel3Fn("FIXME: must write %d\n" _C_ channel);
 #endif
-    DebugLevel3("Removing %p (channel %d)\n" _C_ Channels[channel].Source.Base _C_
-		channel);
+    DebugLevel3("Removing %p (channel %d)\n" _C_
+	Channels[channel].Source.Base _C_ channel);
 }
 
 /**
@@ -504,22 +504,24 @@ local void UnRegisterSource(int channel) {
 **
 **	@return		volume for given distance (0..??)
 */
-local unsigned char VolumeForDistance(unsigned short d,unsigned char range) {
+local unsigned char VolumeForDistance(unsigned short d, unsigned char range) {
     int d_tmp;
     int range_tmp;
+
     //FIXME: THIS IS SLOW!!!!!!!
-    if (d <= ViewPointOffset || range==INFINITE_SOUND_RANGE)
+    if (d <= ViewPointOffset || range==INFINITE_SOUND_RANGE) {
 	return MaxVolume;
-    else {
+    } else {
 	if (range) {
-	    d-=ViewPointOffset;
-	    d_tmp=d*MAX_SOUND_RANGE;
-	    range_tmp=DistanceSilent*range;
+	    d -= ViewPointOffset;
+	    d_tmp = d * MAX_SOUND_RANGE;
+	    range_tmp = DistanceSilent * range;
 	    DebugLevel3("Distance: %d, Range: %d\n" _C_ d_tmp _C_ range_tmp);
-	    if (d_tmp > range_tmp )
+	    if (d_tmp > range_tmp) {
 		return 0;
-	    else
-		return (unsigned char)((range_tmp-d_tmp)*MAX_SOUND_RANGE/range_tmp);
+	    } else {
+		return (unsigned char)((range_tmp - d_tmp) * MAX_SOUND_RANGE / range_tmp);
+	    }
 	} else {
 	    return 0;
 	}
@@ -532,14 +534,14 @@ local unsigned char VolumeForDistance(unsigned short d,unsigned char range) {
 */
 local unsigned char ComputeVolume(SoundRequest* sr) {
     if (sr->IsVolume) {
-	if (sr->Power>MaxVolume) {
+	if (sr->Power > MaxVolume) {
 	    return MaxVolume;
 	} else {
 	    return (unsigned char)sr->Power;
 	}
     } else {
 	// map distance to volume
-	return VolumeForDistance(sr->Power,((ServerSoundId)(sr->Sound))->Range);
+	return VolumeForDistance(sr->Power, ((ServerSoundId)(sr->Sound))->Range);
     }
 }
 
@@ -547,12 +549,12 @@ local unsigned char ComputeVolume(SoundRequest* sr) {
 ** "Randomly" choose a sample from a sound group.
 */
 local Sample* SimpleChooseSample(ServerSoundId sound) {
-    if (sound->Number==ONE_SOUND) {
+    if (sound->Number == ONE_SOUND) {
 	return sound->Sound.OneSound;
     } else {
 	//FIXME: check for errors
 	//FIXME: valid only in shared memory context (FrameCounter)
-	return sound->Sound.OneGroup[FrameCounter%sound->Number];
+	return sound->Sound.OneGroup[FrameCounter % sound->Number];
     }
 }
 
@@ -562,58 +564,60 @@ local Sample* SimpleChooseSample(ServerSoundId sound) {
 */
 local Sample* ChooseSample(SoundRequest* sr)
 {
-    ServerSoundId TheSound;
-    Sample* Result=NO_SOUND;
+    ServerSoundId theSound;
+    Sample* result;
+    
+    result = NO_SOUND;
 
-    if (sr->Sound!=NO_SOUND) {
-	TheSound=(ServerSoundId)(sr->Sound);
-	if (TheSound->Number==TWO_GROUPS) {
+    if (sr->Sound != NO_SOUND) {
+	theSound = (ServerSoundId)(sr->Sound);
+	if (theSound->Number == TWO_GROUPS) {
 	    // handle a special sound (selection)
-	    if (SelectionHandler.Source.Base==sr->Source.Base
-		&& SelectionHandler.Source.Id==sr->Source.Id) {
-		if (SelectionHandler.Sound==TheSound->Sound.TwoGroups->First) {
+	    if (SelectionHandler.Source.Base == sr->Source.Base
+		&& SelectionHandler.Source.Id == sr->Source.Id) {
+		if (SelectionHandler.Sound == theSound->Sound.TwoGroups->First) {
 		    DebugLevel3("First group\n");
-		    Result=SimpleChooseSample(SelectionHandler.Sound);
+		    result = SimpleChooseSample(SelectionHandler.Sound);
 		    SelectionHandler.HowMany++;
-		    if (SelectionHandler.HowMany>=3) {
-			SelectionHandler.HowMany=0;
-			SelectionHandler.Sound=(ServerSoundId)TheSound->Sound.TwoGroups->Second;
+		    if (SelectionHandler.HowMany >= 3) {
+			SelectionHandler.HowMany = 0;
+			SelectionHandler.Sound = (ServerSoundId)theSound->Sound.TwoGroups->Second;
 			DebugLevel3("Switching to second group\n");
 		    }
 		} else {
 		    //FIXME: checks for error
 		    DebugLevel3("Second group\n");
 		    // check wether the second group is really a group
-		    if (SelectionHandler.Sound->Number>1) {
-			Result=SelectionHandler.Sound->Sound.OneGroup[SelectionHandler.HowMany];
+		    if (SelectionHandler.Sound->Number > 1) {
+			result = SelectionHandler.Sound->Sound.OneGroup[SelectionHandler.HowMany];
 			SelectionHandler.HowMany++;
-			if(SelectionHandler.HowMany>=SelectionHandler.Sound->Number) {
-			    SelectionHandler.HowMany=0;
-			    SelectionHandler.Sound=(ServerSoundId)TheSound->Sound.TwoGroups->First;
+			if(SelectionHandler.HowMany >= SelectionHandler.Sound->Number) {
+			    SelectionHandler.HowMany = 0;
+			    SelectionHandler.Sound = (ServerSoundId)theSound->Sound.TwoGroups->First;
 			    DebugLevel3("Switching to first group\n");
 			}
 		    } else {
-			Result=SelectionHandler.Sound->Sound.OneSound;
-			SelectionHandler.HowMany=0;
-			SelectionHandler.Sound=(ServerSoundId)TheSound->Sound.TwoGroups->First;
+			result = SelectionHandler.Sound->Sound.OneSound;
+			SelectionHandler.HowMany = 0;
+			SelectionHandler.Sound = (ServerSoundId)theSound->Sound.TwoGroups->First;
 			DebugLevel3("Switching to first group\n");
 		    }
 		}
 	    } else {
-		SelectionHandler.Source=sr->Source;
-		SelectionHandler.Sound=TheSound->Sound.TwoGroups->First;
-		Result=SimpleChooseSample(SelectionHandler.Sound);
-		SelectionHandler.HowMany=1;
+		SelectionHandler.Source = sr->Source;
+		SelectionHandler.Sound = theSound->Sound.TwoGroups->First;
+		result = SimpleChooseSample(SelectionHandler.Sound);
+		SelectionHandler.HowMany = 1;
 	    }
 	} else {
 	    // normal sound/sound group handling
-	    Result=SimpleChooseSample(TheSound);
+	    result = SimpleChooseSample(theSound);
 	    if (sr->Selection) {
-		SelectionHandler.Source=sr->Source;
+		SelectionHandler.Source = sr->Source;
 	    }
 	}
     }
-    return Result;
+    return result;
 }
 
 /*
@@ -621,9 +625,9 @@ local Sample* ChooseSample(SoundRequest* sr)
 */
 global void FreeOneChannel(int channel)
 {
-    Channels[channel].Command=ChannelFree;
-    Channels[channel].Point=NextFreeChannel;
-    NextFreeChannel=channel;
+    Channels[channel].Command = ChannelFree;
+    Channels[channel].Point = NextFreeChannel;
+    NextFreeChannel = channel;
     if (Channels[channel].Source.Base) {
 	// unregister only valid sources
 	UnRegisterSource(channel);
@@ -639,17 +643,17 @@ local int FillOneChannel(SoundRequest* sr)
     int next_free;
     int old_free;
 
-    old_free=NextFreeChannel;
-    if (NextFreeChannel<MaxChannels) {
-	next_free=Channels[NextFreeChannel].Point;
-	Channels[NextFreeChannel].Source=sr->Source;
-	Channels[NextFreeChannel].Point=0;
-	Channels[NextFreeChannel].Volume=ComputeVolume(sr);
-	Channels[NextFreeChannel].Command=ChannelPlay;
-	Channels[NextFreeChannel].Sound=sr->Sound;
-	Channels[NextFreeChannel].Sample=ChooseSample(sr);
-	Channels[NextFreeChannel].Stereo=sr->Stereo;
-	NextFreeChannel=next_free;
+    old_free = NextFreeChannel;
+    if (NextFreeChannel < MaxChannels) {
+	next_free = Channels[NextFreeChannel].Point;
+	Channels[NextFreeChannel].Source = sr->Source;
+	Channels[NextFreeChannel].Point = 0;
+	Channels[NextFreeChannel].Volume = ComputeVolume(sr);
+	Channels[NextFreeChannel].Command = ChannelPlay;
+	Channels[NextFreeChannel].Sound = sr->Sound;
+	Channels[NextFreeChannel].Sample = ChooseSample(sr);
+	Channels[NextFreeChannel].Stereo = sr->Stereo;
+	NextFreeChannel = next_free;
     } else {
 	// should not happen
 	DebugLevel0("***** NO FREE CHANNEL *****\n");
@@ -667,35 +671,35 @@ local void FillChannels(int free_channels,int* discarded,int* started)
     int channel;
     SoundRequest* sr;
 
-    sr=SoundRequests+NextSoundRequestOut;
-    *discarded=0;
-    *started=0;
-    while(free_channels && sr->Used) {
-	if(KeepRequest(sr)) {
+    sr = SoundRequests+NextSoundRequestOut;
+    *discarded = 0;
+    *started = 0;
+    while (free_channels && sr->Used) {
+	if (KeepRequest(sr)) {
 	    DebugLevel3("Source [%p]: start playing request %p at slot %d\n" _C_
-			sr->Source.Base _C_ sr->Sound _C_ NextSoundRequestOut);
-	    channel=FillOneChannel(sr);
+		sr->Source.Base _C_ sr->Sound _C_ NextSoundRequestOut);
+	    channel = FillOneChannel(sr);
 	    if (sr->Source.Base) {
 		//Register only sound with a valid origin
-		RegisterSource(sr,channel);
+		RegisterSource(sr, channel);
 	    }
-	    free_channels--;
+	    --free_channels;
 	    DebugLevel3("Free channels: %d\n" _C_ free_channels);
-	    sr->Used=0;
-	    NextSoundRequestOut++;
+	    sr->Used = 0;
+	    ++NextSoundRequestOut;
 	    (*started)++;
 	} else {
 	  // Discarding request (for whatever reason)
 	  DebugLevel3("Discarding resquest %p from %p at slot %d\n" _C_
-		      sr->Sound _C_ sr->Source.Base _C_ NextSoundRequestOut);
-	  sr->Used=0;
-	  NextSoundRequestOut++;
+	      sr->Sound _C_ sr->Source.Base _C_ NextSoundRequestOut);
+	  sr->Used = 0;
+	  ++NextSoundRequestOut;
 	  (*discarded)++;
 	}
-	if(NextSoundRequestOut>=MAX_SOUND_REQUESTS) {
-	    NextSoundRequestOut=0;
+	if(NextSoundRequestOut >= MAX_SOUND_REQUESTS) {
+	    NextSoundRequestOut = 0;
 	}
-	sr=SoundRequests+NextSoundRequestOut;
+	sr = SoundRequests + NextSoundRequestOut;
     }
 }
 
@@ -713,23 +717,22 @@ local int MixChannelsToStereo32(int* buffer,int size)
     int i;
     int new_free_channels;
 
-    new_free_channels=0;
-    for( channel=0; channel<MaxChannels; ++channel ) {
-	if( Channels[channel].Command==ChannelPlay
-		&& Channels[channel].Sample) {
-	    i=MixSampleToStereo32(
-		    Channels[channel].Sample,Channels[channel].Point,
-		    Channels[channel].Volume,Channels[channel].Stereo,
-		    buffer,size);
-	    Channels[channel].Point+=i;
+    new_free_channels = 0;
+    for (channel = 0; channel < MaxChannels; ++channel) {
+	if (Channels[channel].Command == ChannelPlay &&
+		Channels[channel].Sample) {
+	    i = MixSampleToStereo32(Channels[channel].Sample,
+		Channels[channel].Point, Channels[channel].Volume,
+		Channels[channel].Stereo, buffer, size);
+	    Channels[channel].Point += i;
 
-	    if( Channels[channel].Point>=Channels[channel].Sample->Length ) {
+	    if (Channels[channel].Point >= Channels[channel].Sample->Length) {
 		// free channel as soon as possible (before playing)
 		// useful in multithreading
 		DebugLevel3("End playing request from %p\n" _C_
-			    Channels[channel].Source.Base);
+		    Channels[channel].Source.Base);
 		FreeOneChannel(channel);
-		new_free_channels++;
+		++new_free_channels;
 	    }
 	}
     }
@@ -737,7 +740,7 @@ local int MixChannelsToStereo32(int* buffer,int size)
     return new_free_channels;
 }
 
-#if SoundSampleSize==8
+#if SoundSampleSize == 8
 /**
 **	Clip mix to output stereo 8 unsigned bit.
 **
@@ -745,24 +748,24 @@ local int MixChannelsToStereo32(int* buffer,int size)
 **	@param size	number of samples in input.
 **	@param output	clipped 8 unsigned bit output buffer.
 */
-local void ClipMixToStereo8(const int* mix,int size,unsigned char* output)
+local void ClipMixToStereo8(const int* mix, int size, unsigned char* output)
 {
     int s;
 
-    while( size-- ) {
-	s=(*mix++)/256;
-	if( s>127 ) {
-	    *output++=255;
-	} else if( s<-127 ) {
-	    *output++=0;
+    while (size--) {
+	s = (*mix++) / 256;
+	if (s > 127) {
+	    *output++ = 255;
+	} else if (s < -127) {
+	    *output++ = 0;
 	} else {
-	    *output++=s+127;
+	    *output++ = s + 127;
 	}
     }
 }
 #endif
 
-#if SoundSampleSize==16
+#if SoundSampleSize == 16
 /**
 **	Clip mix to output stereo 16 signed bit.
 **
@@ -770,20 +773,20 @@ local void ClipMixToStereo8(const int* mix,int size,unsigned char* output)
 **	@param size	number of samples in input.
 **	@param output	clipped 16 signed bit output buffer.
 */
-local void ClipMixToStereo16(const int* mix,int size,short* output)
+local void ClipMixToStereo16(const int* mix, int size, short* output)
 {
     int s;
     const int* end;
 
-    end=mix+size;
-    while( mix<end ) {
-	s=(*mix++);
-	if( s>SHRT_MAX ) {
-	    *output++=SHRT_MAX;
-	} else if( s<SHRT_MIN ) {
-	    *output++=SHRT_MIN;
+    end = mix + size;
+    while (mix < end) {
+	s = (*mix++);
+	if (s > SHRT_MAX) {
+	    *output++ = SHRT_MAX;
+	} else if (s < SHRT_MIN) {
+	    *output++ = SHRT_MIN;
 	} else {
-	    *output++=s;
+	    *output++ = s;
 	}
     }
 }
@@ -857,15 +860,15 @@ local Sample* LoadSample(const char* name)
 **	@todo	FIXME: Must handle the errors better.
 **		FIXME: Support for more sample files (ogg/flac/mp3).
 */
-global SoundId RegisterSound(char *files[], unsigned number)
+global SoundId RegisterSound(char* files[], unsigned number)
 {
     unsigned i;
     ServerSoundId id;
 
     id = malloc(sizeof(*id));
     if (number > 1) {			// load a sound group
-	id->Sound.OneGroup = malloc(sizeof(Sample *) * number);
-	for (i = 0; i < number; i++) {
+	id->Sound.OneGroup = malloc(sizeof(Sample*) * number);
+	for (i = 0; i < number; ++i) {
 	    DebugLevel3("Registering `%s'\n" _C_ files[i]);
 	    id->Sound.OneGroup[i] = LoadSample(files[i]);
 	    if (!id->Sound.OneGroup[i]) {
@@ -885,7 +888,7 @@ global SoundId RegisterSound(char *files[], unsigned number)
 	id->Number = ONE_SOUND;
     }
     id->Range = MAX_SOUND_RANGE;
-    return (SoundId) id;
+    return (SoundId)id;
 }
 
 /**
@@ -903,9 +906,9 @@ global SoundId RegisterTwoGroups(SoundId first, SoundId second)
     if (first == NO_SOUND || second == NO_SOUND) {
 	return NO_SOUND;
     }
-    id = (ServerSoundId) malloc(sizeof(*id));
+    id = (ServerSoundId)malloc(sizeof(*id));
     id->Number = TWO_GROUPS;
-    id->Sound.TwoGroups = (TwoGroups *) malloc(sizeof(TwoGroups));
+    id->Sound.TwoGroups = (TwoGroups*)malloc(sizeof(TwoGroups));
     id->Sound.TwoGroups->First = first;
     id->Sound.TwoGroups->Second = second;
     id->Range = MAX_SOUND_RANGE;
@@ -934,31 +937,31 @@ global void SetSoundRange(SoundId sound, unsigned char range)
 **			enough.
 **	@param samples	Number of samples.
 */
-global void MixIntoBuffer(void* buffer,int samples)
+global void MixIntoBuffer(void* buffer, int samples)
 {
     int* mixer_buffer;
     int free_channels;
     int dummy1;
     int dummy2;
 
-    free_channels=HowManyFree();
-    FillChannels(free_channels,&dummy1,&dummy2);
+    free_channels = HowManyFree();
+    FillChannels(free_channels, &dummy1, &dummy2);
 
     // Create empty mixer buffer
-    mixer_buffer=alloca(samples*sizeof(*mixer_buffer));
+    mixer_buffer = alloca(samples * sizeof(*mixer_buffer));
     // FIXME: can save the memset here, if first channel sets the values
-    memset(mixer_buffer,0,samples*sizeof(*mixer_buffer));
+    memset(mixer_buffer, 0, samples * sizeof(*mixer_buffer));
 
     // Add channels to mixer buffer
-    MixChannelsToStereo32(mixer_buffer,samples);
+    MixChannelsToStereo32(mixer_buffer, samples);
     // Add music to mixer buffer
-    MixMusicToStereo32(mixer_buffer,samples);
+    MixMusicToStereo32(mixer_buffer, samples);
 
-#if SoundSampleSize==8
-    ClipMixToStereo8(mixer_buffer,samples,buffer);
+#if SoundSampleSize == 8
+    ClipMixToStereo8(mixer_buffer, samples, buffer);
 #endif
 #if SoundSampleSize==16
-    ClipMixToStereo16(mixer_buffer,samples,buffer);
+    ClipMixToStereo16(mixer_buffer, samples, buffer);
 #endif
 }
 
@@ -968,10 +971,10 @@ global void MixIntoBuffer(void* buffer,int samples)
 */
 global void WriteSound(void)
 {
-#if SoundSampleSize==8
+#if SoundSampleSize == 8
     char buffer[1024];
 #endif
-#if SoundSampleSize==16
+#if SoundSampleSize == 16
     short buffer[1024];
 #endif
 
@@ -983,17 +986,17 @@ global void WriteSound(void)
 
     DebugLevel3Fn("\n");
 
-    if( 0 ) {
+    if (0) {
 	audio_buf_info info;
 
-	ioctl(SoundFildes,SNDCTL_DSP_GETOSPACE,&info);
+	ioctl(SoundFildes, SNDCTL_DSP_GETOSPACE, &info);
 	DebugLevel0("%lu Free bytes %d\n" _C_ GameCycle _C_ info.bytes);
-	if( info.bytes<(int)sizeof(buffer) ) {
+	if (info.bytes < (int)sizeof(buffer)) {
 	    return;
 	}
     }
 
-    MixIntoBuffer(buffer,sizeof(buffer)/sizeof(*buffer));
+    MixIntoBuffer(buffer, sizeof(buffer) / sizeof(*buffer));
 
 #ifdef WITH_ARTSC
     if (WriteArtsSound(buffer, sizeof(buffer)) < 0) {
@@ -1001,8 +1004,8 @@ global void WriteSound(void)
 	
     }
 #else
-    while( write(SoundFildes,buffer,sizeof(buffer))==-1 ) {
-	switch( errno ) {
+    while (write(SoundFildes, buffer, sizeof(buffer)) == -1) {
+	switch (errno) {
 	    case EAGAIN:
 	    case EINTR:
 		continue;
@@ -1029,14 +1032,14 @@ global void WriteSound(void)
 **	@param stream	pointer to buffer you want to fill with information.
 **	@param len	is length of audio buffer in bytes.
 */
-global void FillAudio(void* udata __attribute__((unused)),Uint8* stream,int len)
+global void FillAudio(void* udata __attribute__((unused)), Uint8* stream, int len)
 {
-#if SoundSampleSize==16
-    len>>=1;
+#if SoundSampleSize == 16
+    len >>= 1;
 #endif
     DebugLevel3Fn("%d\n" _C_ len);
 
-    MixIntoBuffer(stream,len);
+    MixIntoBuffer(stream, len);
 }
 #endif	// } USE_SDLA
 
@@ -1048,10 +1051,10 @@ global void FillAudio(void* udata __attribute__((unused)),Uint8* stream,int len)
 global void WriteSoundThreaded(void)
 {
     int mixer_buffer[1024];
-#if SoundSampleSize==8
+#if SoundSampleSize == 8
     char buffer[1024];
 #endif
-#if SoundSampleSize==16
+#if SoundSampleSize == 16
     short buffer[1024];
 #endif
     int new_free_channels;
@@ -1082,16 +1085,16 @@ global void WriteSoundThreaded(void)
 
 	    if (how_many_playing) {
 		new_free_channels = MixChannelsToStereo32(mixer_buffer,
-			sizeof(mixer_buffer) / sizeof(int));
+		    sizeof(mixer_buffer) / sizeof(int));
 	    }
 	    MixMusicToStereo32(mixer_buffer,
 		sizeof(mixer_buffer) / sizeof(int));
 
-#if SoundSampleSize==8
+#if SoundSampleSize == 8
 	    ClipMixToStereo8(mixer_buffer, sizeof(mixer_buffer) / sizeof(int),
 		buffer);
 #endif
-#if SoundSampleSize==16
+#if SoundSampleSize == 16
 	    ClipMixToStereo16(mixer_buffer, sizeof(mixer_buffer) / sizeof(int),
 		buffer);
 #endif
@@ -1119,7 +1122,7 @@ global void WriteSoundThreaded(void)
 	    new_free_channels);
 	new_free_channels += discarded_request;
 	// decrement semaphore by the number of stopped channels
-	for (; new_free_channels > 0; new_free_channels--) {
+	for (; new_free_channels > 0; --new_free_channels) {
 	    //        sem_getvalue(&SoundThreadChannelSemaphore,&tmp);
 	    //        DebugLevel3("SoundSemaphore: %d\n" _C_ tmp);
 	    sem_wait(&SoundThreadChannelSemaphore);
@@ -1142,8 +1145,8 @@ global int InitSound(void)
     //
     //	Open sound device, 8bit samples, stereo.
     //
-    if( InitSdlSound(SoundDeviceName,SoundFrequency,SoundSampleSize,
-	    WaitForSoundDevice) ) {
+    if (InitSdlSound(SoundDeviceName, SoundFrequency, SoundSampleSize,
+	    WaitForSoundDevice)) {
 	return 1;
     }
 #else
@@ -1151,15 +1154,15 @@ global int InitSound(void)
     //
     //	Connect to artsd, 8bit samples, stereo.
     //
-    if( InitArtsSound(SoundFrequency,SoundSampleSize) ) {
+    if (InitArtsSound(SoundFrequency, SoundSampleSize)) {
 	return 1;
     }
 #else
     //
     //	Open dsp device, 8bit samples, stereo.
     //
-    if( InitOssSound(SoundDeviceName,SoundFrequency,SoundSampleSize,
-	    WaitForSoundDevice) ) {
+    if (InitOssSound(SoundDeviceName, SoundFrequency, SoundSampleSize,
+	    WaitForSoundDevice)) {
 	return 1;
     }
 #endif	// WITH_ARTSC
@@ -1168,14 +1171,14 @@ global int InitSound(void)
     //	ARI:	The following must be done here to allow sound to work in
     //		pre-start menus!
     // initialize channels
-    for(dummy=0;dummy<MaxChannels; ++dummy) {
-	Channels[dummy].Point=dummy+1;
+    for (dummy = 0; dummy < MaxChannels; ++dummy) {
+	Channels[dummy].Point = dummy + 1;
     }
 
     // initialize unit to channel hash table
     // WARNING: creation is only valid for a hash table using pointers as key
 #ifdef USE_GLIB
-    UnitToChannel=g_hash_table_new(g_direct_hash,NULL);
+    UnitToChannel = g_hash_table_new(g_direct_hash, NULL);
 #else
     DebugLevel0Fn("FIXME: must write non GLIB hash functions\n");
 #endif
@@ -1195,35 +1198,35 @@ global int InitSoundServer(void)
     int MapWidth;
     int MapHeight;
 
-    MapWidth = (TheUI.MapArea.EndX-TheUI.MapArea.X +TileSizeX) / TileSizeX;
-    MapHeight = (TheUI.MapArea.EndY-TheUI.MapArea.Y +TileSizeY) / TileSizeY;
+    MapWidth = (TheUI.MapArea.EndX - TheUI.MapArea.X + TileSizeX) / TileSizeX;
+    MapHeight = (TheUI.MapArea.EndY - TheUI.MapArea.Y + TileSizeY) / TileSizeY;
     //FIXME: Valid only in shared memory context!
-    DistanceSilent=3*max(MapWidth,MapHeight);
+    DistanceSilent = 3 * max(MapWidth, MapHeight);
     DebugLevel2("Distance Silent: %d\n" _C_ DistanceSilent);
-    ViewPointOffset=max(MapWidth/2,MapHeight/2);
+    ViewPointOffset = max(MapWidth / 2, MapHeight / 2);
     DebugLevel2("ViewPointOffset: %d\n" _C_ ViewPointOffset);
 
 #ifdef USE_THREAD
     if (WithSoundThread) {
       //prepare for the sound thread
-      if( sem_init(&SoundThreadChannelSemaphore,0,0) ) {
+      if (sem_init(&SoundThreadChannelSemaphore, 0, 0)) {
 	//FIXME: better error handling
 	PrintFunction();
 	// FIXME: ARI: strerror_r() is better here, but not compatible
 	fprintf(stdout, "%s\n", strerror(errno));
 	close(SoundFildes);
-	SoundFildes=-1;
+	SoundFildes = -1;
 	return 1;
       }
-      if( pthread_create(&SoundThread,NULL,(void *)&WriteSoundThreaded,NULL) ) {
+      if (pthread_create(&SoundThread, NULL, (void*)&WriteSoundThreaded, NULL)) {
 	//FIXME: better error handling
 	PrintFunction();
 	fprintf(stdout, "%s\n", strerror(errno));
 	close(SoundFildes);
-	SoundFildes=-1;
+	SoundFildes = -1;
 	return 1;
       }
-      SoundThreadRunning=1;
+      SoundThreadRunning = 1;
     }
 #endif
 
@@ -1237,14 +1240,14 @@ global void QuitSound(void)
 {
 #ifdef USE_SDLA
     SDL_CloseAudio();
-    SoundFildes=-1;
+    SoundFildes = -1;
 #else
 #ifdef WITH_ARTSC
     ExitArtsSound();
 #else // ! WITH_ARTSC
     if (SoundFildes != -1) {
 	close(SoundFildes);
-	SoundFildes=-1;
+	SoundFildes = -1;
     }
 #endif // WITH_ARTSC
 #endif // USE_SDLA