ref: fc1b1f9b441c2ffe090046c968e5d95f2eafb038
parent: 3ab03e05561f81f0eacac3ee724baac33b89683b
author: Jean-Marc Valin <[email protected]>
date: Fri Sep 6 12:32:50 EDT 2013
Makes speech/music detection work with FIXED_POINT (code still float)
--- a/src/analysis.c
+++ b/src/analysis.c
@@ -327,6 +327,10 @@
{
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 @@
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 */
--- 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 @@
}
#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 @@
}
#endif
+#if 0
void mlp_process(const MLP *m, const opus_val16 *in, opus_val16 *out)
{
int j;
@@ -108,4 +109,28 @@
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
--- 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_ */
--- 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,