diff --git a/src/analysis.c b/src/analysis.c index 547e5a4b3e65d277a13f0c3a0033f4d61b1f93fd..6a1840b1e2eeb45734aab008b3ce4bb783f43791 100644 --- a/src/analysis.c +++ b/src/analysis.c @@ -327,6 +327,10 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info_out, con { float binE = out[i].r*(float)out[i].r + out[N-i].r*(float)out[N-i].r + out[i].i*(float)out[i].i + out[N-i].i*(float)out[N-i].i; +#ifdef FIXED_POINT + /* FIXME: It's probably best to change the BFCC filter initial state instead */ + binE *= 5.55e-17f; +#endif E += binE; tE += binE*tonality[i]; nE += binE*2.f*(.5f-noisiness[i]); @@ -479,7 +483,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info_out, con features[23] = info->tonality_slope; features[24] = tonal->lowECount; -#ifndef FIXED_POINT +#ifndef DISABLE_FLOAT_API mlp_process(&net, features, frame_probs); frame_probs[0] = .5f*(frame_probs[0]+1); /* Curve fitting between the MLP probability and the actual probability */ diff --git a/src/mlp.c b/src/mlp.c index dd7d34fc5001850cc0c52afee8778d33efd0235a..73b1d315b86b3a9372ec56b1def7a77e52e77e19 100644 --- a/src/mlp.c +++ b/src/mlp.c @@ -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 diff --git a/src/mlp.h b/src/mlp.h index 68ff68d82ef2fe5907c1c4cb486fbc2dd2fb3595..86c8e0617d0461797e6e104c1b06c20fb62a4f64 100644 --- a/src/mlp.h +++ b/src/mlp.h @@ -33,9 +33,9 @@ typedef struct { int layers; const int *topo; - const opus_val16 *weights; + const float *weights; } MLP; -void mlp_process(const MLP *m, const opus_val16 *in, opus_val16 *out); +void mlp_process(const MLP *m, const float *in, float *out); #endif /* _MLP_H_ */ diff --git a/src/tansig_table.h b/src/tansig_table.h index 885ea3e8d7dbd35dace96078db39c53d808557a2..c76f844a72f428eb0c1abf87f399acc8074118ca 100644 --- a/src/tansig_table.h +++ b/src/tansig_table.h @@ -1,6 +1,6 @@ /* This file is auto-generated by gen_tables */ -static const opus_val16 tansig_table[201] = { +static const float tansig_table[201] = { 0.000000f, 0.039979f, 0.079830f, 0.119427f, 0.158649f, 0.197375f, 0.235496f, 0.272905f, 0.309507f, 0.345214f, 0.379949f, 0.413644f, 0.446244f, 0.477700f, 0.507977f,