[xiph-commits] r11990 - trunk/speex/libspeex
jm at svn.xiph.org
jm at svn.xiph.org
Thu Nov 2 01:45:27 PST 2006
Author: jm
Date: 2006-11-02 01:45:22 -0800 (Thu, 02 Nov 2006)
New Revision: 11990
Modified:
trunk/speex/libspeex/filterbank.c
trunk/speex/libspeex/filterbank.h
trunk/speex/libspeex/fixed_debug.h
Log:
Converted part of the filterbank and added MULT16_32_P15() to
the fixed-point debug build.
Modified: trunk/speex/libspeex/filterbank.c
===================================================================
--- trunk/speex/libspeex/filterbank.c 2006-11-02 08:37:08 UTC (rev 11989)
+++ trunk/speex/libspeex/filterbank.c 2006-11-02 09:45:22 UTC (rev 11990)
@@ -41,7 +41,13 @@
#define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
#define toMEL(n) (2595.f*log10(1.f+(n)/700.f))
-
+
+#ifdef FIXED_POINT
+#define Q15(x) (floor(.5+32767.*(x)))
+#else
+#define Q15(x) (x)
+#endif
+
FilterBank *filterbank_new(int banks, float sampling, int len, int type)
{
FilterBank *bank;
@@ -58,8 +64,8 @@
bank->len = len;
bank->bank_left = speex_alloc(len*sizeof(int));
bank->bank_right = speex_alloc(len*sizeof(int));
- bank->filter_left = speex_alloc(len*sizeof(float));
- bank->filter_right = speex_alloc(len*sizeof(float));
+ bank->filter_left = speex_alloc(len*sizeof(spx_word16_t));
+ bank->filter_right = speex_alloc(len*sizeof(spx_word16_t));
bank->scaling = speex_alloc(banks*sizeof(float));
for (i=0;i<len;i++)
@@ -81,9 +87,9 @@
}
id2 = id1+1;
bank->bank_left[i] = id1;
- bank->filter_left[i] = 1-val;
+ bank->filter_left[i] = Q15(1-val);
bank->bank_right[i] = id2;
- bank->filter_right[i] = val;
+ bank->filter_right[i] = Q15(val);
}
for (i=0;i<bank->nb_banks;i++)
@@ -96,7 +102,7 @@
bank->scaling[id] += bank->filter_right[i];
}
for (i=0;i<bank->nb_banks;i++)
- bank->scaling[i] = 1./(bank->scaling[i]);
+ bank->scaling[i] = Q15_ONE/(bank->scaling[i]);
return bank;
}
@@ -119,13 +125,14 @@
for (i=0;i<bank->len;i++)
{
- int id = bank->bank_left[i];
- mel[id] += bank->filter_left[i]*ps[i];
+ int id;
+ id = bank->bank_left[i];
+ mel[id] += MULT16_32_P15(bank->filter_left[i],ps[i]);
id = bank->bank_right[i];
- mel[id] += bank->filter_right[i]*ps[i];
+ mel[id] += MULT16_32_P15(bank->filter_right[i],ps[i]);
}
for (i=0;i<bank->nb_banks;i++)
- mel[i] *= bank->scaling[i];
+ mel[i] = MULT16_32_P15(Q15(bank->scaling[i]),mel[i]);
}
@@ -164,10 +171,13 @@
int i;
for (i=0;i<bank->len;i++)
{
- int id = bank->bank_left[i];
- ps[i] = mel[id]*bank->filter_left[i];
- id = bank->bank_right[i];
- ps[i] += mel[id]*bank->filter_right[i];
+ spx_word32_t tmp;
+ int id1, id2;
+ id1 = bank->bank_left[i];
+ id2 = bank->bank_right[i];
+ tmp = MULT16_16(mel[id1],bank->filter_left[i]);
+ tmp += MULT16_16(mel[id2],bank->filter_right[i]);
+ ps[i] = EXTRACT16(PSHR32(tmp,15));
}
}
Modified: trunk/speex/libspeex/filterbank.h
===================================================================
--- trunk/speex/libspeex/filterbank.h 2006-11-02 08:37:08 UTC (rev 11989)
+++ trunk/speex/libspeex/filterbank.h 2006-11-02 09:45:22 UTC (rev 11990)
@@ -39,8 +39,8 @@
typedef struct {
int *bank_left;
int *bank_right;
- float *filter_left;
- float *filter_right;
+ spx_word16_t *filter_left;
+ spx_word16_t *filter_right;
float *scaling;
int nb_banks;
int len;
Modified: trunk/speex/libspeex/fixed_debug.h
===================================================================
--- trunk/speex/libspeex/fixed_debug.h 2006-11-02 08:37:08 UTC (rev 11989)
+++ trunk/speex/libspeex/fixed_debug.h 2006-11-02 09:45:22 UTC (rev 11990)
@@ -271,13 +271,28 @@
return res;
}
+static inline int MULT16_32_PX(int a, long long b, int Q)
+{
+ long long res;
+ if (!VERIFY_SHORT(a) || !VERIFY_INT(b))
+ {
+ fprintf (stderr, "MULT16_32_Q%d: inputs are not short+int: %d %d\n", Q, (int)a, (int)b);
+ }
+ res = ((((long long)a)*(long long)b) + ((1<<Q)>>1))>> Q;
+ if (!VERIFY_INT(res))
+ fprintf (stderr, "MULT16_32_Q%d: output is not int: %d*%d=%d\n", Q, (int)a, (int)b,(int)res);
+ spx_mips+=5;
+ return res;
+}
+
#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)
+#define MULT16_32_P15(a,b) MULT16_32_PX(a,b,15)
#define MAC16_32_Q15(c,a,b) ADD32((c),MULT16_32_Q15((a),(b)))
static inline int SATURATE(int a, int b)
More information about the commits
mailing list