aboutsummaryrefslogtreecommitdiffstats
path: root/code
diff options
context:
space:
mode:
Diffstat (limited to 'code')
-rw-r--r--code/client/cl_cgame.c4
-rw-r--r--code/client/cl_main.c30
2 files changed, 12 insertions, 22 deletions
diff --git a/code/client/cl_cgame.c b/code/client/cl_cgame.c
index d0624c9..18a9630 100644
--- a/code/client/cl_cgame.c
+++ b/code/client/cl_cgame.c
@@ -937,10 +937,6 @@ void CL_FirstSnapshot( void ) {
speex_preprocess_ctl(clc.speexPreprocessor,
SPEEX_PREPROCESS_SET_DENOISE, &i);
- i = (cl_voipUseVAD->integer != 0);
- speex_preprocess_ctl(clc.speexPreprocessor,
- SPEEX_PREPROCESS_SET_VAD, &i);
-
for (i = 0; i < MAX_CLIENTS; i++) {
speex_bits_init(&clc.speexDecoderBits[i]);
speex_bits_reset(&clc.speexDecoderBits[i]);
diff --git a/code/client/cl_main.c b/code/client/cl_main.c
index 334b6a5..3fa0933 100644
--- a/code/client/cl_main.c
+++ b/code/client/cl_main.c
@@ -283,11 +283,8 @@ void CL_CaptureVoip(void)
return; // packet is pending transmission, don't record more yet.
if (cl_voipUseVAD->modified) {
- int useVadi = (int) useVad;
- speex_preprocess_ctl(clc.speexPreprocessor,
- SPEEX_PREPROCESS_SET_VAD, &useVadi);
- cl_voipUseVAD->modified = qfalse;
Cvar_Set("cl_voipSend", (useVad) ? "1" : "0");
+ cl_voipUseVAD->modified = qfalse;
}
if ((useVad) && (!cl_voipSend->integer))
@@ -339,8 +336,7 @@ void CL_CaptureVoip(void)
// audio capture is always MONO16 (and that's what speex wants!).
// 2048 will cover 12 uncompressed frames in narrowband mode.
static int16_t sampbuffer[2048];
- qboolean isVoice = qfalse;
- int16_t voipPower = 0;
+ float voipPower = 0.0f;
int speexFrames = 0;
int wpos = 0;
int pos = 0;
@@ -359,19 +355,15 @@ void CL_CaptureVoip(void)
int16_t *sampptr = &sampbuffer[pos];
int i, bytes;
+ // preprocess samples to remove noise...
+ speex_preprocess_run(clc.speexPreprocessor, sampptr);
+
// check the "power" of this packet...
for (i = 0; i < clc.speexFrameSize; i++) {
- int16_t s = sampptr[i];
- if (s < 0)
- s = -s;
- if (s > voipPower)
- voipPower = s; // !!! FIXME: this isn't very clever.
+ const float s = fabs((float) sampptr[i]);
+ voipPower += s * s;
}
- // preprocess samples to remove noise, check for voice...
- if (speex_preprocess_run(clc.speexPreprocessor, sampptr))
- isVoice = qtrue; // player is probably speaking.
-
// encode raw audio samples into Speex data...
speex_bits_reset(&clc.speexEncoderBits);
speex_encode_int(clc.speexEncoder, sampptr,
@@ -389,10 +381,12 @@ void CL_CaptureVoip(void)
speexFrames++;
}
- if ((useVad) && (!isVoice)) {
- CL_VoipNewGeneration(); // no talk for at least 1/4 second.
+ clc.voipPower = voipPower / (32768.0f * 32768.0f *
+ ((float) (clc.speexFrameSize * speexFrames)));
+
+ if ((useVad) && (clc.voipPower > 0.25f)) {
+ CL_VoipNewGeneration(); // no "talk" for at least 1/4 second.
} else {
- clc.voipPower = ((float) voipPower) / 32767.0f;
clc.voipOutgoingDataSize = wpos;
clc.voipOutgoingDataFrames = speexFrames;