diff options
author | Thom Johansen <thomj@rockbox.org> | 2007-11-14 12:11:13 +0000 |
---|---|---|
committer | Thom Johansen <thomj@rockbox.org> | 2007-11-14 12:11:13 +0000 |
commit | 80821482006f0730ba70d3e0af63f77cb976285a (patch) | |
tree | d119cb8e6ceff42db04df77f2a467531a1cd4743 /apps/codecs/libspeex | |
parent | 017e1486553d5fc696a42dd99e9bc2276d293db6 (diff) |
Sync latest Speex stereo changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15617 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libspeex')
-rw-r--r-- | apps/codecs/libspeex/stereo.c | 14 | ||||
-rw-r--r-- | apps/codecs/libspeex/vq.c | 23 | ||||
-rw-r--r-- | apps/codecs/libspeex/vq.h | 1 |
3 files changed, 8 insertions, 30 deletions
diff --git a/apps/codecs/libspeex/stereo.c b/apps/codecs/libspeex/stereo.c index 9fa812dd72..5f74197054 100644 --- a/apps/codecs/libspeex/stereo.c +++ b/apps/codecs/libspeex/stereo.c @@ -45,7 +45,7 @@ typedef struct RealSpeexStereoState { spx_word32_t e_ratio; /**< Ratio of energies: E(left+right)/[E(left)+E(right)] */ spx_word32_t smooth_left; /**< Smoothed left channel gain */ spx_word32_t smooth_right; /**< Smoothed right channel gain */ - spx_int32_t reserved1; /**< Reserved for future use */ + spx_uint32_t reserved1; /**< Reserved for future use */ spx_int32_t reserved2; /**< Reserved for future use */ } RealSpeexStereoState; @@ -53,15 +53,17 @@ typedef struct RealSpeexStereoState { /*float e_ratio_quant[4] = {1, 1.26, 1.587, 2};*/ #ifndef FIXED_POINT static const float e_ratio_quant[4] = {.25f, .315f, .397f, .5f}; +static const float e_ratio_quant_bounds[3] = {0.2825f, 0.356f, 0.4485f}; #else static const spx_word16_t e_ratio_quant[4] = {8192, 10332, 13009, 16384}; +static const spx_word16_t e_ratio_quant_bounds[3] = {9257, 11665, 14696}; #endif /* This is an ugly compatibility hack that properly resets the stereo state In case it it compiled in fixed-point, but initialised with the deprecated floating point static initialiser */ #ifdef FIXED_POINT -#define COMPATIBILITY_HACK(s) do {if ((s)->reserved1 != 0xdeadbeef) speex_stereo_state_init(s); } while (0); +#define COMPATIBILITY_HACK(s) do {if ((s)->reserved1 != 0xdeadbeef) speex_stereo_state_reset((SpeexStereoState*)s); } while (0); #else #define COMPATIBILITY_HACK(s) #endif @@ -134,8 +136,8 @@ void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits) speex_bits_pack(bits, (int)balance, 5); - /* FIXME: Convert properly */ - tmp=vq_index(&e_ratio, e_ratio_quant, 1, 4); + /* FIXME: this is a hack */ + tmp=scal_quant(e_ratio*Q15_ONE, e_ratio_quant_bounds, 3); speex_bits_pack(bits, tmp, 2); } @@ -171,8 +173,8 @@ void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits) speex_bits_pack(bits, (int)balance, 5); - /* FIXME: Convert properly */ - tmp=vq_index(&e_ratio, e_ratio_quant, 1, 4); + /* FIXME: this is a hack */ + tmp=scal_quant(e_ratio*Q15_ONE, e_ratio_quant_bounds, 3); speex_bits_pack(bits, tmp, 2); } #endif /* SPEEX_DISABLE_ENCODER */ diff --git a/apps/codecs/libspeex/vq.c b/apps/codecs/libspeex/vq.c index 1c66b32b16..fff470a588 100644 --- a/apps/codecs/libspeex/vq.c +++ b/apps/codecs/libspeex/vq.c @@ -70,29 +70,6 @@ int scal_quant32(spx_word32_t in, const spx_word32_t *boundary, int entries) return i; } -/*Finds the index of the entry in a codebook that best matches the input*/ -int vq_index(float *in, const float *codebook, int len, int entries) -{ - int i,j; - float min_dist=0; - int best_index=0; - for (i=0;i<entries;i++) - { - float dist=0; - for (j=0;j<len;j++) - { - float tmp = in[j]-*codebook++; - dist += tmp*tmp; - } - if (i==0 || dist<min_dist) - { - min_dist=dist; - best_index=i; - } - } - return best_index; -} - #ifndef OVERRIDE_VQ_NBEST /*Finds the indices of the n-best entries in a codebook*/ diff --git a/apps/codecs/libspeex/vq.h b/apps/codecs/libspeex/vq.h index 478d8696bd..5a4ced249c 100644 --- a/apps/codecs/libspeex/vq.h +++ b/apps/codecs/libspeex/vq.h @@ -40,7 +40,6 @@ int scal_quant(spx_word16_t in, const spx_word16_t *boundary, int entries); int scal_quant32(spx_word32_t in, const spx_word32_t *boundary, int entries); -int vq_index(float *in, const float *codebook, int len, int entries); #ifdef _USE_SSE #include <xmmintrin.h> void vq_nbest(spx_word16_t *in, const __m128 *codebook, int len, int entries, __m128 *E, int N, int *nbest, spx_word32_t *best_dist, char *stack); |