Skip to content

Commit e8fe4ea

Browse files
committed
Update libspeex
1 parent 0bb9d5f commit e8fe4ea

File tree

8 files changed

+16
-37
lines changed

8 files changed

+16
-37
lines changed

vendor/libspeex/libspeex/arch.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ typedef spx_word32_t spx_sig_t;
107107
#define SIG_SHIFT 14
108108
#define GAIN_SHIFT 6
109109

110+
#define EPSILON 1
110111
#define VERY_SMALL 0
111112
#define VERY_LARGE32 ((spx_word32_t)2147483647)
112113
#define VERY_LARGE16 ((spx_word16_t)32767)
@@ -148,6 +149,7 @@ typedef float spx_word32_t;
148149
#define GAIN_SCALING_1 1.f
149150

150151

152+
#define EPSILON 1e-15f
151153
#define VERY_SMALL 1e-15f
152154
#define VERY_LARGE32 1e15f
153155
#define VERY_LARGE16 1e15f
@@ -183,16 +185,13 @@ typedef float spx_word32_t;
183185
#define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b))
184186
#define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
185187

186-
#define MULT16_32_Q11(a,b) ((a)*(b))
187188
#define MULT16_32_Q13(a,b) ((a)*(b))
188189
#define MULT16_32_Q14(a,b) ((a)*(b))
189190
#define MULT16_32_Q15(a,b) ((a)*(b))
190191
#define MULT16_32_P15(a,b) ((a)*(b))
191192

192-
#define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
193193
#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
194194

195-
#define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
196195
#define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
197196
#define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
198197
#define MULT16_16_Q11_32(a,b) ((a)*(b))

vendor/libspeex/libspeex/fixed_arm5e.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,6 @@ static inline spx_word32_t MAC16_32_Q15(spx_word32_t a, spx_word16_t x, spx_word
7171
return(res);
7272
}
7373

74-
#undef MULT16_32_Q11
75-
static inline spx_word32_t MULT16_32_Q11(spx_word16_t x, spx_word32_t y) {
76-
int res;
77-
asm ("smulwb %0,%1,%2;\n"
78-
: "=&r"(res)
79-
: "%r"(y<<5),"r"(x));
80-
return(res);
81-
}
82-
83-
#undef MAC16_32_Q11
84-
static inline spx_word32_t MAC16_32_Q11(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
85-
int res;
86-
asm ("smlawb %0,%1,%2,%3;\n"
87-
: "=&r"(res)
88-
: "%r"(y<<5),"r"(x),"r"(a));
89-
return(res);
90-
}
91-
9274
#undef DIV32_16
9375
static inline short DIV32_16(int a, int b)
9476
{

vendor/libspeex/libspeex/fixed_debug.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,6 @@ static inline int MULT16_32_PX(int a, long long b, int Q)
305305
}
306306

307307

308-
#define MULT16_32_Q11(a,b) MULT16_32_QX(a,b,11)
309-
#define MAC16_32_Q11(c,a,b) ADD32((c),MULT16_32_Q11((a),(b)))
310-
#define MULT16_32_Q12(a,b) MULT16_32_QX(a,b,12)
311308
#define MULT16_32_Q13(a,b) MULT16_32_QX(a,b,13)
312309
#define MULT16_32_Q14(a,b) MULT16_32_QX(a,b,14)
313310
#define MULT16_32_Q15(a,b) MULT16_32_QX(a,b,15)

vendor/libspeex/libspeex/fixed_generic.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,9 @@
7171
#define MULT16_16(a,b) (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b)))
7272

7373
#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
74-
#define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
7574
#define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
7675
#define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))
7776

78-
#define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
79-
#define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)))
80-
8177
#define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
8278
#define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
8379
#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))

vendor/libspeex/libspeex/math_approx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static inline spx_word16_t spx_sqrt(spx_word32_t x)
144144
int k;
145145
spx_word32_t rt;
146146
k = spx_ilog4(x)-6;
147-
x = VSHR32(x, (k<<1));
147+
x = VSHR32(x, (int)((unsigned)k<<1));
148148
rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149149
rt = VSHR32(rt,7-k);
150150
return rt;

