changeset 11652:8b6f3d3b55cb libavcodec

Move clipping of audio samples (for those codecs outputting float) from decoder to the audio conversion routines.
author rbultje
date Wed, 21 Apr 2010 17:57:48 +0000
parents 926ad89ae57a
children 28638e0d6e63
files amrnbdec.c atrac1.c audioconvert.c qcelpdata.h qcelpdec.c ra288.c sipr.c sipr16k.c twinvq.c wmaprodec.c wmavoice.c
diffstat 11 files changed, 17 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/amrnbdec.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/amrnbdec.c	Wed Apr 21 17:57:48 2010 +0000
@@ -796,7 +796,7 @@
                      float fixed_gain, const float *fixed_vector,
                      float *samples, uint8_t overflow)
 {
-    int i, overflow_temp = 0;
+    int i;
     float excitation[AMR_SUBFRAME_SIZE];
 
     // if an overflow has been detected, the pitch vector is scaled down by a
@@ -831,12 +831,10 @@
     // detect overflow
     for (i = 0; i < AMR_SUBFRAME_SIZE; i++)
         if (fabsf(samples[i]) > AMR_SAMPLE_BOUND) {
-            overflow_temp = 1;
-            samples[i] = av_clipf(samples[i], -AMR_SAMPLE_BOUND,
-                                               AMR_SAMPLE_BOUND);
+            return 1;
         }
 
-    return overflow_temp;
+    return 0;
 }
 
 /// @}
@@ -1048,10 +1046,6 @@
                                              highpass_poles, highpass_gain,
                                              p->high_pass_mem, AMR_BLOCK_SIZE);
 
-    for (i = 0; i < AMR_BLOCK_SIZE; i++)
-        buf_out[i] = av_clipf(buf_out[i] * AMR_SAMPLE_SCALE,
-                              -1.0, 32767.0 / 32768.0);
-
     /* Update averaged lsf vector (used for fixed gain smoothing).
      *
      * Note that lsf_avg should not incorporate the current frame's LSFs
--- a/atrac1.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/atrac1.c	Wed Apr 21 17:57:48 2010 +0000
@@ -305,20 +305,15 @@
         at1_subband_synthesis(q, su, q->out_samples[ch]);
     }
 
-    /* round, convert to 16bit and interleave */
+    /* interleave; FIXME, should create/use a DSP function */
     if (q->channels == 1) {
         /* mono */
-        q->dsp.vector_clipf(samples, q->out_samples[0], -32700.0 / (1 << 15),
-                            32700.0 / (1 << 15), AT1_SU_SAMPLES);
+        memcpy(samples, q->out_samples[0], AT1_SU_SAMPLES * 4);
     } else {
         /* stereo */
         for (i = 0; i < AT1_SU_SAMPLES; i++) {
-            samples[i * 2]     = av_clipf(q->out_samples[0][i],
-                                          -32700.0 / (1 << 15),
-                                           32700.0 / (1 << 15));
-            samples[i * 2 + 1] = av_clipf(q->out_samples[1][i],
-                                          -32700.0 / (1 << 15),
-                                           32700.0 / (1 << 15));
+            samples[i * 2]     = q->out_samples[0][i];
+            samples[i * 2 + 1] = q->out_samples[1][i];
         }
     }
 
--- a/audioconvert.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/audioconvert.c	Wed Apr 21 17:57:48 2010 +0000
@@ -209,7 +209,7 @@
 }
 
 //FIXME put things below under ifdefs so we do not waste space for cases no codec will need
-//FIXME rounding and clipping ?
+//FIXME rounding ?
 
              CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_U8 ,  *(const uint8_t*)pi)
         else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<8)
@@ -226,14 +226,14 @@
         else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S32,  *(const int32_t*)pi)
         else CONV(SAMPLE_FMT_FLT, float  , SAMPLE_FMT_S32,  *(const int32_t*)pi*(1.0 / (1<<31)))
         else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_S32,  *(const int32_t*)pi*(1.0 / (1<<31)))
-        else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, lrintf(*(const float*)pi * (1<<7)) + 0x80)
-        else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, lrintf(*(const float*)pi * (1<<15)))
-        else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, lrintf(*(const float*)pi * (1<<31)))
+        else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, av_clip_uint8(  lrintf(*(const float*)pi * (1<<7)) + 0x80))
+        else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, av_clip_int16(  lrintf(*(const float*)pi * (1<<15))))
+        else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float*)pi * (1U<<31))))
         else CONV(SAMPLE_FMT_FLT, float  , SAMPLE_FMT_FLT, *(const float*)pi)
         else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_FLT, *(const float*)pi)
