diff options
author | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2007-05-17 18:14:59 +0400 |
---|---|---|
committer | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2007-05-17 18:14:59 +0400 |
commit | 0f6335ea9ef4d43e9d0c99bc01307698a7a76195 (patch) | |
tree | c8a1d38f5cb9adc99c53ec966bf391d4d16c2dd9 | |
parent | fcdbf450fe0d3f69c7e2e677978e7c3d40bdec30 (diff) |
Implemented SPEEX_GET_ACTIVITY
git-svn-id: http://svn.xiph.org/trunk/speex@12957 0101bb08-14d6-0310-b084-bc0e0c8e3800
-rw-r--r-- | include/speex/speex.h | 4 | ||||
-rw-r--r-- | libspeex/nb_celp.c | 22 | ||||
-rw-r--r-- | libspeex/nb_celp.h | 6 | ||||
-rw-r--r-- | libspeex/sb_celp.c | 4 |
4 files changed, 33 insertions, 3 deletions
diff --git a/include/speex/speex.h b/include/speex/speex.h index f17fa19..99d2764 100644 --- a/include/speex/speex.h +++ b/include/speex/speex.h @@ -155,6 +155,10 @@ extern "C" { /** Get status of input/output high-pass filtering */ #define SPEEX_GET_HIGHPASS 45 +/** Get "activity level" of the last decoded frame, i.e. + now much damage we cause if we remove the frame */ +#define SPEEX_GET_ACTIVITY 47 + /* Preserving compatibility:*/ /** Equivalent to SPEEX_SET_ENH */ diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index 1828aed..6ac12a0 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -1720,6 +1720,14 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) /*for (i=0;i<st->frameSize;i++) printf ("%d\n", (int)st->frame[i]);*/ + /* Tracking output level */ + st->level = 1+PSHR32(ol_gain,SIG_SHIFT); + st->max_level = MAX16(MULT16_16_Q15(QCONST16(.99f,15), st->max_level), st->level); + st->min_level = MIN16(ADD16(1,MULT16_16_Q14(QCONST16(1.01f,14), st->min_level)), st->level); + if (st->max_level < st->min_level+1) + st->max_level = st->min_level+1; + /*printf ("%f %f %f %d\n", og, st->min_level, st->max_level, update);*/ + /* Store the LSPs for interpolation in the next frame */ for (i=0;i<st->lpcSize;i++) st->old_qlsp[i] = qlsp[i]; @@ -2013,7 +2021,19 @@ int nb_decoder_ctl(void *state, int request, void *ptr) case SPEEX_GET_HIGHPASS: (*(spx_int32_t*)ptr) = st->highpass_enabled; break; - + case SPEEX_GET_ACTIVITY: + { + float ret; + ret = log(st->level/st->min_level)/log(st->max_level/st->min_level); + if (ret>1) + ret = 1; + /* Done in a strange way to catch NaNs as well */ + if (!(ret > 0)) + ret = 0; + /*printf ("%f %f %f %f\n", st->level, st->min_level, st->max_level, ret);*/ + (*(spx_int32_t*)ptr) = (int)(100*ret); + } + break; case SPEEX_GET_PI_GAIN: { int i; diff --git a/libspeex/nb_celp.h b/libspeex/nb_celp.h index 1ebf717..cc91b1c 100644 --- a/libspeex/nb_celp.h +++ b/libspeex/nb_celp.h @@ -148,7 +148,11 @@ typedef struct DecState { spx_mem_t *mem_sp; /**< Filter memory for synthesis signal */ spx_mem_t mem_hp[2]; /**< High-pass filter memory */ spx_word32_t *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */ - spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */ + spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */ + + spx_word16_t level; + spx_word16_t max_level; + spx_word16_t min_level; /* This is used in packet loss concealment */ int last_pitch; /**< Pitch of last correctly decoded frame */ diff --git a/libspeex/sb_celp.c b/libspeex/sb_celp.c index 50b9824..50cc1e3 100644 --- a/libspeex/sb_celp.c +++ b/libspeex/sb_celp.c @@ -1441,7 +1441,9 @@ int sb_decoder_ctl(void *state, int request, void *ptr) case SPEEX_GET_HIGHPASS: speex_decoder_ctl(st->st_low, SPEEX_GET_HIGHPASS, ptr); break; - + case SPEEX_GET_ACTIVITY: + speex_decoder_ctl(st->st_low, SPEEX_GET_ACTIVITY, ptr); + break; case SPEEX_GET_PI_GAIN: { int i; |