about summary refs log tree commit diff
path: root/src/engine/client/snd.c
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-06 17:01:06 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-06 17:01:06 +0000
commitf9162202b0ceb25fae4a0848a4a99dbe1158bd22 (patch)
tree1e6350bb0608f2a599e0a303fcf5b18aab691102 /src/engine/client/snd.c
parent449146a2753deb657e0ef641bd6065467ef75322 (diff)
downloadzcatch-f9162202b0ceb25fae4a0848a4a99dbe1158bd22.tar.gz
zcatch-f9162202b0ceb25fae4a0848a4a99dbe1158bd22.zip
fixed some C errors
Diffstat (limited to 'src/engine/client/snd.c')
-rw-r--r--src/engine/client/snd.c82
1 files changed, 44 insertions, 38 deletions
diff --git a/src/engine/client/snd.c b/src/engine/client/snd.c
index 77844367..0fe82e14 100644
--- a/src/engine/client/snd.c
+++ b/src/engine/client/snd.c
@@ -13,10 +13,7 @@ enum
 	NUM_SOUNDS = 512,
 	NUM_VOICES = 64,
 	NUM_CHANNELS = 4,
-};
 
-enum
-{
 	MAX_FRAMES = 1024
 };
 
@@ -116,8 +113,8 @@ static inline void fill_stereo(int *out, unsigned frames, struct voice *v, float
 {
 	int ivol = (int) (31.0f * fvol);
 	int ipan = (int) (31.0f * ipan);
-
 	unsigned i;
+
 	for(i = 0; i < frames; i++)
 	{
 		unsigned j = i<<1;
@@ -131,10 +128,11 @@ static void mix(short *out, unsigned frames)
 {
 	static int main_buffer[MAX_FRAMES*2];
 	unsigned locked = 0;
+	unsigned i;
+	unsigned cid;
 
 	dbg_assert(frames <= MAX_FRAMES, "too many frames to fill");
 
-	unsigned i;
 	for(i = 0; i < frames; i++)
 	{
 		unsigned j = i<<1;
@@ -142,7 +140,6 @@ static void mix(short *out, unsigned frames)
 		main_buffer[j+1] = 0;
 	}
 
-	unsigned cid;
 	for(cid = 0; cid < NUM_CHANNELS; cid++)
 	{
 		struct channel *c = &channels[cid];
@@ -155,24 +152,24 @@ static void mix(short *out, unsigned frames)
 
 			while(v && v->sound && filled < frames)
 			{
-				// calculate maximum frames to fill
+				/* calculate maximum frames to fill */
 				unsigned frames_left = (v->sound->num_samples - v->tick) >> (v->sound->channels-1);
 				unsigned long to_fill = frames>frames_left?frames_left:frames;
 				float vol = 1.0f;
 				float pan = 0.0f;
 
-				// clamp to_fill if voice should stop
+				/* clamp to_fill if voice should stop */
 				if(v->stop >= 0)
 					to_fill = (unsigned)v->stop>frames_left?frames:v->stop;
 
-				// clamp to_fill if we are about to loop
+				/* clamp to_fill if we are about to loop */
 				if(v->loop >= 0 && v->sound->loop_start >= 0)
 				{
 					unsigned tmp = v->sound->loop_end - v->tick;
 					to_fill = tmp>to_fill?to_fill:tmp;
 				}
 
-				// calculate voice volume and delta
+				/* calculate voice volume and delta */
 				if(c->flags & CHANNEL_POSITION_VOLUME)
 				{
 					float dx = v->x - center_x;
@@ -181,14 +178,14 @@ static void mix(short *out, unsigned frames)
 					if(dist < volume_deadzone*volume_deadzone)
 						vol = master_vol * c->vol;
 					else
-						vol = master_vol * c->vol / ((dist - volume_deadzone*volume_deadzone)*volume_falloff); //TODO: use some fast 1/x^2
+						vol = master_vol * c->vol / ((dist - volume_deadzone*volume_deadzone)*volume_falloff); /*TODO: use some fast 1/x^2 */
 				}
 				else
 				{
 					vol = master_vol * c->vol * v->vol;
 				}
 
-				// calculate voice pan and delta
+				/* calculate voice pan and delta */
 				if(c->flags & CHANNEL_POSITION_PAN)
 				{
 					float dx = v->x - center_x;
@@ -202,24 +199,24 @@ static void mix(short *out, unsigned frames)
 					pan = master_pan + c->pan + v->pan;
 				}
 
-				// fill the main buffer
+				/* fill the main buffer */
 				if(v->sound->channels == 1)
 					fill_mono(&main_buffer[filled], to_fill, v, vol, pan);
 				else
 					fill_stereo(&main_buffer[filled], to_fill, v, vol, pan);
 
-				// reset tick of we hit loop point
+				/* reset tick of we hit loop point */
 				if(v->loop >= 0 &&
 						v->sound->loop_start >= 0 &&
 						v->tick >= v->sound->loop_end)
 					v->tick = v->sound->loop_start;
 
-				// stop sample if nessecary
+				/* stop sample if nessecary */
 				if(v->stop >= 0)
 					v->stop -=  to_fill;
 				if(v->tick >= v->sound->num_samples || v->stop == 0)
 				{
-					struct voice *vn = v->next;
+					struct voice *vn = (struct voice *)v->next;
 					if(!locked)
 					{
 						lock_wait(sound_lock);
@@ -253,7 +250,7 @@ static void mix(short *out, unsigned frames)
 	if(locked)
 		lock_release(sound_lock);
 
-	// clamp accumulated values
+	/* clamp accumulated values */
 	for(i = 0; i < frames; i++)
 	{
 		int j = i<<1;
@@ -345,21 +342,26 @@ int snd_load_wv(const char *filename)
 	struct sound *snd;
 	int sid = -1;
 	char error[100];
+	WavpackContext *context;
 
 	sid = snd_alloc_id();
 	if(sid < 0)
 		return -1;
 	snd = &sounds[sid];
 
-	file = fopen(filename, "rb"); // TODO: use system.h stuff for this
+	file = fopen(filename, "rb"); /* TODO: use system.h stuff for this */
 
-	WavpackContext *context = WavpackOpenFileInput(read_data, error);
+	context = WavpackOpenFileInput(read_data, error);
 	if (context)
 	{
 		int samples = WavpackGetNumSamples(context);
 		int bitspersample = WavpackGetBitsPerSample(context);
 		unsigned int samplerate = WavpackGetSampleRate(context);
 		int channels = WavpackGetNumChannels(context);
+		int *data;
+		int *src;
+		short *dst;
+		int i;
 
 		snd->channels = channels;
 		snd->rate = samplerate;
@@ -382,14 +384,13 @@ int snd_load_wv(const char *filename)
 			return -1;
 		}
 
-		int *data = (int *)mem_alloc(4*samples*channels, 1);
-		WavpackUnpackSamples(context, data, samples); // TODO: check return value
-		int *src = data;
+		data = (int *)mem_alloc(4*samples*channels, 1);
+		WavpackUnpackSamples(context, data, samples); /* TODO: check return value */
+		src = data;
 		
 		snd->data = (short *)mem_alloc(2*samples*channels, 1);
-		short *dst = snd->data;
+		dst = snd->data;
 
-		int i;
 		for (i = 0; i < samples*channels; i++)
 			*dst++ = (short)*src++;
 
@@ -413,10 +414,15 @@ int snd_load_wv(const char *filename)
 	return sid;
 }
 
+#if 0
 int snd_load_wav(const char *filename)
 {
-	// open file for reading
+	/* open file for reading */
 	IOHANDLE file;
+	struct sound *snd;
+	int sid = -1;
+	int state = 0;
+
 	file = io_open(filename, IOFLAG_READ);
 	if(!file)
 	{
@@ -424,37 +430,35 @@ int snd_load_wav(const char *filename)
 		return -1;
 	}
 
-	struct sound *snd;
-	int sid = -1;
-
 	sid = snd_alloc_id();
 	if(sid < 0)
 		return -1;
 	snd = &sounds[sid];
 
-	int state = 0;
 	while(1)
 	{
-		// read chunk header
+		/* read chunk header */
 		unsigned char head[8];
+		int chunk_size;
 		if(io_read(file, head, sizeof(head)) != 8)
 		{
 			break;
 		}
 		
-		int chunk_size = head[4] | (head[5]<<8) | (head[6]<<16) | (head[7]<<24);
+		chunk_size = head[4] | (head[5]<<8) | (head[6]<<16) | (head[7]<<24);
 		head[4] = 0;
 			
 		if(state == 0)
 		{
-			// read the riff and wave headers
+			unsigned char type[4];
+
+			/* read the riff and wave headers */
 			if(head[0] != 'R' || head[1] != 'I' || head[2] != 'F' || head[3] != 'F')
 			{
 				dbg_msg("sound/wav", "not a RIFF file. filename='%s'", filename);
 				return -1;
 			}
 			
-			unsigned char type[4];
 			io_read(file, type, 4);
 
 			if(type[0] != 'W' || type[1] != 'A' || type[2] != 'V' || type[3] != 'E')
@@ -467,7 +471,7 @@ int snd_load_wav(const char *filename)
 		}
 		else if(state == 1)
 		{
-			// read the format chunk
+			/* read the format chunk */
 			if(head[0] == 'f' && head[1] == 'm' && head[2] == 't' && head[3] == ' ')
 			{
 				unsigned char fmt[16];
@@ -477,7 +481,7 @@ int snd_load_wav(const char *filename)
 					return -1;
 				}
 				
-				// decode format
+				/* decode format */
 				int compression_code = fmt[0] | (fmt[1]<<8);
 				snd->channels = fmt[2] | (fmt[3]<<8);
 				snd->rate = fmt[4] | (fmt[5]<<8) | (fmt[6]<<16) | (fmt[7]<<24);
@@ -507,7 +511,7 @@ int snd_load_wav(const char *filename)
 					return -1;
 				}
 				
-				// next state
+				/* next state */
 				state++;
 			}
 			else
@@ -515,7 +519,7 @@ int snd_load_wav(const char *filename)
 		}
 		else if(state == 2)
 		{
-			// read the data
+			/* read the data */
 			if(head[0] == 'd' && head[1] == 'a' && head[2] == 't' && head[3] == 'a')
 			{
 				snd->data = (short*)mem_alloc(chunk_size, 1);
@@ -571,6 +575,8 @@ int snd_load_wav(const char *filename)
 
 	return sid;
 }
+#endif
+
 
 int snd_play(int cid, int sid, int loop, float x, float y)
 {
@@ -611,7 +617,7 @@ void snd_set_master_volume(float val)
 
 void snd_stop(int vid)
 {
-	//TODO: lerp volume to 0
+	/*TODO: lerp volume to 0*/
 	voices[vid].stop = 0;
 }