Skip to content

Commit 6e31df2

Browse files
authored
Merge pull request #76 from joseph-yiu/main
AudioMark improvements on KWS unit test, floating-point handling, documentation.
2 parents 9ea7506 + c151b31 commit 6e31df2

21 files changed

Lines changed: 791 additions & 706 deletions

README.md

100644100755
Lines changed: 520 additions & 488 deletions
Large diffs are not rendered by default.

lib/speexdsp/include/speex/speex_echo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extern "C" {
4545
#endif
4646

4747
#ifndef M_PI
48-
#define M_PI 3.14159265358979323846
48+
#define M_PI 3.14159265358979323846f
4949
#endif
5050

5151
#ifdef FIXED_POINT

lib/speexdsp/libspeexdsp/arch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ typedef float spx_word32_t;
149149
#define VERY_LARGE16 1e15f
150150
#define Q15_ONE ((spx_word16_t)1.f)
151151

152+
#define Q0CONST(x) ((float)(x))
152153
#define QCONST16(x,bits) (x)
153154
#define QCONST32(x,bits) (x)
154155

@@ -203,7 +204,7 @@ typedef float spx_word32_t;
203204
#define PDIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
204205

205206
#define WORD2INT(x) ((x) < -32767.5f ? -32768 : \
206-
((x) > 32766.5f ? 32767 : (spx_int16_t)floor(.5 + (x))))
207+
((x) > 32766.5f ? 32767 : (spx_int16_t)floorf(.5f + (x))))
207208
#endif
208209

209210

lib/speexdsp/libspeexdsp/filterbank.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
#define toBARK(n) (MULT16_16(26829,spx_atan(SHR32(MULT16_16(97,n),2))) + MULT16_16(4588,spx_atan(MULT16_32_Q15(20,MULT16_16(n,n)))) + MULT16_16(3355,n))
4747

4848
#else
49-
#define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
49+
#define toBARK(n) (13.1f*atanf(.00074f*(n))+2.24f*atanf((n)*(n)*1.85e-8f)+1e-4f*(n))
5050
#endif
5151

52-
#define toMEL(n) (2595.f*log10(1.f+(n)/700.f))
52+
#define toMEL(n) (2595.f*log10f(1.f+(n)/700.f))
5353

5454
/* Optimized filter bank routines */
5555
#include "filterbank_opt.c"

lib/speexdsp/libspeexdsp/fixed_debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
extern long long spx_mips;
4141
#define MIPS_INC spx_mips++,
4242

43-
#define QCONST16(x,bits) ((spx_word16_t)(.5+(x)*(((spx_word32_t)1)<<(bits))))
44-
#define QCONST32(x,bits) ((spx_word32_t)(.5+(x)*(((spx_word32_t)1)<<(bits))))
43+
#define QCONST16(x,bits) ((spx_word16_t)(.5f+(x)*(((spx_word32_t)1)<<(bits))))
44+
#define QCONST32(x,bits) ((spx_word32_t)(.5f+(x)*(((spx_word32_t)1)<<(bits))))
4545

4646

4747
#define VERIFY_SHORT(x) ((x)<=32767&&(x)>=-32768)

lib/speexdsp/libspeexdsp/fixed_generic.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
#ifndef FIXED_GENERIC_H
3636
#define FIXED_GENERIC_H
3737

38-
#define QCONST16(x,bits) ((spx_word16_t)(.5+(x)*(((spx_word32_t)1)<<(bits))))
39-
#define QCONST32(x,bits) ((spx_word32_t)(.5+(x)*(((spx_word32_t)1)<<(bits))))
38+
#define Q0CONST(x) (x)
39+
#define QCONST16(x,bits) ((spx_word16_t)(.5f+(x)*(((spx_word32_t)1)<<(bits))))
40+
#define QCONST32(x,bits) ((spx_word32_t)(.5f+(x)*(((spx_word32_t)1)<<(bits))))
4041

4142
#define NEG16(x) (-(x))
4243
#define NEG32(x) (-(x))

lib/speexdsp/libspeexdsp/math_approx.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939

4040
#ifndef FIXED_POINT
4141

42-
#define spx_sqrt sqrt
43-
#define spx_acos acos
44-
#define spx_exp exp
45-
#define spx_cos_norm(x) (cos((.5f*M_PI)*(x)))
46-
#define spx_atan atan
42+
#define spx_sqrt sqrtf
43+
#define spx_acos acosf
44+
#define spx_exp expf
45+
#define spx_cos_norm(x) (cosf((.5f*M_PI)*(x)))
46+
#define spx_atan atanf
4747

