[Asterisk-cvs] asterisk/codecs codec_speex.c,1.16,1.17

kpfleming at lists.digium.com kpfleming at lists.digium.com
Tue Jul 12 18:12:08 CDT 2005


Update of /usr/cvsroot/asterisk/codecs
In directory mongoose.digium.com:/tmp/cvs-serv20209/codecs

Modified Files:
	codec_speex.c 
Log Message:
support DTX and CNG in speex (bug #4608)


Index: codec_speex.c
===================================================================
RCS file: /usr/cvsroot/asterisk/codecs/codec_speex.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- codec_speex.c	21 Jun 2005 23:16:32 -0000	1.16
+++ codec_speex.c	12 Jul 2005 22:20:16 -0000	1.17
@@ -69,6 +69,7 @@
 	/* Enough to store a full second */
 	short buf[8000];
 	int tail;
+       int silent_state;
 };
 
 #define speex_coder_pvt ast_translator_pvt
@@ -91,8 +92,6 @@
 				speex_encoder_ctl(tmp->speex, SPEEX_SET_QUALITY, &quality);
 				if (vad)
 					speex_encoder_ctl(tmp->speex, SPEEX_SET_VAD, &vad);
-				if (dtx)
-					speex_encoder_ctl(tmp->speex, SPEEX_SET_DTX, &dtx); 
 			}
 			if (vbr) {
 				speex_encoder_ctl(tmp->speex, SPEEX_SET_VBR, &vbr);
@@ -101,7 +100,10 @@
 			if (abr) {
 				speex_encoder_ctl(tmp->speex, SPEEX_SET_ABR, &abr);
 			}
+                       if (dtx)
+                               speex_encoder_ctl(tmp->speex, SPEEX_SET_DTX, &dtx);
 			tmp->tail = 0;
+                       tmp->silent_state = 0;
 		}
 		localusecnt++;
 	}
@@ -241,6 +243,7 @@
 	float fbuf[1024];
 	int len;
 	int y=0,x;
+       int is_speech=1;
 	/* We can't work on anything less than a frame in size */
 	if (tmp->tail < tmp->framesize)
 		return NULL;
@@ -256,7 +259,7 @@
 		for (x=0;x<tmp->framesize;x++)
 			fbuf[x] = tmp->buf[x];
 		/* Encode a frame of data */
-		speex_encode(tmp->speex, fbuf, &tmp->bits);
+               is_speech = speex_encode(tmp->speex, fbuf, &tmp->bits) || !dtx;
 		/* Assume 8000 Hz -- 20 ms */
 		tmp->tail -= tmp->framesize;
 		/* Move the data at the end of the buffer to the front */
@@ -264,6 +267,20 @@
 			memmove(tmp->buf, tmp->buf + tmp->framesize, tmp->tail * 2);
 		y++;
 	}
+
+       /* Use AST_FRAME_CNG to signify the start of any silence period */
+       if(!is_speech) {
+               if(tmp->silent_state) {
+                       return NULL;
+               } else {
+                       tmp->silent_state = 1;
+                       speex_bits_reset(&tmp->bits);
+                       tmp->f.frametype = AST_FRAME_CNG;
+               }
+       } else {
+               tmp->silent_state = 0;
+       }
+
 	/* Terminate bit stream */
 	speex_bits_pack(&tmp->bits, 15, 5);
 	len = speex_bits_write(&tmp->bits, (char *)tmp->outbuf, sizeof(tmp->outbuf));




More information about the svn-commits mailing list