r1372 - trunk/code/client

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Jun 7 10:38:46 EDT 2008


Author: icculus
Date: 2008-06-07 10:38:46 -0400 (Sat, 07 Jun 2008)
New Revision: 1372

Modified:
   trunk/code/client/cl_cgame.c
   trunk/code/client/cl_main.c
   trunk/code/client/cl_parse.c
   trunk/code/client/client.h
   trunk/code/client/snd_openal.c
Log:
VoIP: Don't hardcode Speex sample rate.


Modified: trunk/code/client/cl_cgame.c
===================================================================
--- trunk/code/client/cl_cgame.c	2008-06-07 13:31:18 UTC (rev 1371)
+++ trunk/code/client/cl_cgame.c	2008-06-07 14:38:46 UTC (rev 1372)
@@ -923,6 +923,12 @@
 		speex_bits_init(&clc.speexEncoderBits);
 		speex_bits_reset(&clc.speexEncoderBits);
 		clc.speexEncoder = speex_encoder_init(&speex_nb_mode);
+
+		speex_encoder_ctl(clc.speexEncoder, SPEEX_GET_FRAME_SIZE,
+		                  &clc.speexFrameSize);
+		speex_encoder_ctl(clc.speexEncoder, SPEEX_GET_SAMPLING_RATE,
+		                  &clc.speexSamplingRate);
+
 		for (i = 0; i < MAX_CLIENTS; i++) {
 			speex_bits_init(&clc.speexDecoderBits[i]);
 			speex_bits_reset(&clc.speexDecoderBits[i]);
@@ -930,8 +936,6 @@
 			clc.voipIgnore[i] = qfalse;
 			clc.voipGain[i] = 1.0f;
 		}
-		speex_encoder_ctl(clc.speexEncoder, SPEEX_GET_FRAME_SIZE,
-		                  &clc.speexFrameSize);
 		clc.speexInitialized = qtrue;
 		clc.voipMuteAll = qfalse;
 		Cmd_AddCommand ("voip", CL_Voip_f);

Modified: trunk/code/client/cl_main.c
===================================================================
--- trunk/code/client/cl_main.c	2008-06-07 13:31:18 UTC (rev 1371)
+++ trunk/code/client/cl_main.c	2008-06-07 14:38:46 UTC (rev 1372)
@@ -310,14 +310,14 @@
 	}
 
 	if ((cl_voipSend->integer) || (finalFrame)) { // user wants to capture audio?
-		// !!! FIXME: 8000, MONO16, 4096 samples are hardcoded in snd_openal.c
 		int samples = S_AvailableCaptureSamples();
 		const int mult = (finalFrame) ? 1 : 12; // 12 == 240ms of audio.
 
 		// enough data buffered in audio hardware to process yet?
 		if (samples >= (clc.speexFrameSize * mult)) {
 			// audio capture is always MONO16 (and that's what speex wants!).
-			static int16_t sampbuffer[4096];  // !!! FIXME: don't hardcode.
+			//  2048 will cover 12 uncompressed frames in narrowband mode.
+			static int16_t sampbuffer[2048];
 			int16_t voipPower = 0;
 			int speexFrames = 0;
 			int wpos = 0;

Modified: trunk/code/client/cl_parse.c
===================================================================
--- trunk/code/client/cl_parse.c	2008-06-07 13:31:18 UTC (rev 1371)
+++ trunk/code/client/cl_parse.c	2008-06-07 14:38:46 UTC (rev 1372)
@@ -759,8 +759,8 @@
 		if ((written + clc.speexFrameSize) * 2 > sizeof (decoded)) {
 			Com_DPrintf("VoIP: playback %d bytes, %d samples, %d frames\n",
 			            written * 2, written, i);
-			S_RawSamples(sender + 1, written, 8000, 2, 1,
-			             (const byte *) decoded, clc.voipGain[sender]);  // !!! FIXME: hardcoding!
+			S_RawSamples(sender + 1, written, clc.speexSampleRate, 2, 1,
+			             (const byte *) decoded, clc.voipGain[sender]);
 			written = 0;
 		}
 
@@ -784,8 +784,8 @@
 	            written * 2, written, i);
 
 	if (written > 0) {
-		S_RawSamples(sender + 1, written, 8000, 2, 1,
-		             (const byte *) decoded, clc.voipGain[sender]);  // !!! FIXME: hardcoding!
+		S_RawSamples(sender + 1, written, clc.speexSampleRate, 2, 1,
+		             (const byte *) decoded, clc.voipGain[sender]);
 	}
 
 	clc.voipIncomingSequence[sender] = sequence + frames;

Modified: trunk/code/client/client.h
===================================================================
--- trunk/code/client/client.h	2008-06-07 13:31:18 UTC (rev 1371)
+++ trunk/code/client/client.h	2008-06-07 14:38:46 UTC (rev 1372)
@@ -232,6 +232,7 @@
 #if USE_VOIP
 	qboolean speexInitialized;
 	int speexFrameSize;
+	int speexSampleRate;
 
 	// incoming data...
 	// !!! FIXME: convert from parallel arrays to array of a struct.

Modified: trunk/code/client/snd_openal.c
===================================================================
--- trunk/code/client/snd_openal.c	2008-06-07 13:31:18 UTC (rev 1371)
+++ trunk/code/client/snd_openal.c	2008-06-07 14:38:46 UTC (rev 1372)
@@ -2088,6 +2088,10 @@
 		if (qalcCaptureOpenDevice == NULL) {
 			Com_Printf("No ALC_EXT_capture support, can't record audio.\n");
 		} else {
+			// !!! FIXME: 8000Hz is what Speex narrowband mode needs, but we
+			// !!! FIXME:  should probably open the capture device after
+			// !!! FIXME:  initializing Speex so we can change to wideband
+			// !!! FIXME:  if we like.
 			Com_Printf("OpenAL default capture device is '%s'\n",
 			           qalcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
 			alCaptureDevice = qalcCaptureOpenDevice(NULL, 8000, AL_FORMAT_MONO16, 4096);




More information about the quake3-commits mailing list