vendor/libspeex/libspeex/nb_celp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
508508
int nol_pitch[6];
509509
spx_word16_t nol_pitch_coef[6];
510510

511-
bw_lpc(0.9, interp_lpc, bw_lpc1, NB_ORDER);
512-
bw_lpc(0.55, interp_lpc, bw_lpc2, NB_ORDER);
511+
bw_lpc(QCONST16(0.9,15), interp_lpc, bw_lpc1, NB_ORDER);
512+
bw_lpc(QCONST16(0.55,15), interp_lpc, bw_lpc2, NB_ORDER);
513513

514514
SPEEX_COPY(st->sw, st->winBuf, diff);
515515
SPEEX_COPY(st->sw+diff, in, NB_FRAME_SIZE-diff);

vendor/libspeex/libspeex/sb_celp.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits)
866866
if (st->subframeSize==80)
867867
gc = MULT16_16_P14(QCONST16(1.4142f,14), gc);
868868

869-
scale = SHL32(MULT16_16(PDIV32_16(SHL32(EXTEND32(gc),SIG_SHIFT-6),filter_ratio),(1+el)),6);
869+
scale = SHL32(MULT16_16(PDIV32_16(SHL32(EXTEND32(gc),SIG_SHIFT-6),MAX16(EPSILON,filter_ratio)),(1+el)),6);
870870

871871
compute_impulse_response(st->interp_qlpc, bw_lpc1, bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack);
872872

@@ -1370,7 +1370,8 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
13701370
quant = speex_bits_unpack_unsigned(bits, 5);
13711371
g= spx_exp(MULT16_16(QCONST16(.125f,11),(quant-10)));
13721372

1373-
g = PDIV32(g, filter_ratio);
1373+
/* Clamp to a minimum of epsilon to avoid division by 0 */
1374+
g = PDIV32(g, MAX16(EPSILON,filter_ratio));
13741375

13751376
for (i=0;i<st->subframeSize;i+=2)
13761377
{
@@ -1389,7 +1390,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
13891390
if (st->subframeSize==80)
13901391
gc = MULT16_16_P14(QCONST16(1.4142f,14),gc);
13911392

1392-
scale = SHL32(PDIV32(SHL32(MULT16_16(gc, el),3), filter_ratio),SIG_SHIFT-3);
1393+
scale = SHL32(PDIV32(SHL32(MULT16_16(gc, el),3), MAX16(EPSILON,filter_ratio)),SIG_SHIFT-3);
13931394
SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize,
13941395
bits, stack, &st->seed);
13951396

vendor/libspeex/libspeex/stereo.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ EXPORT void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits
153153
int balance_id;
154154
#ifdef FIXED_POINT
155155
int shift;
156+
int sqr_shift;
157+
158+
/* Avoid overflows when summing squares */
159+
sqr_shift = frame_size >= 512 ? 9 : 8;
156160
#endif
157161

158162
/* In band marker */
@@ -162,15 +166,15 @@ EXPORT void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits
162166

163167
for (i=0;i<frame_size;i++)
164168
{
165-
e_left += SHR32(MULT16_16(data[2*i],data[2*i]),8);
166-
e_right += SHR32(MULT16_16(data[2*i+1],data[2*i+1]),8);
169+
e_left += SHR32(MULT16_16(data[2*i],data[2*i]),sqr_shift);
170+
e_right += SHR32(MULT16_16(data[2*i+1],data[2*i+1]),sqr_shift);
167171
#ifdef FIXED_POINT
168172
/* I think this is actually unbiased */
169173
data[i] = SHR16(data[2*i],1)+PSHR16(data[2*i+1],1);
170174
#else
171175
data[i] = .5*(((float)data[2*i])+data[2*i+1]);
172176
#endif
173-
e_tot += SHR32(MULT16_16(data[i],data[i]),8);
177+
e_tot += SHR32(MULT16_16(data[i],data[i]),sqr_shift);
174178
}
175179
if (e_left > e_right)
176180
{

0 commit comments

Comments
 (0)