shithub: opus

Download patch

ref: 43279728cd39947f95dbf77557a0a698f164fdd1
parent: cfe8e2b86d778da6c3d4521ae6f3bd46311399d8
author: Gregory Maxwell <[email protected]>
date: Mon Jul 15 11:23:03 EDT 2013

Fixes a number of double promotions and missing casts.

At a minimum MSVC warns on some of this stuff.

--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -327,7 +327,7 @@
       /* Costs two sqrt() to avoid overflows */
       mean = MULT16_16(celt_sqrt(mean), celt_sqrt(MULT16_16(maxE,len2>>1)));
 #else
-      mean = celt_sqrt(mean * maxE*.5*len2);
+      mean = celt_sqrt(mean * maxE*.5f*len2);
 #endif
       /* Inverse of the mean energy in Q15+6 */
       norm = SHL32(EXTEND32(len2),6+14)/ADD32(EPSILON,SHR32(mean,1));
@@ -1139,7 +1139,7 @@
 
    /*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 (analysis->valid && analysis->activity<.4)
+   if (analysis->valid && analysis->activity<.4f)
       target -= (opus_int32)((coded_bins<<BITRES)*(.4f-analysis->activity));
 #endif
    /* Stereo savings */
@@ -1457,8 +1457,8 @@
 
       prefilter_tapset = st->tapset_decision;
       pf_on = run_prefilter(st, in, prefilter_mem, CC, N, prefilter_tapset, &pitch_index, &gain1, &qg, enabled, nbAvailableBytes);
