aboutsummaryrefslogtreecommitdiffstats
path: root/codecs/codec_speex.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-12 22:20:16 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-12 22:20:16 +0000
commit20933df5384da8f82a38bd52502452220f3834d2 (patch)
tree8fef81a6d9059e7e1a1c9c7dfc503c799c0fe389 /codecs/codec_speex.c
parent4e3e4a83f21eddbe588133ad826012923a84b90e (diff)
support DTX and CNG in speex (bug #4608)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6113 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'codecs/codec_speex.c')
-rwxr-xr-xcodecs/codec_speex.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/codecs/codec_speex.c b/codecs/codec_speex.c
index c96892858..f2f0a86c5 100755
--- a/codecs/codec_speex.c
+++ b/codecs/codec_speex.c
@@ -69,6 +69,7 @@ struct ast_translator_pvt {
/* 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 @@ static struct ast_translator_pvt *lintospeex_new(void)
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 @@ static struct ast_translator_pvt *lintospeex_new(void)
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 @@ static struct ast_frame *lintospeex_frameout(struct ast_translator_pvt *tmp)
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 @@ static struct ast_frame *lintospeex_frameout(struct ast_translator_pvt *tmp)
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 @@ static struct ast_frame *lintospeex_frameout(struct ast_translator_pvt *tmp)
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));