From d683c76b882224cb331268438c001ac46fe8e3ab Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Fri, 21 Dec 2012 16:17:38 -0500 Subject: Fixes MSVC warnings for double->float and float->int conversion --- celt/celt_encoder.c | 40 +++++++++--------- src/analysis.c | 116 ++++++++++++++++++++++++++-------------------------- src/mlp.c | 11 +++-- 3 files changed, 83 insertions(+), 84 deletions(-) diff --git a/celt/celt_encoder.c b/celt/celt_encoder.c index 2226b23d..30b6d9e5 100644 --- a/celt/celt_encoder.c +++ b/celt/celt_encoder.c @@ -215,7 +215,7 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int int is_transient = 0; opus_int32 mask_metric = 0; int c; - int tf_max; + opus_val16 tf_max; int len2; /* Table of 6*64/x, trained on real data to minimize the average error */ 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 */ mean = MULT16_16(celt_sqrt(mean), celt_sqrt(MULT16_16(maxE,len2>>1))); #else - mean = sqrt(mean * maxE*.5*len2); + mean = celt_sqrt(mean * maxE*.5*len2); #endif /* Inverse of the mean energy in Q15+6 */ 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 id = IMAX(0,IMIN(127,MULT16_32_Q15(tmp[i],norm))); /* Do not round to nearest */ #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 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 */ tf_max = MAX16(0,celt_sqrt(27*mask_metric)-42); /* *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);*/ RESTORE_STACK; #ifdef FUZZING @@ -755,14 +755,14 @@ static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X, #ifndef FIXED_POINT 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 #ifdef FIXED_POINT trim_index = PSHR32(trim, 8); #else - trim_index = floor(.5+trim); + trim_index = (int)floor(.5f+trim); #endif if (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); } -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 isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM, 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])< 48) { - boost = SHR32(EXTEND32(follower[i])*8,DB_SHIFT); + boost = (int)SHR32(EXTEND32(follower[i])*8,DB_SHIFT); boost_bits = (boost*width<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)); } @@ -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);*/ #ifndef FIXED_POINT if (st->analysis.valid && st->analysis.activity<.4) - target -= (coded_bins<analysis.activity); + target -= (opus_int32)((coded_bins<analysis.activity)); #endif /* Stereo savings */ 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. */ 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);*/ - 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<analysis.valid) { - int tonal_target; + opus_int32 tonal_target; float tonal; /* Tonality boost (compensating for the average). */ - tonal = MAX16(0,st->analysis.tonality-.15)-0.09; - tonal_target = target + (coded_bins<analysis.tonality-.15f)-0.09f; + tonal_target = target + (opus_int32)((coded_bins<analysis.tonality, tonal);*/ target = tonal_target; } @@ -1584,7 +1584,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, int bins; bins = eBands[nbEBands-2]<>2); target = IMIN(target, 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 if (st->constrained_vbr) 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 */ diff --git a/src/analysis.c b/src/analysis.c index 80b56815..22a8fa79 100644 --- a/src/analysis.c +++ b/src/analysis.c @@ -45,22 +45,22 @@ extern const MLP net; #endif static const float dct_table[128] = { - 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, - 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, - 0.351851, 0.338330, 0.311806, 0.273300, 0.224292, 0.166664, 0.102631, 0.034654, - -0.034654, -0.102631, -0.166664, -0.224292, -0.273300, -0.311806, -0.338330, -0.351851, - 0.346760, 0.293969, 0.196424, 0.068975, -0.068975, -0.196424, -0.293969, -0.346760, - -0.346760, -0.293969, -0.196424, -0.068975, 0.068975, 0.196424, 0.293969, 0.346760, - 0.338330, 0.224292, 0.034654, -0.166664, -0.311806, -0.351851, -0.273300, -0.102631, - 0.102631, 0.273300, 0.351851, 0.311806, 0.166664, -0.034654, -0.224292, -0.338330, - 0.326641, 0.135299, -0.135299, -0.326641, -0.326641, -0.135299, 0.135299, 0.326641, - 0.326641, 0.135299, -0.135299, -0.326641, -0.326641, -0.135299, 0.135299, 0.326641, - 0.311806, 0.034654, -0.273300, -0.338330, -0.102631, 0.224292, 0.351851, 0.166664, - -0.166664, -0.351851, -0.224292, 0.102631, 0.338330, 0.273300, -0.034654, -0.311806, - 0.293969, -0.068975, -0.346760, -0.196424, 0.196424, 0.346760, 0.068975, -0.293969, - -0.293969, 0.068975, 0.346760, 0.196424, -0.196424, -0.346760, -0.068975, 0.293969, - 0.273300, -0.166664, -0.338330, 0.034654, 0.351851, 0.102631, -0.311806, -0.224292, - 0.224292, 0.311806, -0.102631, -0.351851, -0.034654, 0.338330, 0.166664, -0.273300, + 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, + 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, + 0.351851f, 0.338330f, 0.311806f, 0.273300f, 0.224292f, 0.166664f, 0.102631f, 0.034654f, + -0.034654f,-0.102631f,-0.166664f,-0.224292f,-0.273300f,-0.311806f,-0.338330f,-0.351851f, + 0.346760f, 0.293969f, 0.196424f, 0.068975f,-0.068975f,-0.196424f,-0.293969f,-0.346760f, + -0.346760f,-0.293969f,-0.196424f,-0.068975f, 0.068975f, 0.196424f, 0.293969f, 0.346760f, + 0.338330f, 0.224292f, 0.034654f,-0.166664f,-0.311806f,-0.351851f,-0.273300f,-0.102631f, + 0.102631f, 0.273300f, 0.351851f, 0.311806f, 0.166664f,-0.034654f,-0.224292f,-0.338330f, + 0.326641f, 0.135299f,-0.135299f,-0.326641f,-0.326641f,-0.135299f, 0.135299f, 0.326641f, + 0.326641f, 0.135299f,-0.135299f,-0.326641f,-0.326641f,-0.135299f, 0.135299f, 0.326641f, + 0.311806f, 0.034654f,-0.273300f,-0.338330f,-0.102631f, 0.224292f, 0.351851f, 0.166664f, + -0.166664f,-0.351851f,-0.224292f, 0.102631f, 0.338330f, 0.273300f,-0.034654f,-0.311806f, + 0.293969f,-0.068975f,-0.346760f,-0.196424f, 0.196424f, 0.346760f, 0.068975f,-0.293969f, + -0.293969f, 0.068975f, 0.346760f, 0.196424f,-0.196424f,-0.346760f,-0.068975f, 0.293969f, + 0.273300f,-0.166664f,-0.338330f, 0.034654f, 0.351851f, 0.102631f,-0.311806f,-0.224292f, + 0.224292f, 0.311806f,-0.102631f,-0.351851f,-0.034654f, 0.338330f, 0.166664f,-0.273300f, }; static const float analysis_window[240] = { @@ -113,14 +113,14 @@ static const int extra_bands[NB_TOT_BANDS+1] = { #define cA 0.43157974f #define cB 0.67848403f #define cC 0.08595542f -#define cE (M_PI/2) +#define cE ((float)M_PI/2) static inline float fast_atan2f(float y, float x) { float x2, y2; /* 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; - y*=1e12; + x*=1e12f; + y*=1e12f; } x2 = x*x; y2 = y*y; @@ -159,7 +159,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc float max_frame_tonality; /*float tw_sum=0;*/ 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 frame_stationarity; float relativeE; @@ -213,26 +213,26 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc X2r = out[i].i+out[N-i].i; 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]; 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; d2_angle2 = d_angle2 - d_angle; - mod1 = d2_angle - floor(.5+d2_angle); - noisiness[i] = fabs(mod1); + mod1 = d2_angle - (float)floor(.5+d2_angle); + noisiness[i] = ABS16(mod1); mod1 *= mod1; mod1 *= mod1; - mod2 = d2_angle2 - floor(.5+d2_angle2); - noisiness[i] += fabs(mod2); + mod2 = d2_angle2 - (float)floor(.5+d2_angle2); + noisiness[i] += ABS16(mod2); mod2 *= mod2; mod2 *= mod2; - avg_mod = .25*(d2A[i]+2*mod1+mod2); - tonality[i] = 1./(1+40*16*pi4*avg_mod)-.015; + avg_mod = .25f*(d2A[i]+2.f*mod1+mod2); + tonality[i] = 1.f/(1.f+40.f*16.f*pi4*avg_mod)-.015f; A[i] = 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; E += binE; tE += binE*tonality[i]; - nE += binE*2*(.5-noisiness[i]); + nE += binE*2.f*(.5f-noisiness[i]); } 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); - logE[b] = log(E+1e-10); - tonal->lowE[b] = MIN32(logE[b], tonal->lowE[b]+.01); - tonal->highE[b] = MAX32(logE[b], tonal->highE[b]-.1); - if (tonal->highE[b] < tonal->lowE[b]+1) + frame_loudness += celt_sqrt(E+1e-10f); + logE[b] = (float)log(E+1e-10f); + tonal->lowE[b] = MIN32(logE[b], tonal->lowE[b]+.01f); + tonal->highE[b] = MAX32(logE[b], tonal->highE[b]-.1f); + if (tonal->highE[b] < tonal->lowE[b]+1.f) { - tonal->highE[b]+=.5; - tonal->lowE[b]-=.5; + tonal->highE[b]+=.5f; + tonal->lowE[b]-=.5f; } relativeE += (logE[b]-tonal->lowE[b])/(EPSILON+tonal->highE[b]-tonal->lowE[b]); L1=L2=0; for (i=0;iE[i][b]); + L1 += celt_sqrt(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; frame_stationarity += stationarity; @@ -307,7 +307,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc if (b>=NB_TBANDS-NB_TONAL_SKIP_BANDS) frame_tonality -= band_tonality[b-NB_TBANDS+NB_TONAL_SKIP_BANDS]; #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); /*printf("%f %f ", band_tonality[b], stationarity);*/ 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]); /* 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 */ if (E>.1*bandwidth_mask && E*1e10f > maxE && E > noise_floor) bandwidth = b; } if (tonal->count<=2) bandwidth = 20; - frame_loudness = 20*log10(frame_loudness); - tonal->Etracker = MAX32(tonal->Etracker-.03, frame_loudness); + frame_loudness = 20*(float)log10(frame_loudness); + tonal->Etracker = MAX32(tonal->Etracker-.03f, frame_loudness); tonal->lowECount *= (1-alphaE); if (frame_loudness < tonal->Etracker-30) tonal->lowECount += alphaE; @@ -374,7 +374,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc info->activity = .5*(1+frame_noisiness-frame_stationarity); #endif 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; slope /= 8*8; @@ -385,15 +385,15 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc info->tonality = frame_tonality; 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++) tonal->cmean[i] = (1-alpha)*tonal->cmean[i] + alpha*BFCC[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++) - 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) { @@ -409,7 +409,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc tonal->mem[i] = BFCC[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[21] = info->activity; features[22] = frame_stationarity; @@ -418,9 +418,9 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc #ifndef FIXED_POINT 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 */ - 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);*/ { @@ -428,20 +428,20 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc float p0, p1; float max_certainty; /* One transition every 3 minutes */ - tau = .00005; - beta = .1; - max_certainty = .01+1.f/(20+.5*tonal->last_transition); + tau = .00005f; + beta = .1f; + max_certainty = .01f+1.f/(20.f+.5f*tonal->last_transition); p0 = (1-tonal->music_prob)*(1-tau) + tonal->music_prob *tau; p1 = tonal->music_prob *(1-tau) + (1-tonal->music_prob)*tau; - p0 *= pow(1-frame_prob, beta); - p1 *= pow(frame_prob, beta); + p0 *= (float)pow(1-frame_prob, beta); + p1 *= (float)pow(frame_prob, beta); tonal->music_prob = MAX16(max_certainty, MIN16(1-max_certainty, p1/(p0+p1))); info->music_prob = tonal->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_music = tonal->music_prob>.5; + tonal->last_music = tonal->music_prob>.5f; #else info->music_prob = 0; #endif diff --git a/src/mlp.c b/src/mlp.c index 32380fd6..90e94a5f 100644 --- a/src/mlp.c +++ b/src/mlp.c @@ -36,7 +36,6 @@ #define MAX_NEURONS 100 #ifdef FIXED_POINT -extern const opus_val16 tansig_table[501]; static inline opus_val16 tansig_approx(opus_val32 _x) /* Q19 */ { int i; @@ -63,11 +62,11 @@ static inline opus_val16 tansig_approx(opus_val32 _x) /* Q19 */ } #else /*extern const float tansig_table[501];*/ -static inline double tansig_approx(double x) +static inline opus_val16 tansig_approx(opus_val16 x) { int i; - double y, dy; - double sign=1; + opus_val16 y, dy; + opus_val16 sign=1; if (x>=8) return 1; if (x<=-8) @@ -77,8 +76,8 @@ static inline double tansig_approx(double x) x=-x; sign=-1; } - i = floor(.5+25*x); - x -= .04*i; + i = (int)floor(.5f+25*x); + x -= .04f*i; y = tansig_table[i]; dy = 1-y*y; y = y + x*dy*(1 - y*x); -- cgit v1.2.3