diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2013-09-07 00:32:50 +0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2013-09-07 00:32:50 +0400 |
commit | fc1b1f9b441c2ffe090046c968e5d95f2eafb038 (patch) | |
tree | 9c534200eaf4e654c630c3a65624f9d25e37871a /src/mlp.c | |
parent | 3ab03e05561f81f0eacac3ee724baac33b89683b (diff) |
Makes speech/music detection work with FIXED_POINT (code still float)
Diffstat (limited to 'src/mlp.c')
-rw-r--r-- | src/mlp.c | 35 |
1 files changed, 30 insertions, 5 deletions
@@ -35,7 +35,7 @@ #include "tansig_table.h" #define MAX_NEURONS 100 -#ifdef FIXED_POINT +#if 0 static inline opus_val16 tansig_approx(opus_val32 _x) /* Q19 */ { int i; @@ -62,11 +62,11 @@ static inline opus_val16 tansig_approx(opus_val32 _x) /* Q19 */ } #else /*extern const float tansig_table[501];*/ -static inline opus_val16 tansig_approx(opus_val16 x) +static inline float tansig_approx(float x) { int i; - opus_val16 y, dy; - opus_val16 sign=1; + float y, dy; + float sign=1; if (x>=8) return 1; if (x<=-8) @@ -85,6 +85,7 @@ static inline opus_val16 tansig_approx(opus_val16 x) } #endif +#if 0 void mlp_process(const MLP *m, const opus_val16 *in, opus_val16 *out) { int j; @@ -108,4 +109,28 @@ void mlp_process(const MLP *m, const opus_val16 *in, opus_val16 *out) out[j] = tansig_approx(EXTRACT16(PSHR32(sum,17))); } } - +#else +void mlp_process(const MLP *m, const float *in, float *out) +{ + int j; + float hidden[MAX_NEURONS]; + const float *W = m->weights; + /* Copy to tmp_in */ + for (j=0;j<m->topo[1];j++) + { + int k; + float sum = *W++; + for (k=0;k<m->topo[0];k++) + sum = sum + in[k]**W++; + hidden[j] = tansig_approx(sum); + } + for (j=0;j<m->topo[2];j++) + { + int k; + float sum = *W++; + for (k=0;k<m->topo[1];k++) + sum = sum + hidden[k]**W++; + out[j] = tansig_approx(sum); + } +} +#endif |