4848
/** Generate a pseudo-random number */
4949
static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed)

lib/speexdsp/libspeexdsp/mdf.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ static inline void filter_dc_notch16(const spx_int16_t *in, spx_word16_t radius,
181181
int i;
182182
spx_word16_t den2;
183183
#ifdef FIXED_POINT
184-
den2 = MULT16_16_Q15(radius,radius) + MULT16_16_Q15(QCONST16(.7,15),MULT16_16_Q15(32767-radius,32767-radius));
184+
den2 = MULT16_16_Q15(radius,radius) + MULT16_16_Q15(QCONST16(.7f,15),MULT16_16_Q15(32767-radius,32767-radius));
185185
#else
186-
den2 = radius*radius + .7*(1-radius)*(1-radius);
186+
den2 = radius*radius + .7f*(1.0f-radius)*(1.0f-radius);
187187
#endif
188188
/*printf ("%d %d %d %d %d %d\n", num[0], num[1], num[2], den[0], den[1], den[2]);*/
189189
for (i=0;i<len;i++)
@@ -193,7 +193,7 @@ static inline void filter_dc_notch16(const spx_int16_t *in, spx_word16_t radius,
193193
#ifdef FIXED_POINT
194194
mem[0] = mem[1] + SHL32(SHL32(-EXTEND32(vin),15) + MULT16_32_Q15(radius,vout),1);
195195
#else
196-
mem[0] = mem[1] + 2*(-vin + radius*vout);
196+
mem[0] = mem[1] + 2.0f*(-vin + radius*vout);
197197
#endif
198198
mem[1] = SHL32(EXTEND32(vin),15) - MULT16_32_Q15(den2,vout);
199199
out[i] = SATURATE32(PSHR32(MULT16_32_Q15(radius,vout),15),32767);
@@ -485,7 +485,7 @@ EXPORT SpeexEchoState *speex_echo_state_init_mc(int frame_size, int filter_lengt
485485
}
486486
#else
487487
for (i=0;i<N;i++)
488-
st->window[i] = .5-.5*cos(2*M_PI*i/N);
488+
st->window[i] = .5f-.5f*cosf(2*M_PI*i/N);
489489
#endif
490490
for (i=0;i<=st->frame_size;i++)
491491
st->power_1[i] = FLOAT_ONE;
@@ -494,8 +494,8 @@ EXPORT SpeexEchoState *speex_echo_state_init_mc(int frame_size, int filter_lengt
494494
{
495495
spx_word32_t sum = 0;
496496
/* Ratio of ~10 between adaptation rate of first and last block */
497-
spx_word16_t decay = SHR32(spx_exp(NEG16(DIV32_16(QCONST16(2.4,11),M))),1);
498-
st->prop[0] = QCONST16(.7, 15);
497+
spx_word16_t decay = SHR32(spx_exp(NEG16(DIV32_16(QCONST16(2.4f,11),M))),1);
498+
st->prop[0] = QCONST16(.7f, 15);
499499
sum = EXTEND32(st->prop[0]);
500500
for (i=1;i<M;i++)
501501
{
@@ -511,13 +511,13 @@ EXPORT SpeexEchoState *speex_echo_state_init_mc(int frame_size, int filter_lengt
511511
st->memX = (spx_word16_t*)speex_alloc(K*sizeof(spx_word16_t));
512512
st->memD = (spx_word16_t*)speex_alloc(C*sizeof(spx_word16_t));
513513
st->memE = (spx_word16_t*)speex_alloc(C*sizeof(spx_word16_t));
514-
st->preemph = QCONST16(.9,15);
514+
st->preemph = QCONST16(.9f,15);
515515
if (st->sampling_rate<12000)
516-
st->notch_radius = QCONST16(.9, 15);
516+
st->notch_radius = QCONST16(.9f, 15);
517517
else if (st->sampling_rate<24000)
518-
st->notch_radius = QCONST16(.982, 15);
518+
st->notch_radius = QCONST16(.982f, 15);
519519
else
520-
st->notch_radius = QCONST16(.992, 15);
520+
st->notch_radius = QCONST16(.992f, 15);
521521

522522
st->notch_mem = (spx_mem_t*)speex_alloc(2*C*sizeof(spx_mem_t));
523523
st->adapted = 0;
@@ -724,8 +724,8 @@ EXPORT void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, c
724724
ss=DIV32_16(11469,M);
725725
ss_1 = SUB16(32767,ss);
726726
#else
727-
ss=.35/M;
728-
ss_1 = 1-ss;
727+
ss=.35f/M;
728+
ss_1 = 1.0f-ss;
729729
#endif
730730

731731
for (chan = 0; chan < C; chan++)
@@ -1103,7 +1103,7 @@ EXPORT void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, c
11031103
/* Do some sanity check */
11041104
if (!(Syy>=0 && Sxx>=0 && See >= 0)
11051105
#ifndef FIXED_POINT
1106-
|| !(Sff < N*1e9 && Syy < N*1e9 && Sxx < N*1e9)
1106+
|| !(Sff < N*1e9f && Syy < N*1e9f && Sxx < N*1e9f)
11071107
#endif
11081108
)
11091109
{
@@ -1142,7 +1142,7 @@ EXPORT void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, c
11421142
#ifndef OVERRIDE_MDF_SMOOTH_FE_NRG
11431143
/* Smooth far end energy estimate over time */
11441144
for (j=0;j<=st->frame_size;j++)
1145-
st->power[j] = MULT16_32_Q15(ss_1,st->power[j]) + 1 + MULT16_32_Q15(ss,st->Xf[j]);
1145+
st->power[j] = MULT16_32_Q15(ss_1,st->power[j]) + Q0CONST(1) + MULT16_32_Q15(ss,st->Xf[j]);
11461146
#else
11471147
smooth_fe_nrg(st->power, ss_1, st->Xf, ss, st->power, st->frame_size + 1);
11481148
#endif
@@ -1211,12 +1211,12 @@ EXPORT void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, c
12111211
tmp32 = SHR32(See,1);
12121212
RER = FLOAT_EXTRACT16(FLOAT_SHL(FLOAT_DIV32(tmp32,See),15));
12131213
#else
1214-
RER = (.0001*Sxx + 3.*MULT16_32_Q15(st->leak_estimate,Syy)) / See;
1214+
RER = (.0001f*Sxx + 3.0f*MULT16_32_Q15(st->leak_estimate,Syy)) / See;
12151215
/* Check for y in e (lower bound on RER) */
1216-
if (RER < Sey*Sey/(1+See*Syy))
1217-
RER = Sey*Sey/(1+See*Syy);
1218-
if (RER > .5)
1219-
RER = .5;
1216+
if (RER < Sey*Sey/(1.0f+See*Syy))
1217+
RER = Sey*Sey/(1.0f+See*Syy);
1218+
if (RER > .5f)
1219+
RER = .5f;
12201220
#endif
12211221

12221222
/* We consider that the filter has had minimal adaptation if the following is true*/
@@ -1239,12 +1239,12 @@ EXPORT void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, c
12391239
if (r>SHR32(e,1))
12401240
r = SHR32(e,1);
12411241
#else
1242-
if (r>.5*e)
1243-
r = .5*e;
1242+
if (r>.5f*e)
1243+
r = .5f*e;
12441244
#endif
1245-
r = MULT16_32_Q15(QCONST16(.7,15),r) + MULT16_32_Q15(QCONST16(.3,15),(spx_word32_t)(MULT16_32_Q15(RER,e)));
1245+
r = MULT16_32_Q15(QCONST16(.7f,15),r) + MULT16_32_Q15(QCONST16(.3f,15),(spx_word32_t)(MULT16_32_Q15(RER,e)));
12461246
/*st->power_1[i] = adapt_rate*r/(e*(1+st->power[i]));*/
1247-
st->power_1[i] = FLOAT_SHL(FLOAT_DIV32_FLOAT(r,FLOAT_MUL32U(e,st->power[i]+10)),WEIGHT_SHIFT+16);
1247+
st->power_1[i] = FLOAT_SHL(FLOAT_DIV32_FLOAT(r,FLOAT_MUL32U(e,st->power[i]+Q0CONST(10))),WEIGHT_SHIFT+16);
12481248
}
12491249
#else
12501250
mdf_nominal_learning_rate_calc(st->Rf, st->power, st->Yf, st->power_1, st->leak_estimate, RER, st->frame_size + 1);
@@ -1260,14 +1260,14 @@ EXPORT void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, c
12601260
if (tmp32 > SHR32(See,2))
12611261
tmp32 = SHR32(See,2);
12621262
#else
1263-
if (tmp32 > .25*See)
1264-
tmp32 = .25*See;
1263+
if (tmp32 > .25f*See)
1264+
tmp32 = .25f*See;
12651265
#endif
12661266
adapt_rate = FLOAT_EXTRACT16(FLOAT_SHL(FLOAT_DIV32(tmp32, See),15));
12671267
}
12681268
#ifndef OVERRIDE_MDF_CONVERG_LEARN_RATE_CALC
12691269
for (i=0;i<=st->frame_size;i++)
1270-
st->power_1[i] = FLOAT_SHL(FLOAT_DIV32(EXTEND32(adapt_rate),ADD32(st->power[i],10)),WEIGHT_SHIFT+1);
1270+
st->power_1[i] = FLOAT_SHL(FLOAT_DIV32(EXTEND32(adapt_rate),ADD32(st->power[i],Q0CONST(10))),WEIGHT_SHIFT+1);
12711271
#else
12721272
mdf_non_adapt_learning_rate_calc(st->power, st->power_1, adapt_rate, st->frame_size + 1);
12731273
#endif
@@ -1328,7 +1328,7 @@ void speex_echo_get_residual(SpeexEchoState *st, spx_word32_t *residual_echo, in
13281328
else
13291329
leak2 = SHL16(st->leak_estimate, 1);
13301330
#else
1331-
if (st->leak_estimate>.5)
1331+
if (st->leak_estimate>.5f)
13321332
leak2 = 1;
13331333
else
13341334
leak2 = 2*st->leak_estimate;
@@ -1362,11 +1362,11 @@ EXPORT int speex_echo_ctl(SpeexEchoState *st, int request, void *ptr)
13621362
st->beta_max = (.5f*st->frame_size)/st->sampling_rate;
13631363
#endif
13641364
if (st->sampling_rate<12000)
1365-
st->notch_radius = QCONST16(.9, 15);
1365+
st->notch_radius = QCONST16(.9f, 15);
13661366
else if (st->sampling_rate<24000)
1367-
st->notch_radius = QCONST16(.982, 15);
1367+
st->notch_radius = QCONST16(.982f, 15);
13681368
else
1369-
st->notch_radius = QCONST16(.992, 15);
1369+
st->notch_radius = QCONST16(.992f, 15);
13701370
break;
13711371
case SPEEX_ECHO_GET_SAMPLING_RATE:
13721372
(*(int*)ptr) = st->sampling_rate;

lib/speexdsp/libspeexdsp/mdf_opt_generic.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ static void filter_dc_notch16(const spx_int16_t * in, spx_word16_t radius, spx_w
4545
int i;
4646
spx_word16_t den2;
4747
#ifdef FIXED_POINT
48-
den2 = MULT16_16_Q15(radius, radius) + MULT16_16_Q15(QCONST16(.7, 15), MULT16_16_Q15(32767 - radius, 32767 - radius));
48+
den2 = MULT16_16_Q15(radius, radius) + MULT16_16_Q15(QCONST16(.7f, 15), MULT16_16_Q15(32767 - radius, 32767 - radius));
4949
#else
50-
den2 = radius * radius + .7 * (1 - radius) * (1 - radius);
50+
den2 = radius * radius + .7f * (1.0f - radius) * (1.0f - radius);
5151
#endif
5252
/*printf ("%d %d %d %d %d %d\n", num[0], num[1], num[2], den[0], den[1], den[2]); */
5353
for (i = 0; i < len; i++) {
@@ -56,7 +56,7 @@ static void filter_dc_notch16(const spx_int16_t * in, spx_word16_t radius, spx_w
5656
#ifdef FIXED_POINT
5757
mem[0] = mem[1] + SHL32(SHL32(-EXTEND32(vin), 15) + MULT16_32_Q15(radius, vout), 1);
5858
#else
59-
mem[0] = mem[1] + 2 * (-vin + radius * vout);
59+
mem[0] = mem[1] + 2.0f * (-vin + radius * vout);
6060
#endif
6161
mem[1] = SHL32(EXTEND32(vin), 15) - MULT16_32_Q15(den2, vout);
6262
out[i] = SATURATE32(PSHR32(MULT16_32_Q15(radius, vout), 15), 32767);
@@ -415,7 +415,7 @@ static void smooth_fe_nrg(spx_word32_t * in1, spx_word16_t c1, spx_word32_t * in
415415
int j;
416416

417417
for (j = 0; j <= frame_size; j++)
418-
pDst[j] = MULT16_32_Q15(c1, in1[j]) + 1 + MULT16_32_Q15(c2, in2[j]);
418+
pDst[j] = MULT16_32_Q15(c1, in1[j]) + Q0CONST(1) + MULT16_32_Q15(c2, in2[j]);
419419
}
420420
#endif
421421

@@ -458,12 +458,12 @@ static void mdf_nominal_learning_rate_calc(spx_word32_t * pRf, spx_word32_t * po
458458
if (r > SHR32(e, 1))
459459
r = SHR32(e, 1);
460460
#else
461-
if (r > .5 * e)
462-
r = .5 * e;
461+
if (r > .5f * e)
462+
r = .5f * e;
463463
#endif
464-
r = MULT16_32_Q15(QCONST16(.7, 15), r) + MULT16_32_Q15(QCONST16(.3, 15), (spx_word32_t) (MULT16_32_Q15(RER, e)));
464+
r = MULT16_32_Q15(QCONST16(.7f, 15), r) + MULT16_32_Q15(QCONST16(.3f, 15), (spx_word32_t) (MULT16_32_Q15(RER, e)));
465465
/*st->power_1[i] = adapt_rate*r/(e*(1+st->power[i])); */
466-
power_1[i] = FLOAT_SHL(FLOAT_DIV32_FLOAT(r, FLOAT_MUL32U(e, power[i] + 10)), WEIGHT_SHIFT + 16);
466+
power_1[i] = FLOAT_SHL(FLOAT_DIV32_FLOAT(r, FLOAT_MUL32U(e, power[i] + 10.f)), WEIGHT_SHIFT + 16);
467467
}
468468
}
469469

@@ -475,7 +475,7 @@ static void mdf_non_adapt_learning_rate_calc(spx_word32_t * power, spx_float_t *
475475
int i;
476476

477477
for (i = 0; i < frame_size; i++)
478-
power_1[i] = FLOAT_SHL(FLOAT_DIV32(EXTEND32(adapt_rate), ADD32(power[i], 10)), WEIGHT_SHIFT + 1);
478+
power_1[i] = FLOAT_SHL(FLOAT_DIV32(EXTEND32(adapt_rate), ADD32(power[i], Q0CONST(10))), WEIGHT_SHIFT + 1);
479479
}
480480

481481
#endif

lib/speexdsp/libspeexdsp/mdf_opt_helium.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,8 @@ VISIB_ATTR void mdf_nominal_learning_rate_calc(spx_word32_t * pRf, spx_word32_t
733733
spx_word32_t * pYf, spx_float_t * power_1, spx_word16_t leak_estimate, spx_word16_t RER, uint16_t len)
734734
{
735735
int blockSize = len >> 2;
736-
float32_t cst_0_7 = QCONST16(.7, 15);
737-
float32_t cst_0_3 = QCONST16(.3, 15);
736+
float32_t cst_0_7 = QCONST16(.7f, 15);
737+
float32_t cst_0_3 = QCONST16(.3f, 15);
738738

739739
do {
740740
float32x4_t vecYf = vld1q(pYf);
@@ -771,10 +771,10 @@ VISIB_ATTR void mdf_nominal_learning_rate_calc(spx_word32_t * pRf, spx_word32_t
771771
r = MULT16_32_Q15(leak_estimate, SHL32(*pYf++, 3));
772772
e = SHL32(*pRf++, 3) + 1;
773773

774-
if (r > .5 * e)
775-
r = .5 * e;
774+
if (r > .5f * e)
775+
r = .5f * e;
776776

777-
r = MULT16_32_Q15(QCONST16(.7, 15), r) + MULT16_32_Q15(QCONST16(.3, 15), (spx_word32_t) (MULT16_32_Q15(RER, e)));
777+
r = MULT16_32_Q15(QCONST16(.7f, 15), r) + MULT16_32_Q15(QCONST16(.3f, 15), (spx_word32_t) (MULT16_32_Q15(RER, e)));
778778
/*st->power_1[i] = adapt_rate*r/(e*(1+st->power[i])); */
779779
*power_1++ = FLOAT_SHL(FLOAT_DIV32_FLOAT(r, FLOAT_MUL32U(e, *power++ + 10)), WEIGHT_SHIFT + 16);
780780
}
@@ -804,7 +804,7 @@ VISIB_ATTR void mdf_non_adapt_learning_rate_calc(spx_word32_t * power, spx_float
804804

805805
/* tail */
806806
for (int i = 0; i <= (len & 3); i++) {
807-
*power_1++ = FLOAT_SHL(FLOAT_DIV32(EXTEND32(adapt_rate), ADD32(*power++, 10)), WEIGHT_SHIFT + 1);
807+
*power_1++ = FLOAT_SHL(FLOAT_DIV32(EXTEND32(adapt_rate), ADD32(*power++, Q0CONST(10))), WEIGHT_SHIFT + 1);
808808
}
809809
}
810810

0 commit comments

Comments
 (0)