From f3d2697ea300f22202b5e53f56c0d1931cf792e6 Mon Sep 17 00:00:00 2001
From: jsalmon3 <>
Date: Wed, 1 Oct 2003 16:52:40 +0000
Subject: [PATCH] Cleanup

---
 src/sound/arts_audio.cpp | 10 +++---
 src/sound/cdaudio.cpp    | 16 +++++-----
 src/sound/cdda.cpp       | 18 +++++------
 src/sound/flac.cpp       | 66 +++++++++++++++++++++-------------------
 4 files changed, 57 insertions(+), 53 deletions(-)

diff --git a/src/sound/arts_audio.cpp b/src/sound/arts_audio.cpp
index 856b9d45c..9e7a56837 100644
--- a/src/sound/arts_audio.cpp
+++ b/src/sound/arts_audio.cpp
@@ -92,16 +92,16 @@ global int InitArtsSound(int freq, int size)
 
     switch (freq) {
 	case 11025:
-	    frags = ((8<<16) |  8);   // 8 Buffers of  256 Bytes
+	    frags = ((8 << 16) |  8);   // 8 Buffers of  256 Bytes
 	    break;
 	case 22050:
-	    frags = ((8<<16) |  9);   // 8 Buffers of  512 Bytes
+	    frags = ((8 << 16) |  9);   // 8 Buffers of  512 Bytes
 	    break;
 	default:
 	    DebugLevel0Fn("Unexpected sample frequency %d\n" _C_ freq);
 	    // FALL THROUGH
 	case 44100:
-	    frags = ((8<<16) | 10);   // 8 Buffers of 1024 Bytes
+	    frags = ((8 << 16) | 10);   // 8 Buffers of 1024 Bytes
 	    break;
     }
     if (size == 16) {			//  8 bit
@@ -139,7 +139,7 @@ global void ExitArtsSound(void)
 */
 global int WriteArtsSound(void* data,int len)
 {
-	return arts_write(stream, data, len);
+    return arts_write(stream, data, len);
 }
 
 /**
@@ -149,7 +149,7 @@ global int WriteArtsSound(void* data,int len)
 */
 global int ArtsGetSpace(void)
 {
-	return arts_stream_get(stream, ARTS_P_BUFFER_SPACE);
+    return arts_stream_get(stream, ARTS_P_BUFFER_SPACE);
 }
 
 #endif	// } WITH_ARTSC
diff --git a/src/sound/cdaudio.cpp b/src/sound/cdaudio.cpp
index bc42bca1a..166191677 100644
--- a/src/sound/cdaudio.cpp
+++ b/src/sound/cdaudio.cpp
@@ -67,7 +67,7 @@ global int CDTrack;			/// Current cd track
 global int NumCDTracks;			/// Number of tracks on the cd
 
 #if defined(USE_SDLCD) 
-local SDL_CD *CDRom;			/// SDL cdrom device
+local SDL_CD* CDRom;			/// SDL cdrom device
 #elif defined(USE_CDDA) 
 global int CDDrive;			/// CDRom device
 global struct cdrom_tocentry CDtocentry[64];	/// TOC track header struct
@@ -105,7 +105,7 @@ local int InitCD(void)
 global int PlayCDTrack(int track)
 {
     CDTrack = track;
-    return SDL_CDPlayTracks(CDRom, track-1, 0, 0, 0);
+    return SDL_CDPlayTracks(CDRom, track - 1, 0, 0, 0);
 }
 
 /**
@@ -249,6 +249,7 @@ global int IsCDPlaying(void)
 global int GetCDVolume(void)
 {
     int vol;
+
     cd_get_volume(&vol, &vol);
     return vol;
 }
@@ -258,7 +259,6 @@ global int GetCDVolume(void)
 */
 global void SetCDVolume(int vol)
 {
-    vol = vol;
     cd_set_volume(vol, vol);
 }
 
@@ -307,7 +307,7 @@ local int InitCD(void)
 */
 global int PlayCDTrack(int track)
 {
-    Sample *sample;
+    Sample* sample;
 
     sample = LoadCD(NULL, track);
     CDTrack = track;
@@ -339,7 +339,7 @@ global void PauseCD(void)
 */
 global int IsAudioTrack(track)
 {
-    return !(CDtocentry[track].cdte_ctrl&CDROM_DATA_TRACK);
+    return !(CDtocentry[track].cdte_ctrl & CDROM_DATA_TRACK);
 }
 
 /**
@@ -380,10 +380,10 @@ global void QuitCD(void)
 ** 
 **      Perodic called from the main loop. 
 */
-global int CDRomCheck(void *unused __attribute__ ((unused)))
+global int CDRomCheck(void* unused __attribute__ ((unused)))
 {
-    if (CDMode != CDModeOff && CDMode != CDModeStopped
-	    && !IsCDPlaying() && CDMode != CDModeDefined) {
+    if (CDMode != CDModeOff && CDMode != CDModeStopped &&
+	    !IsCDPlaying() && CDMode != CDModeDefined) {
         DebugLevel0Fn("Playing new track\n");
         PlayCDRom(CDMode);
     }
diff --git a/src/sound/cdda.cpp b/src/sound/cdda.cpp
index f72b6c5d0..573c66571 100644
--- a/src/sound/cdda.cpp
+++ b/src/sound/cdda.cpp
@@ -72,10 +72,9 @@ typedef struct _cdda_data {
 **
 **	@return		    Number of bytes read
 */
-local int CDRead(Sample *sample, void *buf, int len)
+local int CDRead(Sample* sample, void* buf, int len)
 {
-    CddaData *data;
-
+    CddaData* data;
     int n;
 
     data = (CddaData*)sample->User;
@@ -84,9 +83,10 @@ local int CDRead(Sample *sample, void *buf, int len)
     data->Readdata.addr_format = CDROM_LBA;
 
     // end of track
-    if (FRAME_SIZE * (CDtocentry[CDTrack+1].cdte_addr.lba - 
+    if (FRAME_SIZE * (CDtocentry[CDTrack + 1].cdte_addr.lba - 
 	    CDtocentry[CDTrack].cdte_addr.lba) - data->PosInCd < len) {
-	len = FRAME_SIZE * (CDtocentry[CDTrack+1].cdte_addr.lba - CDtocentry[CDTrack].cdte_addr.lba) - data->PosInCd;
+	len = FRAME_SIZE * (CDtocentry[CDTrack+1].cdte_addr.lba -
+	    CDtocentry[CDTrack].cdte_addr.lba) - data->PosInCd;
 	data->PosInCd = 0;
     }
 
@@ -98,12 +98,12 @@ local int CDRead(Sample *sample, void *buf, int len)
 
 	n = CDDA_BUFFER_SIZE - sample->Length;
 
-	data->Readdata.nframes = n/FRAME_SIZE;
+	data->Readdata.nframes = n / FRAME_SIZE;
 	data->Readdata.buf = data->PointerInBuffer + sample->Length;
 	ioctl(CDDrive, CDROMREADAUDIO, &data->Readdata);
 
-	sample->Length += data->Readdata.nframes*FRAME_SIZE;
-	data->PosInCd += data->Readdata.nframes*FRAME_SIZE;
+	sample->Length += data->Readdata.nframes * FRAME_SIZE;
+	data->PosInCd += data->Readdata.nframes * FRAME_SIZE;
     }
 
     memcpy(buf, data->PointerInBuffer, len);
@@ -116,7 +116,7 @@ local int CDRead(Sample *sample, void *buf, int len)
 **
 **	@param sample	    Sample to free
 */
-local void CDFree(Sample *sample)
+local void CDFree(Sample* sample)
 {
     free(sample);
 }
diff --git a/src/sound/flac.cpp b/src/sound/flac.cpp
index 86b22e44a..354588ca1 100644
--- a/src/sound/flac.cpp
+++ b/src/sound/flac.cpp
@@ -78,9 +78,9 @@ local const SampleType FlacSampleType;
 **	@param user	User data.
 */
 local void FLAC_error_callback(
-	const FLAC__StreamDecoder * stream __attribute__((unused)),
-	FLAC__StreamDecoderErrorStatus status __attribute__((unused)),
-	void *user __attribute__((unused)))
+    const FLAC__StreamDecoder* stream __attribute__((unused)),
+    FLAC__StreamDecoderErrorStatus status __attribute__((unused)),
+    void* user __attribute__((unused)))
 {
     DebugLevel0Fn(" %s\n" _C_ FLAC__StreamDecoderErrorStatusString[status]);
 }
@@ -96,12 +96,12 @@ local void FLAC_error_callback(
 **	@return		Error status.
 */
 local FLAC__StreamDecoderReadStatus FLAC_read_callback(
-	const FLAC__StreamDecoder * stream __attribute__((unused)),
-	FLAC__byte buffer[], unsigned int *bytes, void *user)
+    const FLAC__StreamDecoder * stream __attribute__((unused)),
+    FLAC__byte buffer[], unsigned int *bytes, void *user)
 {
     unsigned i;
-    CLFile *f;
-    FlacData *data;
+    CLFile* f;
+    FlacData* data;
 
     DebugLevel3Fn("Read callback %d\n" _C_ *bytes);
 
@@ -125,10 +125,10 @@ local FLAC__StreamDecoderReadStatus FLAC_read_callback(
 **	@param user	User data.
 */
 local void FLAC_metadata_callback(
-	const FLAC__StreamDecoder * stream __attribute__((unused)),
-	const FLAC__StreamMetadata * metadata, void *user)
+    const FLAC__StreamDecoder* stream __attribute__((unused)),
+    const FLAC__StreamMetadata* metadata, void *user)
 {
-    Sample *sample;
+    Sample* sample;
     int rate;
 
     if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
@@ -140,12 +140,12 @@ local void FLAC_metadata_callback(
 
 	rate = 44100 / sample->Frequency;
 	// will overbuffer, so double the amount to allocate
-	sample = realloc(sample, sizeof(*sample) + 2*rate*FLAC_BUFFER_SIZE);
+	sample = realloc(sample, sizeof(*sample) + 2 * rate * FLAC_BUFFER_SIZE);
 	((FlacData*)(sample->User))->Sample = sample;
 	((FlacData*)(sample->User))->PointerInBuffer = sample->Data;
 
 	DebugLevel3Fn("Stream %d Channels, %d frequency, %d bits\n" _C_
-		sample->Channels _C_ sample->Frequency _C_ sample->SampleSize);
+	    sample->Channels _C_ sample->Frequency _C_ sample->SampleSize);
     }
 }
 
@@ -159,15 +159,15 @@ local void FLAC_metadata_callback(
 **
 **	@return		Error status.
 */
-local FLAC__StreamDecoderWriteStatus FLAC_write_callback(const
-    FLAC__StreamDecoder * stream __attribute__((unused)),
-    const FLAC__Frame * frame, const FLAC__int32 * const buffer[], void *user)
+local FLAC__StreamDecoderWriteStatus FLAC_write_callback(
+    const FLAC__StreamDecoder* stream __attribute__((unused)),
+    const FLAC__Frame* frame, const FLAC__int32* const buffer[], void* user)
 {
-    FlacData *data;
-    Sample *sample;
+    FlacData* data;
+    Sample* sample;
     unsigned i;
     unsigned channel;
-    void *p;
+    void* p;
     int rate;
     int y;
 
@@ -187,7 +187,7 @@ local FLAC__StreamDecoderWriteStatus FLAC_write_callback(const
 
     if (sample->Type == &FlacSampleType) {
 	// not streaming
-	sample = realloc(sample, sizeof(*sample) + sample->Length + i*rate);
+	sample = realloc(sample, sizeof(*sample) + sample->Length + i * rate);
 	if (!sample) {
 	    fprintf(stderr, "Out of memory!\n");
 	    CLclose(data->FlacFile);
@@ -198,15 +198,15 @@ local FLAC__StreamDecoderWriteStatus FLAC_write_callback(const
     }
 
     p = sample->Data + sample->Length;
-    sample->Length += i*rate;
-    data->Bytes -= i*rate;
+    sample->Length += i * rate;
+    data->Bytes -= i * rate;
 
     switch (sample->SampleSize) {
 	case 8:
 	    for (i = 0; i < frame->header.blocksize; ++i) {
 		for (y = 0; y < rate; ++y) {
 		    for (channel = 0; channel < frame->header.channels; channel++) {
-			*((unsigned char *)p)++ = buffer[channel][i] + 128;
+			*((unsigned char*)p)++ = buffer[channel][i] + 128;
 		    }
 		}
 	    }
@@ -215,7 +215,7 @@ local FLAC__StreamDecoderWriteStatus FLAC_write_callback(const
 	    for (i = 0; i < frame->header.blocksize; ++i) {
 		for (y = 0; y < rate; ++y) {
 		    for (channel = 0; channel < frame->header.channels; channel++) {
-			*((short *)p)++ = buffer[channel][i];
+			*((short*)p)++ = buffer[channel][i];
 		    }
 		}
 	    }
@@ -240,7 +240,7 @@ local FLAC__StreamDecoderWriteStatus FLAC_write_callback(const
 */
 local int FlacRead(Sample* sample, void* buf, int len)
 {
-    char *pos;
+    char* pos;
 
     pos = ((FlacData*)sample->User)->PointerInBuffer;
 
@@ -262,7 +262,9 @@ local int FlacRead(Sample* sample, void* buf, int len)
 */
 local void FlacFree(Sample* sample)
 {
-    IfDebug( AllocatedSoundMemory -= sample->Length; );
+#ifdef DEBUG
+    AllocatedSoundMemory -= sample->Length;
+#endif
 
     free(sample);
 }
@@ -288,7 +290,7 @@ local int FlacStreamRead(Sample* sample, void* buf, int len)
 {
     FlacData* data;
 
-    data = (FlacData*) sample->User;
+    data = (FlacData*)sample->User;
 
     while (FLAC__stream_decoder_get_state(data->Stream) != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) {
 	// read metadata
@@ -324,9 +326,11 @@ local int FlacStreamRead(Sample* sample, void* buf, int len)
 */
 local void FlacStreamFree(Sample* sample)
 {
-    FlacData *data;
+    FlacData* data;
 
-    IfDebug( AllocatedSoundMemory -= sizeof(*sample) + FLAC_BUFFER_SIZE);
+#ifdef DEBUG
+    AllocatedSoundMemory -= sizeof(*sample) + FLAC_BUFFER_SIZE;
+#endif
 
     data = (FlacData*)sample->User;
     CLclose(data->FlacFile);
@@ -358,9 +362,9 @@ global Sample* LoadFlac(const char* name, int flags)
     Sample* sample;
     unsigned int magic[1];
     FLAC__StreamDecoder* stream;
-    FlacData *data;
+    FlacData* data;
 
-    if (!(f = CLopen(name,CL_OPEN_READ))) {
+    if (!(f = CLopen(name, CL_OPEN_READ))) {
 	fprintf(stderr, "Can't open file `%s'\n", name);
 	return NULL;
     }
@@ -385,7 +389,7 @@ global Sample* LoadFlac(const char* name, int flags)
 	return NULL;
     }
 
-    sample = malloc(sizeof(*sample) + 2*FLAC_BUFFER_SIZE);
+    sample = malloc(sizeof(*sample) + 2 * FLAC_BUFFER_SIZE);
 
     data = malloc(sizeof(FlacData));
     data->FlacFile = f;