mirror of
https://github.com/xiph/opus.git
synced 2025-06-06 07:21:03 +00:00
Fixes MSVC warnings for double->float and float->int conversion
This commit is contained in:
parent
b5f739455d
commit
d683c76b88
3 changed files with 83 additions and 84 deletions
|
@ -215,7 +215,7 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int
|
||||||
int is_transient = 0;
|
int is_transient = 0;
|
||||||
opus_int32 mask_metric = 0;
|
opus_int32 mask_metric = 0;
|
||||||
int c;
|
int c;
|
||||||
int tf_max;
|
opus_val16 tf_max;
|
||||||
int len2;
|
int len2;
|
||||||
/* Table of 6*64/x, trained on real data to minimize the average error */
|
/* Table of 6*64/x, trained on real data to minimize the average error */
|
||||||
static const unsigned char inv_table[128] = {
|
static const unsigned char inv_table[128] = {
|
||||||
|
@ -318,7 +318,7 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int
|
||||||
/* Costs two sqrt() to avoid overflows */
|
/* Costs two sqrt() to avoid overflows */
|
||||||
mean = MULT16_16(celt_sqrt(mean), celt_sqrt(MULT16_16(maxE,len2>>1)));
|
mean = MULT16_16(celt_sqrt(mean), celt_sqrt(MULT16_16(maxE,len2>>1)));
|
||||||
#else
|
#else
|
||||||
mean = sqrt(mean * maxE*.5*len2);
|
mean = celt_sqrt(mean * maxE*.5*len2);
|
||||||
#endif
|
#endif
|
||||||
/* Inverse of the mean energy in Q15+6 */
|
/* Inverse of the mean energy in Q15+6 */
|
||||||
norm = SHL32(EXTEND32(len2),6+14)/ADD32(EPSILON,SHR32(mean,1));
|
norm = SHL32(EXTEND32(len2),6+14)/ADD32(EPSILON,SHR32(mean,1));
|
||||||
|
@ -331,7 +331,7 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int
|
||||||
#ifdef FIXED_POINT
|
#ifdef FIXED_POINT
|
||||||
id = IMAX(0,IMIN(127,MULT16_32_Q15(tmp[i],norm))); /* Do not round to nearest */
|
id = IMAX(0,IMIN(127,MULT16_32_Q15(tmp[i],norm))); /* Do not round to nearest */
|
||||||
#else
|
#else
|
||||||
id = IMAX(0,IMIN(127,floor(64*norm*tmp[i]))); /* Do not round to nearest */
|
id = IMAX(0,IMIN(127,(int)floor(64*norm*tmp[i]))); /* Do not round to nearest */
|
||||||
#endif
|
#endif
|
||||||
unmask += inv_table[id];
|
unmask += inv_table[id];
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int
|
||||||
/* Arbitrary metric for VBR boost */
|
/* Arbitrary metric for VBR boost */
|
||||||
tf_max = MAX16(0,celt_sqrt(27*mask_metric)-42);
|
tf_max = MAX16(0,celt_sqrt(27*mask_metric)-42);
|
||||||
/* *tf_estimate = 1 + MIN16(1, sqrt(MAX16(0, tf_max-30))/20); */
|
/* *tf_estimate = 1 + MIN16(1, sqrt(MAX16(0, tf_max-30))/20); */
|
||||||
*tf_estimate = celt_sqrt(MAX16(0, SHL32(MULT16_16(QCONST16(0.0069,14),IMIN(163,tf_max)),14)-QCONST32(0.139,28)));
|
*tf_estimate = celt_sqrt(MAX16(0, SHL32(MULT16_16(QCONST16(0.0069,14),MIN16(163,tf_max)),14)-QCONST32(0.139,28)));
|
||||||
/*printf("%d %f\n", tf_max, mask_metric);*/
|
/*printf("%d %f\n", tf_max, mask_metric);*/
|
||||||
RESTORE_STACK;
|
RESTORE_STACK;
|
||||||
#ifdef FUZZING
|
#ifdef FUZZING
|
||||||
|
@ -755,14 +755,14 @@ static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X,
|
||||||
#ifndef FIXED_POINT
|
#ifndef FIXED_POINT
|
||||||
if (analysis->valid)
|
if (analysis->valid)
|
||||||
{
|
{
|
||||||
trim -= MAX16(-QCONST16(2.f, 8), MIN16(QCONST16(2.f, 8), 2*(analysis->tonality_slope+.05)));
|
trim -= MAX16(-QCONST16(2.f, 8), MIN16(QCONST16(2.f, 8), 2*(analysis->tonality_slope+.05f)));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FIXED_POINT
|
#ifdef FIXED_POINT
|
||||||
trim_index = PSHR32(trim, 8);
|
trim_index = PSHR32(trim, 8);
|
||||||
#else
|
#else
|
||||||
trim_index = floor(.5+trim);
|
trim_index = (int)floor(.5f+trim);
|
||||||
#endif
|
#endif
|
||||||
if (trim_index<0)
|
if (trim_index<0)
|
||||||
trim_index = 0;
|
trim_index = 0;
|
||||||
|
@ -807,7 +807,7 @@ static int stereo_analysis(const CELTMode *m, const celt_norm *X,
|
||||||
> MULT16_32_Q15(m->eBands[13]<<(LM+1), sumLR);
|
> MULT16_32_Q15(m->eBands[13]<<(LM+1), sumLR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 *bandLogE2,
|
static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 *bandLogE2,
|
||||||
int nbEBands, int start, int end, int C, int *offsets, int lsb_depth, const opus_int16 *logN,
|
int nbEBands, int start, int end, int C, int *offsets, int lsb_depth, const opus_int16 *logN,
|
||||||
int isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM,
|
int isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM,
|
||||||
int effectiveBytes, opus_int32 *tot_boost_)
|
int effectiveBytes, opus_int32 *tot_boost_)
|
||||||
|
@ -894,13 +894,13 @@ static int dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 *bandL
|
||||||
width = C*(eBands[i+1]-eBands[i])<<LM;
|
width = C*(eBands[i+1]-eBands[i])<<LM;
|
||||||
if (width<6)
|
if (width<6)
|
||||||
{
|
{
|
||||||
boost = SHR32(EXTEND32(follower[i]),DB_SHIFT);
|
boost = (int)SHR32(EXTEND32(follower[i]),DB_SHIFT);
|
||||||
boost_bits = boost*width<<BITRES;
|
boost_bits = boost*width<<BITRES;
|
||||||
} else if (width > 48) {
|
} else if (width > 48) {
|
||||||
boost = SHR32(EXTEND32(follower[i])*8,DB_SHIFT);
|
boost = (int)SHR32(EXTEND32(follower[i])*8,DB_SHIFT);
|
||||||
boost_bits = (boost*width<<BITRES)/8;
|
boost_bits = (boost*width<<BITRES)/8;
|
||||||
} else {
|
} else {
|
||||||
boost = SHR32(EXTEND32(follower[i])*width/6,DB_SHIFT);
|
boost = (int)SHR32(EXTEND32(follower[i])*width/6,DB_SHIFT);
|
||||||
boost_bits = boost*6<<BITRES;
|
boost_bits = boost*6<<BITRES;
|
||||||
}
|
}
|
||||||
/* For CBR and non-transient CVBR frames, limit dynalloc to 1/4 of the bits */
|
/* For CBR and non-transient CVBR frames, limit dynalloc to 1/4 of the bits */
|
||||||
|
@ -1501,7 +1501,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
|
||||||
/* effectiveRate in kb/s */
|
/* effectiveRate in kb/s */
|
||||||
effectiveRate = 2*effectiveRate/5;
|
effectiveRate = 2*effectiveRate/5;
|
||||||
|
|
||||||
st->intensity = hysteresis_decision(effectiveRate, intensity_thresholds, intensity_histeresis, 21, st->intensity);
|
st->intensity = hysteresis_decision((opus_val16)effectiveRate, intensity_thresholds, intensity_histeresis, 21, st->intensity);
|
||||||
st->intensity = IMIN(st->end,IMAX(st->start, st->intensity));
|
st->intensity = IMIN(st->end,IMAX(st->start, st->intensity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1542,7 +1542,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
|
||||||
/*printf("%f %f %f %f %d %d ", st->analysis.activity, st->analysis.tonality, tf_estimate, st->stereo_saving, tot_boost, coded_bands);*/
|
/*printf("%f %f %f %f %d %d ", st->analysis.activity, st->analysis.tonality, tf_estimate, st->stereo_saving, tot_boost, coded_bands);*/
|
||||||
#ifndef FIXED_POINT
|
#ifndef FIXED_POINT
|
||||||
if (st->analysis.valid && st->analysis.activity<.4)
|
if (st->analysis.valid && st->analysis.activity<.4)
|
||||||
target -= (coded_bins<<BITRES)*1*(.4-st->analysis.activity);
|
target -= (opus_int32)((coded_bins<<BITRES)*(.4f-st->analysis.activity));
|
||||||
#endif
|
#endif
|
||||||
/* Stereo savings */
|
/* Stereo savings */
|
||||||
if (C==2)
|
if (C==2)
|
||||||
|
@ -1555,25 +1555,25 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
|
||||||
/* Maximum fraction of the bits we can save if the signal is mono. */
|
/* Maximum fraction of the bits we can save if the signal is mono. */
|
||||||
max_frac = DIV32_16(MULT16_16(QCONST16(0.8f, 15), coded_stereo_dof), coded_bins);
|
max_frac = DIV32_16(MULT16_16(QCONST16(0.8f, 15), coded_stereo_dof), coded_bins);
|
||||||
/*printf("%d %d %d ", coded_stereo_dof, coded_bins, tot_boost);*/
|
/*printf("%d %d %d ", coded_stereo_dof, coded_bins, tot_boost);*/
|
||||||
target -= MIN32(MULT16_32_Q15(max_frac,target),
|
target -= (opus_int32)MIN32(MULT16_32_Q15(max_frac,target),
|
||||||
SHR16(MULT16_16(st->stereo_saving-QCONST16(0.1f,8),(coded_stereo_dof<<BITRES)),8));
|
SHR16(MULT16_16(st->stereo_saving-QCONST16(0.1f,8),(coded_stereo_dof<<BITRES)),8));
|
||||||
}
|
}
|
||||||
/* Boost the rate according to dynalloc (minus the dynalloc average for calibration). */
|
/* Boost the rate according to dynalloc (minus the dynalloc average for calibration). */
|
||||||
target += tot_boost-(16<<LM);
|
target += tot_boost-(16<<LM);
|
||||||
/* Apply transient boost, compensating for average boost. */
|
/* Apply transient boost, compensating for average boost. */
|
||||||
target += SHL32(MULT16_32_Q15(tf_estimate-QCONST16(0.04f,14), target),1);
|
target += (opus_int32)SHL32(MULT16_32_Q15(tf_estimate-QCONST16(0.04f,14), target),1);
|
||||||
|
|
||||||
#ifndef FIXED_POINT
|
#ifndef FIXED_POINT
|
||||||
/* Apply tonality boost */
|
/* Apply tonality boost */
|
||||||
if (st->analysis.valid) {
|
if (st->analysis.valid) {
|
||||||
int tonal_target;
|
opus_int32 tonal_target;
|
||||||
float tonal;
|
float tonal;
|
||||||
|
|
||||||
/* Tonality boost (compensating for the average). */
|
/* Tonality boost (compensating for the average). */
|
||||||
tonal = MAX16(0,st->analysis.tonality-.15)-0.09;
|
tonal = MAX16(0.f,st->analysis.tonality-.15f)-0.09f;
|
||||||
tonal_target = target + (coded_bins<<BITRES)*1.2f*tonal;
|
tonal_target = target + (opus_int32)((coded_bins<<BITRES)*1.2f*tonal);
|
||||||
if (pitch_change)
|
if (pitch_change)
|
||||||
tonal_target += (coded_bins<<BITRES)*.8;
|
tonal_target += (opus_int32)((coded_bins<<BITRES)*.8f);
|
||||||
/*printf("%f %f ", st->analysis.tonality, tonal);*/
|
/*printf("%f %f ", st->analysis.tonality, tonal);*/
|
||||||
target = tonal_target;
|
target = tonal_target;
|
||||||
}
|
}
|
||||||
|
@ -1584,7 +1584,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
|
||||||
int bins;
|
int bins;
|
||||||
bins = eBands[nbEBands-2]<<LM;
|
bins = eBands[nbEBands-2]<<LM;
|
||||||
/*floor_depth = SHR32(MULT16_16((C*bins<<BITRES),celt_log2(SHL32(MAX16(1,sample_max),13))), DB_SHIFT);*/
|
/*floor_depth = SHR32(MULT16_16((C*bins<<BITRES),celt_log2(SHL32(MAX16(1,sample_max),13))), DB_SHIFT);*/
|
||||||
floor_depth = SHR32(MULT16_16((C*bins<<BITRES),maxDepth), DB_SHIFT);
|
floor_depth = (opus_int32)SHR32(MULT16_16((C*bins<<BITRES),maxDepth), DB_SHIFT);
|
||||||
floor_depth = IMAX(floor_depth, target>>2);
|
floor_depth = IMAX(floor_depth, target>>2);
|
||||||
target = IMIN(target, floor_depth);
|
target = IMIN(target, floor_depth);
|
||||||
/*printf("%f %d\n", maxDepth, floor_depth);*/
|
/*printf("%f %d\n", maxDepth, floor_depth);*/
|
||||||
|
@ -1600,7 +1600,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
|
||||||
#endif
|
#endif
|
||||||
if (st->constrained_vbr)
|
if (st->constrained_vbr)
|
||||||
rate_factor = MIN16(rate_factor, QCONST16(0.67f, 15));
|
rate_factor = MIN16(rate_factor, QCONST16(0.67f, 15));
|
||||||
target = base_target + MULT16_32_Q15(rate_factor, target-base_target);
|
target = base_target + (opus_int32)MULT16_32_Q15(rate_factor, target-base_target);
|
||||||
|
|
||||||
}
|
}
|
||||||
/* Don't allow more than doubling the rate */
|
/* Don't allow more than doubling the rate */
|
||||||
|
|
116
src/analysis.c
116
src/analysis.c
|
@ -45,22 +45,22 @@ extern const MLP net;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const float dct_table[128] = {
|
static const float dct_table[128] = {
|
||||||
0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000,
|
0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f,
|
||||||
0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000,
|
0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f,
|
||||||
0.351851, 0.338330, 0.311806, 0.273300, 0.224292, 0.166664, 0.102631, 0.034654,
|
0.351851f, 0.338330f, 0.311806f, 0.273300f, 0.224292f, 0.166664f, 0.102631f, 0.034654f,
|
||||||
-0.034654, -0.102631, -0.166664, -0.224292, -0.273300, -0.311806, -0.338330, -0.351851,
|
-0.034654f,-0.102631f,-0.166664f,-0.224292f,-0.273300f,-0.311806f,-0.338330f,-0.351851f,
|
||||||
0.346760, 0.293969, 0.196424, 0.068975, -0.068975, -0.196424, -0.293969, -0.346760,
|
0.346760f, 0.293969f, 0.196424f, 0.068975f,-0.068975f,-0.196424f,-0.293969f,-0.346760f,
|
||||||
-0.346760, -0.293969, -0.196424, -0.068975, 0.068975, 0.196424, 0.293969, 0.346760,
|
-0.346760f,-0.293969f,-0.196424f,-0.068975f, 0.068975f, 0.196424f, 0.293969f, 0.346760f,
|
||||||
0.338330, 0.224292, 0.034654, -0.166664, -0.311806, -0.351851, -0.273300, -0.102631,
|
0.338330f, 0.224292f, 0.034654f,-0.166664f,-0.311806f,-0.351851f,-0.273300f,-0.102631f,
|
||||||
0.102631, 0.273300, 0.351851, 0.311806, 0.166664, -0.034654, -0.224292, -0.338330,
|
0.102631f, 0.273300f, 0.351851f, 0.311806f, 0.166664f,-0.034654f,-0.224292f,-0.338330f,
|
||||||
0.326641, 0.135299, -0.135299, -0.326641, -0.326641, -0.135299, 0.135299, 0.326641,
|
0.326641f, 0.135299f,-0.135299f,-0.326641f,-0.326641f,-0.135299f, 0.135299f, 0.326641f,
|
||||||
0.326641, 0.135299, -0.135299, -0.326641, -0.326641, -0.135299, 0.135299, 0.326641,
|
0.326641f, 0.135299f,-0.135299f,-0.326641f,-0.326641f,-0.135299f, 0.135299f, 0.326641f,
|
||||||
0.311806, 0.034654, -0.273300, -0.338330, -0.102631, 0.224292, 0.351851, 0.166664,
|
0.311806f, 0.034654f,-0.273300f,-0.338330f,-0.102631f, 0.224292f, 0.351851f, 0.166664f,
|
||||||
-0.166664, -0.351851, -0.224292, 0.102631, 0.338330, 0.273300, -0.034654, -0.311806,
|
-0.166664f,-0.351851f,-0.224292f, 0.102631f, 0.338330f, 0.273300f,-0.034654f,-0.311806f,
|
||||||
0.293969, -0.068975, -0.346760, -0.196424, 0.196424, 0.346760, 0.068975, -0.293969,
|
0.293969f,-0.068975f,-0.346760f,-0.196424f, 0.196424f, 0.346760f, 0.068975f,-0.293969f,
|
||||||
-0.293969, 0.068975, 0.346760, 0.196424, -0.196424, -0.346760, -0.068975, 0.293969,
|
-0.293969f, 0.068975f, 0.346760f, 0.196424f,-0.196424f,-0.346760f,-0.068975f, 0.293969f,
|
||||||
0.273300, -0.166664, -0.338330, 0.034654, 0.351851, 0.102631, -0.311806, -0.224292,
|
0.273300f,-0.166664f,-0.338330f, 0.034654f, 0.351851f, 0.102631f,-0.311806f,-0.224292f,
|
||||||
0.224292, 0.311806, -0.102631, -0.351851, -0.034654, 0.338330, 0.166664, -0.273300,
|
0.224292f, 0.311806f,-0.102631f,-0.351851f,-0.034654f, 0.338330f, 0.166664f,-0.273300f,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const float analysis_window[240] = {
|
static const float analysis_window[240] = {
|
||||||
|
@ -113,14 +113,14 @@ static const int extra_bands[NB_TOT_BANDS+1] = {
|
||||||
#define cA 0.43157974f
|
#define cA 0.43157974f
|
||||||
#define cB 0.67848403f
|
#define cB 0.67848403f
|
||||||
#define cC 0.08595542f
|
#define cC 0.08595542f
|
||||||
#define cE (M_PI/2)
|
#define cE ((float)M_PI/2)
|
||||||
static inline float fast_atan2f(float y, float x) {
|
static inline float fast_atan2f(float y, float x) {
|
||||||
float x2, y2;
|
float x2, y2;
|
||||||
/* Should avoid underflow on the values we'll get */
|
/* Should avoid underflow on the values we'll get */
|
||||||
if (ABS16(x)+ABS16(y)<1e-9)
|
if (ABS16(x)+ABS16(y)<1e-9f)
|
||||||
{
|
{
|
||||||
x*=1e12;
|
x*=1e12f;
|
||||||
y*=1e12;
|
y*=1e12f;
|
||||||
}
|
}
|
||||||
x2 = x*x;
|
x2 = x*x;
|
||||||
y2 = y*y;
|
y2 = y*y;
|
||||||
|
@ -159,7 +159,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
float max_frame_tonality;
|
float max_frame_tonality;
|
||||||
/*float tw_sum=0;*/
|
/*float tw_sum=0;*/
|
||||||
float frame_noisiness;
|
float frame_noisiness;
|
||||||
const float pi4 = M_PI*M_PI*M_PI*M_PI;
|
const float pi4 = (float)(M_PI*M_PI*M_PI*M_PI);
|
||||||
float slope=0;
|
float slope=0;
|
||||||
float frame_stationarity;
|
float frame_stationarity;
|
||||||
float relativeE;
|
float relativeE;
|
||||||
|
@ -213,26 +213,26 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
X2r = out[i].i+out[N-i].i;
|
X2r = out[i].i+out[N-i].i;
|
||||||
X2i = out[N-i].r-out[i].r;
|
X2i = out[N-i].r-out[i].r;
|
||||||
|
|
||||||
angle = (.5/M_PI)*fast_atan2f(X1i, X1r);
|
angle = (float)(.5f/M_PI)*fast_atan2f(X1i, X1r);
|
||||||
d_angle = angle - A[i];
|
d_angle = angle - A[i];
|
||||||
d2_angle = d_angle - dA[i];
|
d2_angle = d_angle - dA[i];
|
||||||
|
|
||||||
angle2 = (.5/M_PI)*fast_atan2f(X2i, X2r);
|
angle2 = (float)(.5f/M_PI)*fast_atan2f(X2i, X2r);
|
||||||
d_angle2 = angle2 - angle;
|
d_angle2 = angle2 - angle;
|
||||||
d2_angle2 = d_angle2 - d_angle;
|
d2_angle2 = d_angle2 - d_angle;
|
||||||
|
|
||||||
mod1 = d2_angle - floor(.5+d2_angle);
|
mod1 = d2_angle - (float)floor(.5+d2_angle);
|
||||||
noisiness[i] = fabs(mod1);
|
noisiness[i] = ABS16(mod1);
|
||||||
mod1 *= mod1;
|
mod1 *= mod1;
|
||||||
mod1 *= mod1;
|
mod1 *= mod1;
|
||||||
|
|
||||||
mod2 = d2_angle2 - floor(.5+d2_angle2);
|
mod2 = d2_angle2 - (float)floor(.5+d2_angle2);
|
||||||
noisiness[i] += fabs(mod2);
|
noisiness[i] += ABS16(mod2);
|
||||||
mod2 *= mod2;
|
mod2 *= mod2;
|
||||||
mod2 *= mod2;
|
mod2 *= mod2;
|
||||||
|
|
||||||
avg_mod = .25*(d2A[i]+2*mod1+mod2);
|
avg_mod = .25f*(d2A[i]+2.f*mod1+mod2);
|
||||||
tonality[i] = 1./(1+40*16*pi4*avg_mod)-.015;
|
tonality[i] = 1.f/(1.f+40.f*16.f*pi4*avg_mod)-.015f;
|
||||||
|
|
||||||
A[i] = angle2;
|
A[i] = angle2;
|
||||||
dA[i] = d_angle2;
|
dA[i] = d_angle2;
|
||||||
|
@ -267,30 +267,30 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
+ out[i].i*out[i].i + out[N-i].i*out[N-i].i;
|
+ out[i].i*out[i].i + out[N-i].i*out[N-i].i;
|
||||||
E += binE;
|
E += binE;
|
||||||
tE += binE*tonality[i];
|
tE += binE*tonality[i];
|
||||||
nE += binE*2*(.5-noisiness[i]);
|
nE += binE*2.f*(.5f-noisiness[i]);
|
||||||
}
|
}
|
||||||
tonal->E[tonal->E_count][b] = E;
|
tonal->E[tonal->E_count][b] = E;
|
||||||
frame_noisiness += nE/(1e-15+E);
|
frame_noisiness += nE/(1e-15f+E);
|
||||||
|
|
||||||
frame_loudness += sqrt(E+1e-10);
|
frame_loudness += celt_sqrt(E+1e-10f);
|
||||||
logE[b] = log(E+1e-10);
|
logE[b] = (float)log(E+1e-10f);
|
||||||
tonal->lowE[b] = MIN32(logE[b], tonal->lowE[b]+.01);
|
tonal->lowE[b] = MIN32(logE[b], tonal->lowE[b]+.01f);
|
||||||
tonal->highE[b] = MAX32(logE[b], tonal->highE[b]-.1);
|
tonal->highE[b] = MAX32(logE[b], tonal->highE[b]-.1f);
|
||||||
if (tonal->highE[b] < tonal->lowE[b]+1)
|
if (tonal->highE[b] < tonal->lowE[b]+1.f)
|
||||||
{
|
{
|
||||||
tonal->highE[b]+=.5;
|
tonal->highE[b]+=.5f;
|
||||||
tonal->lowE[b]-=.5;
|
tonal->lowE[b]-=.5f;
|
||||||
}
|
}
|
||||||
relativeE += (logE[b]-tonal->lowE[b])/(EPSILON+tonal->highE[b]-tonal->lowE[b]);
|
relativeE += (logE[b]-tonal->lowE[b])/(EPSILON+tonal->highE[b]-tonal->lowE[b]);
|
||||||
|
|
||||||
L1=L2=0;
|
L1=L2=0;
|
||||||
for (i=0;i<NB_FRAMES;i++)
|
for (i=0;i<NB_FRAMES;i++)
|
||||||
{
|
{
|
||||||
L1 += sqrt(tonal->E[i][b]);
|
L1 += celt_sqrt(tonal->E[i][b]);
|
||||||
L2 += tonal->E[i][b];
|
L2 += tonal->E[i][b];
|
||||||
}
|
}
|
||||||
|
|
||||||
stationarity = MIN16(0.99,L1/sqrt(EPSILON+NB_FRAMES*L2));
|
stationarity = MIN16(0.99f,L1/celt_sqrt(EPSILON+NB_FRAMES*L2));
|
||||||
stationarity *= stationarity;
|
stationarity *= stationarity;
|
||||||
stationarity *= stationarity;
|
stationarity *= stationarity;
|
||||||
frame_stationarity += stationarity;
|
frame_stationarity += stationarity;
|
||||||
|
@ -307,7 +307,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
if (b>=NB_TBANDS-NB_TONAL_SKIP_BANDS)
|
if (b>=NB_TBANDS-NB_TONAL_SKIP_BANDS)
|
||||||
frame_tonality -= band_tonality[b-NB_TBANDS+NB_TONAL_SKIP_BANDS];
|
frame_tonality -= band_tonality[b-NB_TBANDS+NB_TONAL_SKIP_BANDS];
|
||||||
#endif
|
#endif
|
||||||
max_frame_tonality = MAX16(max_frame_tonality, (1+.03*(b-NB_TBANDS))*frame_tonality);
|
max_frame_tonality = MAX16(max_frame_tonality, (1.f+.03f*(b-NB_TBANDS))*frame_tonality);
|
||||||
slope += band_tonality[b]*(b-8);
|
slope += band_tonality[b]*(b-8);
|
||||||
/*printf("%f %f ", band_tonality[b], stationarity);*/
|
/*printf("%f %f ", band_tonality[b], stationarity);*/
|
||||||
tonal->prev_band_tonality[b] = band_tonality[b];
|
tonal->prev_band_tonality[b] = band_tonality[b];
|
||||||
|
@ -342,15 +342,15 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
}
|
}
|
||||||
E = MAX32(E, tonal->meanE[b]);
|
E = MAX32(E, tonal->meanE[b]);
|
||||||
/* 13 dB slope for spreading function */
|
/* 13 dB slope for spreading function */
|
||||||
bandwidth_mask = MAX32(.05*bandwidth_mask, E);
|
bandwidth_mask = MAX32(.05f*bandwidth_mask, E);
|
||||||
/* Checks if band looks like stationary noise or if it's below a (trivial) masking curve */
|
/* Checks if band looks like stationary noise or if it's below a (trivial) masking curve */
|
||||||
if (E>.1*bandwidth_mask && E*1e10f > maxE && E > noise_floor)
|
if (E>.1*bandwidth_mask && E*1e10f > maxE && E > noise_floor)
|
||||||
bandwidth = b;
|
bandwidth = b;
|
||||||
}
|
}
|
||||||
if (tonal->count<=2)
|
if (tonal->count<=2)
|
||||||
bandwidth = 20;
|
bandwidth = 20;
|
||||||
frame_loudness = 20*log10(frame_loudness);
|
frame_loudness = 20*(float)log10(frame_loudness);
|
||||||
tonal->Etracker = MAX32(tonal->Etracker-.03, frame_loudness);
|
tonal->Etracker = MAX32(tonal->Etracker-.03f, frame_loudness);
|
||||||
tonal->lowECount *= (1-alphaE);
|
tonal->lowECount *= (1-alphaE);
|
||||||
if (frame_loudness < tonal->Etracker-30)
|
if (frame_loudness < tonal->Etracker-30)
|
||||||
tonal->lowECount += alphaE;
|
tonal->lowECount += alphaE;
|
||||||
|
@ -374,7 +374,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
info->activity = .5*(1+frame_noisiness-frame_stationarity);
|
info->activity = .5*(1+frame_noisiness-frame_stationarity);
|
||||||
#endif
|
#endif
|
||||||
frame_tonality = (max_frame_tonality/(NB_TBANDS-NB_TONAL_SKIP_BANDS));
|
frame_tonality = (max_frame_tonality/(NB_TBANDS-NB_TONAL_SKIP_BANDS));
|
||||||
frame_tonality = MAX16(frame_tonality, tonal->prev_tonality*.8);
|
frame_tonality = MAX16(frame_tonality, tonal->prev_tonality*.8f);
|
||||||
tonal->prev_tonality = frame_tonality;
|
tonal->prev_tonality = frame_tonality;
|
||||||
|
|
||||||
slope /= 8*8;
|
slope /= 8*8;
|
||||||
|
@ -385,15 +385,15 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
info->tonality = frame_tonality;
|
info->tonality = frame_tonality;
|
||||||
|
|
||||||
for (i=0;i<4;i++)
|
for (i=0;i<4;i++)
|
||||||
features[i] = -0.12299*(BFCC[i]+tonal->mem[i+24]) + 0.49195*(tonal->mem[i]+tonal->mem[i+16]) + 0.69693*tonal->mem[i+8] - 1.4349*tonal->cmean[i];
|
features[i] = -0.12299f*(BFCC[i]+tonal->mem[i+24]) + 0.49195f*(tonal->mem[i]+tonal->mem[i+16]) + 0.69693f*tonal->mem[i+8] - 1.4349f*tonal->cmean[i];
|
||||||
|
|
||||||
for (i=0;i<4;i++)
|
for (i=0;i<4;i++)
|
||||||
tonal->cmean[i] = (1-alpha)*tonal->cmean[i] + alpha*BFCC[i];
|
tonal->cmean[i] = (1-alpha)*tonal->cmean[i] + alpha*BFCC[i];
|
||||||
|
|
||||||
for (i=0;i<4;i++)
|
for (i=0;i<4;i++)
|
||||||
features[4+i] = 0.63246*(BFCC[i]-tonal->mem[i+24]) + 0.31623*(tonal->mem[i]-tonal->mem[i+16]);
|
features[4+i] = 0.63246f*(BFCC[i]-tonal->mem[i+24]) + 0.31623f*(tonal->mem[i]-tonal->mem[i+16]);
|
||||||
for (i=0;i<3;i++)
|
for (i=0;i<3;i++)
|
||||||
features[8+i] = 0.53452*(BFCC[i]+tonal->mem[i+24]) - 0.26726*(tonal->mem[i]+tonal->mem[i+16]) -0.53452*tonal->mem[i+8];
|
features[8+i] = 0.53452f*(BFCC[i]+tonal->mem[i+24]) - 0.26726f*(tonal->mem[i]+tonal->mem[i+16]) -0.53452f*tonal->mem[i+8];
|
||||||
|
|
||||||
if (tonal->count > 5)
|
if (tonal->count > 5)
|
||||||
{
|
{
|
||||||
|
@ -409,7 +409,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
tonal->mem[i] = BFCC[i];
|
tonal->mem[i] = BFCC[i];
|
||||||
}
|
}
|
||||||
for (i=0;i<9;i++)
|
for (i=0;i<9;i++)
|
||||||
features[11+i] = sqrt(tonal->std[i]);
|
features[11+i] = celt_sqrt(tonal->std[i]);
|
||||||
features[20] = info->tonality;
|
features[20] = info->tonality;
|
||||||
features[21] = info->activity;
|
features[21] = info->activity;
|
||||||
features[22] = frame_stationarity;
|
features[22] = frame_stationarity;
|
||||||
|
@ -418,9 +418,9 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
|
|
||||||
#ifndef FIXED_POINT
|
#ifndef FIXED_POINT
|
||||||
mlp_process(&net, features, &frame_prob);
|
mlp_process(&net, features, &frame_prob);
|
||||||
frame_prob = .5*(frame_prob+1);
|
frame_prob = .5f*(frame_prob+1);
|
||||||
/* Curve fitting between the MLP probability and the actual probability */
|
/* Curve fitting between the MLP probability and the actual probability */
|
||||||
frame_prob = .01 + 1.21*frame_prob*frame_prob - .23*pow(frame_prob, 10);
|
frame_prob = .01f + 1.21f*frame_prob*frame_prob - .23f*(float)pow(frame_prob, 10);
|
||||||
|
|
||||||
/*printf("%f\n", frame_prob);*/
|
/*printf("%f\n", frame_prob);*/
|
||||||
{
|
{
|
||||||
|
@ -428,20 +428,20 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc
|
||||||
float p0, p1;
|
float p0, p1;
|
||||||
float max_certainty;
|
float max_certainty;
|
||||||
/* One transition every 3 minutes */
|
/* One transition every 3 minutes */
|
||||||
tau = .00005;
|
tau = .00005f;
|
||||||
beta = .1;
|
beta = .1f;
|
||||||
max_certainty = .01+1.f/(20+.5*tonal->last_transition);
|
max_certainty = .01f+1.f/(20.f+.5f*tonal->last_transition);
|
||||||
p0 = (1-tonal->music_prob)*(1-tau) + tonal->music_prob *tau;
|
p0 = (1-tonal->music_prob)*(1-tau) + tonal->music_prob *tau;
|
||||||
p1 = tonal->music_prob *(1-tau) + (1-tonal->music_prob)*tau;
|
p1 = tonal->music_prob *(1-tau) + (1-tonal->music_prob)*tau;
|
||||||
p0 *= pow(1-frame_prob, beta);
|
p0 *= (float)pow(1-frame_prob, beta);
|
||||||
p1 *= pow(frame_prob, beta);
|
p1 *= (float)pow(frame_prob, beta);
|
||||||
tonal->music_prob = MAX16(max_certainty, MIN16(1-max_certainty, p1/(p0+p1)));
|
tonal->music_prob = MAX16(max_certainty, MIN16(1-max_certainty, p1/(p0+p1)));
|
||||||
info->music_prob = tonal->music_prob;
|
info->music_prob = tonal->music_prob;
|
||||||
/*printf("%f %f\n", frame_prob, info->music_prob);*/
|
/*printf("%f %f\n", frame_prob, info->music_prob);*/
|
||||||
}
|
}
|
||||||
if (tonal->last_music != (tonal->music_prob>.5))
|
if (tonal->last_music != (tonal->music_prob>.5f))
|
||||||
tonal->last_transition=0;
|
tonal->last_transition=0;
|
||||||
tonal->last_music = tonal->music_prob>.5;
|
tonal->last_music = tonal->music_prob>.5f;
|
||||||
#else
|
#else
|
||||||
info->music_prob = 0;
|
info->music_prob = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
11
src/mlp.c
11
src/mlp.c
|
@ -36,7 +36,6 @@
|
||||||
#define MAX_NEURONS 100
|
#define MAX_NEURONS 100
|
||||||
|
|
||||||
#ifdef FIXED_POINT
|
#ifdef FIXED_POINT
|
||||||
extern const opus_val16 tansig_table[501];
|
|
||||||
static inline opus_val16 tansig_approx(opus_val32 _x) /* Q19 */
|
static inline opus_val16 tansig_approx(opus_val32 _x) /* Q19 */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -63,11 +62,11 @@ static inline opus_val16 tansig_approx(opus_val32 _x) /* Q19 */
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/*extern const float tansig_table[501];*/
|
/*extern const float tansig_table[501];*/
|
||||||
static inline double tansig_approx(double x)
|
static inline opus_val16 tansig_approx(opus_val16 x)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double y, dy;
|
opus_val16 y, dy;
|
||||||
double sign=1;
|
opus_val16 sign=1;
|
||||||
if (x>=8)
|
if (x>=8)
|
||||||
return 1;
|
return 1;
|
||||||
if (x<=-8)
|
if (x<=-8)
|
||||||
|
@ -77,8 +76,8 @@ static inline double tansig_approx(double x)
|
||||||
x=-x;
|
x=-x;
|
||||||
sign=-1;
|
sign=-1;
|
||||||
}
|
}
|
||||||
i = floor(.5+25*x);
|
i = (int)floor(.5f+25*x);
|
||||||
x -= .04*i;
|
x -= .04f*i;
|
||||||
y = tansig_table[i];
|
y = tansig_table[i];
|
||||||
dy = 1-y*y;
|
dy = 1-y*y;
|
||||||
y = y + x*dy*(1 - y*x);
|
y = y + x*dy*(1 - y*x);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue