Skip to content
Snippets Groups Projects
Commit fc1b1f9b authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Makes speech/music detection work with FIXED_POINT (code still float)

parent 3ab03e05
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......
......@@ -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
......@@ -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_ */
/* 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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment