Skip to content

Commit

Permalink
Update libspeex
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutchman101 committed Feb 17, 2025
1 parent 0bb9d5f commit e8fe4ea
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 37 deletions.
5 changes: 2 additions & 3 deletions vendor/libspeex/libspeex/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ typedef spx_word32_t spx_sig_t;
#define SIG_SHIFT 14
#define GAIN_SHIFT 6

#define EPSILON 1
#define VERY_SMALL 0
#define VERY_LARGE32 ((spx_word32_t)2147483647)
#define VERY_LARGE16 ((spx_word16_t)32767)
Expand Down Expand Up @@ -148,6 +149,7 @@ typedef float spx_word32_t;
#define GAIN_SCALING_1 1.f


#define EPSILON 1e-15f
#define VERY_SMALL 1e-15f
#define VERY_LARGE32 1e15f
#define VERY_LARGE16 1e15f
Expand Down Expand Up @@ -183,16 +185,13 @@ typedef float spx_word32_t;
#define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b))
#define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))

#define MULT16_32_Q11(a,b) ((a)*(b))
#define MULT16_32_Q13(a,b) ((a)*(b))
#define MULT16_32_Q14(a,b) ((a)*(b))
#define MULT16_32_Q15(a,b) ((a)*(b))
#define MULT16_32_P15(a,b) ((a)*(b))

#define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))

#define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
#define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
#define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
#define MULT16_16_Q11_32(a,b) ((a)*(b))
Expand Down
18 changes: 0 additions & 18 deletions vendor/libspeex/libspeex/fixed_arm5e.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,6 @@ static inline spx_word32_t MAC16_32_Q15(spx_word32_t a, spx_word16_t x, spx_word
return(res);
}

#undef MULT16_32_Q11
static inline spx_word32_t MULT16_32_Q11(spx_word16_t x, spx_word32_t y) {
int res;
asm ("smulwb %0,%1,%2;\n"
: "=&r"(res)
: "%r"(y<<5),"r"(x));
return(res);
}

#undef MAC16_32_Q11
static inline spx_word32_t MAC16_32_Q11(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
int res;
asm ("smlawb %0,%1,%2,%3;\n"
: "=&r"(res)
: "%r"(y<<5),"r"(x),"r"(a));
return(res);
}

#undef DIV32_16
static inline short DIV32_16(int a, int b)
{
Expand Down
3 changes: 0 additions & 3 deletions vendor/libspeex/libspeex/fixed_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,6 @@ static inline int MULT16_32_PX(int a, long long b, int Q)
}


#define MULT16_32_Q11(a,b) MULT16_32_QX(a,b,11)
#define MAC16_32_Q11(c,a,b) ADD32((c),MULT16_32_Q11((a),(b)))
#define MULT16_32_Q12(a,b) MULT16_32_QX(a,b,12)
#define MULT16_32_Q13(a,b) MULT16_32_QX(a,b,13)
#define MULT16_32_Q14(a,b) MULT16_32_QX(a,b,14)
#define MULT16_32_Q15(a,b) MULT16_32_QX(a,b,15)
Expand Down
4 changes: 0 additions & 4 deletions vendor/libspeex/libspeex/fixed_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,9 @@
#define MULT16_16(a,b) (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b)))

#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
#define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
#define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
#define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))

#define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
#define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)))

#define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
#define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
Expand Down
2 changes: 1 addition & 1 deletion vendor/libspeex/libspeex/math_approx.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static inline spx_word16_t spx_sqrt(spx_word32_t x)
int k;
spx_word32_t rt;
k = spx_ilog4(x)-6;
x = VSHR32(x, (k<<1));
x = VSHR32(x, (int)((unsigned)k<<1));
rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
rt = VSHR32(rt,7-k);
return rt;
Expand Down
4 changes: 2 additions & 2 deletions vendor/libspeex/libspeex/nb_celp.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
int nol_pitch[6];
spx_word16_t nol_pitch_coef[6];

bw_lpc(0.9, interp_lpc, bw_lpc1, NB_ORDER);
bw_lpc(0.55, interp_lpc, bw_lpc2, NB_ORDER);
bw_lpc(QCONST16(0.9,15), interp_lpc, bw_lpc1, NB_ORDER);
bw_lpc(QCONST16(0.55,15), interp_lpc, bw_lpc2, NB_ORDER);

SPEEX_COPY(st->sw, st->winBuf, diff);
SPEEX_COPY(st->sw+diff, in, NB_FRAME_SIZE-diff);
Expand Down
7 changes: 4 additions & 3 deletions vendor/libspeex/libspeex/sb_celp.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits)
if (st->subframeSize==80)
gc = MULT16_16_P14(QCONST16(1.4142f,14), gc);

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

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

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

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

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

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

Expand Down
10 changes: 7 additions & 3 deletions vendor/libspeex/libspeex/stereo.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ EXPORT void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits
int balance_id;
#ifdef FIXED_POINT
int shift;
int sqr_shift;

/* Avoid overflows when summing squares */
sqr_shift = frame_size >= 512 ? 9 : 8;
#endif

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

for (i=0;i<frame_size;i++)
{
e_left += SHR32(MULT16_16(data[2*i],data[2*i]),8);
e_right += SHR32(MULT16_16(data[2*i+1],data[2*i+1]),8);
e_left += SHR32(MULT16_16(data[2*i],data[2*i]),sqr_shift);
e_right += SHR32(MULT16_16(data[2*i+1],data[2*i+1]),sqr_shift);
#ifdef FIXED_POINT
/* I think this is actually unbiased */
data[i] = SHR16(data[2*i],1)+PSHR16(data[2*i+1],1);
#else
data[i] = .5*(((float)data[2*i])+data[2*i+1]);
#endif
e_tot += SHR32(MULT16_16(data[i],data[i]),8);
e_tot += SHR32(MULT16_16(data[i],data[i]),sqr_shift);
}
if (e_left > e_right)
{
Expand Down

0 comments on commit e8fe4ea

Please # to comment.