-        else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_DBL, lrint(*(const double*)pi * (1<<7)) + 0x80)
-        else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_DBL, lrint(*(const double*)pi * (1<<15)))
-        else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_DBL, lrint(*(const double*)pi * (1<<31)))
+        else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_DBL, av_clip_uint8(  lrint(*(const double*)pi * (1<<7)) + 0x80))
+        else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_DBL, av_clip_int16(  lrint(*(const double*)pi * (1<<15))))
+        else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double*)pi * (1U<<31))))
         else CONV(SAMPLE_FMT_FLT, float  , SAMPLE_FMT_DBL, *(const double*)pi)
         else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_DBL, *(const double*)pi)
         else return -1;
--- a/qcelpdata.h	Wed Apr 21 17:51:37 2010 +0000
+++ b/qcelpdata.h	Wed Apr 21 17:57:48 2010 +0000
@@ -425,16 +425,6 @@
 #define QCELP_SCALE 8192.
 
 /**
- * the upper boundary of the clipping, depends on QCELP_SCALE
- */
-#define QCELP_CLIP_UPPER_BOUND (8191.75/8192.)
-
-/**
- * the lower boundary of the clipping, depends on QCELP_SCALE
- */
-#define QCELP_CLIP_LOWER_BOUND -1.
-
-/**
  * table for computing Ga (decoded linear codebook gain magnitude)
  *
  * @note The table could fit in int16_t in x*8 form, but it seems
--- a/qcelpdec.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/qcelpdec.c	Wed Apr 21 17:57:48 2010 +0000
@@ -834,10 +834,6 @@
 
     memcpy(q->formant_mem, q->formant_mem + 160, 10 * sizeof(float));
 
-    for(i=0; i<160; i++)
-        outbuffer[i] = av_clipf(outbuffer[i], QCELP_CLIP_LOWER_BOUND,
-                                QCELP_CLIP_UPPER_BOUND);
-
     memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf));
     q->prev_bitrate = q->bitrate;
 
--- a/ra288.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/ra288.c	Wed Apr 21 17:57:48 2010 +0000
@@ -102,10 +102,6 @@
     gain_block[9] = 10 * log10(sum) - 32;
 
     ff_celp_lp_synthesis_filterf(block, ractx->sp_lpc, buffer, 5, 36);
-
-    /* output */
-    for (i=0; i < 5; i++)
-        block[i] = av_clipf(block[i], -4095./4096., 4095./4096.);
 }
 
 /**
--- a/sipr.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/sipr.c	Wed Apr 21 17:57:48 2010 +0000
@@ -496,9 +496,6 @@
                                              0.939805806,
                                              ctx->highpass_filt_mem,
                                              frame_size);
-
-    ctx->dsp.vector_clipf(out_data, out_data, -1, 32767./(1<<15), frame_size);
-
 }
 
 static av_cold int sipr_decoder_init(AVCodecContext * avctx)
--- a/sipr16k.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/sipr16k.c	Wed Apr 21 17:57:48 2010 +0000
@@ -264,9 +264,6 @@
     postfilter(out_data, synth, ctx->iir_mem, ctx->filt_mem, ctx->mem_preemph);
 
     memcpy(ctx->iir_mem, Az[1], LP_FILTER_ORDER_16k * sizeof(float));
-
-    ctx->dsp.vector_clipf(out_data, out_data, -1, 32767./(1<<15), frame_size);
-
 }
 
 void ff_sipr_init_16k(SiprContext *ctx)
--- a/twinvq.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/twinvq.c	Wed Apr 21 17:57:48 2010 +0000
@@ -850,9 +850,6 @@
         return buf_size;
     }
 
-    tctx->dsp.vector_clipf(out, out, -32700./(1<<15), 32700./(1<<15),
-                           avctx->channels * mtab->size);
-
     *data_size = mtab->size*avctx->channels*4;
 
     return buf_size;
--- a/wmaprodec.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/wmaprodec.c	Wed Apr 21 17:57:48 2010 +0000
@@ -1351,8 +1351,9 @@
         float* iptr = s->channel[i].out;
         float* iend = iptr + s->samples_per_frame;
 
+        // FIXME should create/use a DSP function here
         while (iptr < iend) {
-            *ptr = av_clipf(*iptr++, -1.0, 32767.0 / 32768.0);
+            *ptr = *iptr++;
             ptr += incr;
         }
 
--- a/wmavoice.c	Wed Apr 21 17:51:37 2010 +0000
+++ b/wmavoice.c	Wed Apr 21 17:57:48 2010 +0000
@@ -1117,8 +1117,7 @@
         av_log_missing_feature(ctx, "APF", 0);
         s->do_apf = 0;
     } //else
-        for (n = 0; n < 160; n++)
-            samples[n] = av_clipf(synth[n], -1.0, 1.0);
+        memcpy(samples, synth, 160 * sizeof(synth[0]));
 
     /* Cache values for next frame */
     s->frame_cntr++;