-      if ((gain1 > QCONST16(.4f,15) || st->prefilter_gain > QCONST16(.4f,15)) && (!st->analysis.valid || st->analysis.tonality > .3)
-            && (pitch_index > 1.26*st->prefilter_period || pitch_index < .79*st->prefilter_period))
+      if ((gain1 > QCONST16(.4f,15) || st->prefilter_gain > QCONST16(.4f,15)) && (!st->analysis.valid || st->analysis.tonality > .3f)
+            && (pitch_index > 1.26f*st->prefilter_period || pitch_index < .79f*st->prefilter_period))
          pitch_change = 1;
       if (pf_on==0)
       {
--- a/celt/tests/test_unit_mathops.c
+++ b/celt/tests/test_unit_mathops.c
@@ -65,11 +65,11 @@
       opus_val32 val;
       val = celt_rcp(i);
 #ifdef FIXED_POINT
-      prod = (1./32768./65526.)*val*i;
+      prod = (1.f/32768.f/65526.f)*val*i;
 #else
       prod = val*i;
 #endif
-      if (fabs(prod-1) > .00025)
+      if (fabs(prod-1) > .00025f)
       {
          fprintf (stderr, "div failed: 1/%d="WORD" (product = %f)\n", i, val, prod);
          ret = 1;
@@ -86,7 +86,7 @@
       opus_val16 val;
       val = celt_sqrt(i);
       ratio = val/sqrt(i);
-      if (fabs(ratio - 1) > .0005 && fabs(val-sqrt(i)) > 2)
+      if (fabs(ratio - 1) > .0005f && fabs(val-sqrt(i)) > 2)
       {
          fprintf (stderr, "sqrt failed: sqrt(%d)="WORD" (ratio = %f)\n", i, val, ratio);
          ret = 1;
@@ -152,10 +152,10 @@
 void testlog2(void)
 {
    float x;
-   for (x=0.001;x<1677700.0;x+=(x/8.0))
+   for (x=0.001f;x<1677700.0f;x+=(x/8.0f))
    {
       float error = fabs((1.442695040888963387*log(x))-celt_log2(x));
-      if (error>0.0009)
+      if (error>0.0009f)
       {
          fprintf (stderr, "celt_log2 failed: fabs((1.442695040888963387*log(x))-celt_log2(x))>0.001 (x = %f, error = %f)\n", x,error);
          ret = 1;
@@ -166,10 +166,10 @@
 void testexp2(void)
 {
    float x;
-   for (x=-11.0;x<24.0;x+=0.0007)
+   for (x=-11.0f;x<24.0f;x+=0.0007f)
    {
       float error = fabs(x-(1.442695040888963387*log(celt_exp2(x))));
-      if (error>0.0002)
+      if (error>0.0002f)
       {
          fprintf (stderr, "celt_exp2 failed: fabs(x-(1.442695040888963387*log(celt_exp2(x))))>0.0005 (x = %f, error = %f)\n", x,error);
          ret = 1;
@@ -180,10 +180,10 @@
 void testexp2log2(void)
 {
    float x;
-   for (x=-11.0;x<24.0;x+=0.0007)
+   for (x=-11.0f;x<24.0f;x+=0.0007f)
    {
       float error = fabs(x-(celt_log2(celt_exp2(x))));
-      if (error>0.001)
+      if (error>0.001f)
       {
          fprintf (stderr, "celt_log2/celt_exp2 failed: fabs(x-(celt_log2(celt_exp2(x))))>0.001 (x = %f, error = %f)\n", x,error);
          ret = 1;
@@ -196,8 +196,8 @@
    opus_val32 x;
    for (x=8;x<1073741824;x+=(x>>3))
    {
-      float error = fabs((1.442695040888963387*log(x/16384.0))-celt_log2(x)/1024.0);
-      if (error>0.003)
+      float error = fabs((1.442695040888963387*log(x/16384.0f))-celt_log2(x)/1024.0f);
+      if (error>0.003f)
       {
          fprintf (stderr, "celt_log2 failed: x = %ld, error = %f\n", (long)x,error);
          ret = 1;
@@ -210,9 +210,9 @@
    opus_val16 x;
    for (x=-32768;x<15360;x++)
    {
-      float error1 = fabs(x/1024.0-(1.442695040888963387*log(celt_exp2(x)/65536.0)));
-      float error2 = fabs(exp(0.6931471805599453094*x/1024.0)-celt_exp2(x)/65536.0);
-      if (error1>0.0002&&error2>0.00004)
+      float error1 = fabs(x/1024.0f-(1.442695040888963387*log(celt_exp2(x)/65536.0f)));
+      float error2 = fabs(exp(0.6931471805599453094f*x/1024.0f)-celt_exp2(x)/65536.0f);
+      if (error1>0.0002f&&error2>0.00004f)
       {
     	 fprintf (stderr, "celt_exp2 failed: x = "WORD", error1 = %f, error2 = %f\n", x,error1,error2);
          ret = 1;
@@ -225,8 +225,8 @@
    opus_val32 x;
    for (x=8;x<65536;x+=(x>>3))
    {
-      float error = fabs(x-0.25*celt_exp2(celt_log2(x)))/16384;
-      if (error>0.004)
+      float error = fabs(x-0.25f*celt_exp2(celt_log2(x)))/16384;
+      if (error>0.004f)
       {
          fprintf (stderr, "celt_log2/celt_exp2 failed: fabs(x-(celt_exp2(celt_log2(x))))>0.001 (x = %ld, error = %f)\n", (long)x,error);
          ret = 1;
--- a/silk/NLSF2A.c
+++ b/silk/NLSF2A.c
@@ -163,7 +163,7 @@
     }
 
     for( i = 0; i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) {
-        if( silk_LPC_inverse_pred_gain( a_Q12, d ) < SILK_FIX_CONST( 1.0 / MAX_PREDICTION_POWER_GAIN, 30 ) ) {
+        if( silk_LPC_inverse_pred_gain( a_Q12, d ) < SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN, 30 ) ) {
             /* Prediction coefficients are (too close to) unstable; apply bandwidth expansion   */
             /* on the unscaled coefficients, convert to Q12 and measure again                   */
             silk_bwexpander_32( a32_QA1, d, 65536 - silk_LSHIFT( 2, i ) );
--- a/src/analysis.c
+++ b/src/analysis.c
@@ -283,12 +283,12 @@
        d_angle2 = angle2 - angle;
        d2_angle2 = d_angle2 - d_angle;
 
-       mod1 = d2_angle - (float)floor(.5+d2_angle);
+       mod1 = d2_angle - (float)floor(.5f+d2_angle);
        noisiness[i] = ABS16(mod1);
        mod1 *= mod1;
        mod1 *= mod1;
 
-       mod2 = d2_angle2 - (float)floor(.5+d2_angle2);
+       mod2 = d2_angle2 - (float)floor(.5f+d2_angle2);
        noisiness[i] += ABS16(mod2);
        mod2 *= mod2;
        mod2 *= mod2;
@@ -404,7 +404,7 @@
              both the ATH and the loudness-dependent slope of the spreading function)
           3) above the PCM quantization noise floor
        */
-       if (E>.1*bandwidth_mask && E*1e9f > maxE && E > noise_floor*(band_end-band_start))
+       if (E>.1f*bandwidth_mask && E*1e9f > maxE && E > noise_floor*(band_end-band_start))
           bandwidth = b;
     }
     if (tonal->count<=2)
@@ -568,9 +568,9 @@
           psum += tonal->pspeech[i];
 
        /* Estimate our confidence in the speech/music decisions */
-       if (frame_probs[1]>.75)
+       if (frame_probs[1]>.75f)
        {
-          if (tonal->music_prob>.9)
+          if (tonal->music_prob>.9f)
           {
              float adapt;
              adapt = 1.f/(++tonal->music_confidence_count);
@@ -577,7 +577,7 @@
              tonal->music_confidence_count = IMIN(tonal->music_confidence_count, 500);
              tonal->music_confidence += adapt*MAX16(-.2f,frame_probs[0]-tonal->music_confidence);
           }
-          if (tonal->music_prob<.1)
+          if (tonal->music_prob<.1f)
           {
              float adapt;
              adapt = 1.f/(++tonal->speech_confidence_count);
--- a/src/opus_compare.c
+++ b/src/opus_compare.c
@@ -75,7 +75,7 @@
         int s;
         s=buf[2*(xi*_nchannels+ci)+1]<<8|buf[2*(xi*_nchannels+ci)];
         s=((s&0xFFFF)^0x8000)-0x8000;
-        samples[(nsamples+xi)*_nchannels+ci]=s;
+        samples[(nsamples+xi)*_nchannels+ci]=(float)s;
       }
     }
     nsamples+=nread;
@@ -230,7 +230,7 @@
   /*Read in the data and allocate scratch space.*/
   xlength=read_pcm16(&x,fin1,2);
   if(nchannels==1){
-    for(xi=0;xi<xlength;xi++)x[xi]=.5*(x[2*xi]+x[2*xi+1]);
+    for(xi=0;xi<xlength;xi++)x[xi]=.5f*(x[2*xi]+x[2*xi+1]);
   }
   fclose(fin1);
   ylength=read_pcm16(&y,fin2,nchannels);
@@ -346,7 +346,7 @@
           float re;
           float im;
           re=Y[(xi*yfreqs+xj)*nchannels+ci]/X[(xi*NFREQS+xj)*nchannels+ci];
-          im=re-log(re)-1;
+          im=re-(float)log(re)-1;
           /*Make comparison less sensitive around the SILK/CELT cross-over to
             allow for mode freedom in the filters.*/
           if(xj>=79&&xj<=81)im*=0.1F;
@@ -364,7 +364,7 @@
     err+=Ef*Ef;
   }
   err=pow(err/nframes,1.0/16);
-  Q=100*(1-0.5*log(1+err)/log(1.13));
+  Q=100*(1-0.5f*(float)log(1+err)/log(1.13f));
   if(Q<0){
     fprintf(stderr,"Test vector FAILS\n");
     fprintf(stderr,"Internal weighted error is %f\n",err);
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -949,7 +949,7 @@
     {
        int analysis_bandwidth;
        if (st->signal_type == OPUS_AUTO)
-          st->voice_ratio = (int)floor(.5+100*(1-analysis_info->music_prob));
+          st->voice_ratio = (int)floor(.5f+100*(1-analysis_info->music_prob));
 
        analysis_bandwidth = analysis_info->bandwidth;
        if (analysis_bandwidth<=12)