summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/libspeex/stereo.c14
-rw-r--r--apps/codecs/libspeex/vq.c23
-rw-r--r--apps/codecs/libspeex/vq.h1
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 {
45 spx_word32_t e_ratio; /**< Ratio of energies: E(left+right)/[E(left)+E(right)] */ 45 spx_word32_t e_ratio; /**< Ratio of energies: E(left+right)/[E(left)+E(right)] */
46 spx_word32_t smooth_left; /**< Smoothed left channel gain */ 46 spx_word32_t smooth_left; /**< Smoothed left channel gain */
47 spx_word32_t smooth_right; /**< Smoothed right channel gain */ 47 spx_word32_t smooth_right; /**< Smoothed right channel gain */
48 spx_int32_t reserved1; /**< Reserved for future use */ 48 spx_uint32_t reserved1; /**< Reserved for future use */
49 spx_int32_t reserved2; /**< Reserved for future use */ 49 spx_int32_t reserved2; /**< Reserved for future use */
50} RealSpeexStereoState; 50} RealSpeexStereoState;
51 51
@@ -53,15 +53,17 @@ typedef struct RealSpeexStereoState {
53/*float e_ratio_quant[4] = {1, 1.26, 1.587, 2};*/ 53/*float e_ratio_quant[4] = {1, 1.26, 1.587, 2};*/
54#ifndef FIXED_POINT 54#ifndef FIXED_POINT
55static const float e_ratio_quant[4] = {.25f, .315f, .397f, .5f}; 55static const float e_ratio_quant[4] = {.25f, .315f, .397f, .5f};
56static const float e_ratio_quant_bounds[3] = {0.2825f, 0.356f, 0.4485f};
56#else 57#else
57static const spx_word16_t e_ratio_quant[4] = {8192, 10332, 13009, 16384}; 58static const spx_word16_t e_ratio_quant[4] = {8192, 10332, 13009, 16384};
59static const spx_word16_t e_ratio_quant_bounds[3] = {9257, 11665, 14696};
58#endif 60#endif
59 61
60/* This is an ugly compatibility hack that properly resets the stereo state 62/* This is an ugly compatibility hack that properly resets the stereo state
61 In case it it compiled in fixed-point, but initialised with the deprecated 63 In case it it compiled in fixed-point, but initialised with the deprecated
62 floating point static initialiser */ 64 floating point static initialiser */
63#ifdef FIXED_POINT 65#ifdef FIXED_POINT
64#define COMPATIBILITY_HACK(s) do {if ((s)->reserved1 != 0xdeadbeef) speex_stereo_state_init(s); } while (0); 66#define COMPATIBILITY_HACK(s) do {if ((s)->reserved1 != 0xdeadbeef) speex_stereo_state_reset((SpeexStereoState*)s); } while (0);
65#else 67#else
66#define COMPATIBILITY_HACK(s) 68#define COMPATIBILITY_HACK(s)
67#endif 69#endif
@@ -134,8 +136,8 @@ void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits)
134 136
135 speex_bits_pack(bits, (int)balance, 5); 137 speex_bits_pack(bits, (int)balance, 5);
136 138
137 /* FIXME: Convert properly */ 139 /* FIXME: this is a hack */
138 tmp=vq_index(&e_ratio, e_ratio_quant, 1, 4); 140 tmp=scal_quant(e_ratio*Q15_ONE, e_ratio_quant_bounds, 3);
139 speex_bits_pack(bits, tmp, 2); 141 speex_bits_pack(bits, tmp, 2);
140} 142}
141 143
@@ -171,8 +173,8 @@ void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits)
171 173
172 speex_bits_pack(bits, (int)balance, 5); 174 speex_bits_pack(bits, (int)balance, 5);
173 175
174 /* FIXME: Convert properly */ 176 /* FIXME: this is a hack */
175 tmp=vq_index(&e_ratio, e_ratio_quant, 1, 4); 177 tmp=scal_quant(e_ratio*Q15_ONE, e_ratio_quant_bounds, 3);
176 speex_bits_pack(bits, tmp, 2); 178 speex_bits_pack(bits, tmp, 2);
177} 179}
178#endif /* SPEEX_DISABLE_ENCODER */ 180#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)
70 return i; 70 return i;
71} 71}
72 72
73/*Finds the index of the entry in a codebook that best matches the input*/
74int vq_index(float *in, const float *codebook, int len, int entries)
75{
76 int i,j;
77 float min_dist=0;
78 int best_index=0;
79 for (i=0;i<entries;i++)
80 {
81 float dist=0;
82 for (j=0;j<len;j++)
83 {
84 float tmp = in[j]-*codebook++;
85 dist += tmp*tmp;
86 }
87 if (i==0 || dist<min_dist)
88 {
89 min_dist=dist;
90 best_index=i;
91 }
92 }
93 return best_index;
94}
95
96 73
97#ifndef OVERRIDE_VQ_NBEST 74#ifndef OVERRIDE_VQ_NBEST
98/*Finds the indices of the n-best entries in a codebook*/ 75/*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 @@
40int scal_quant(spx_word16_t in, const spx_word16_t *boundary, int entries); 40int scal_quant(spx_word16_t in, const spx_word16_t *boundary, int entries);
41int scal_quant32(spx_word32_t in, const spx_word32_t *boundary, int entries); 41int scal_quant32(spx_word32_t in, const spx_word32_t *boundary, int entries);
42 42
43int vq_index(float *in, const float *codebook, int len, int entries);
44#ifdef _USE_SSE 43#ifdef _USE_SSE
45#include <xmmintrin.h> 44#include <xmmintrin.h>
46void 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); 45void 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);