[FFmpeg-cvslog] r22937 - in trunk: libavcodec/amrnbdec.c libavcodec/atrac1.c libavcodec/audioconvert.c libavcodec/qcelpdata.h libavcodec/qcelpdec.c libavcodec/ra288.c libavcodec/sipr.c libavcodec/sipr16k.c libavco...

rbultje subversion
Wed Apr 21 19:57:48 CEST 2010


Author: rbultje
Date: Wed Apr 21 19:57:48 2010
New Revision: 22937

Log:
Move clipping of audio samples (for those codecs outputting float) from decoder
to the audio conversion routines.

Modified:
   trunk/libavcodec/amrnbdec.c
   trunk/libavcodec/atrac1.c
   trunk/libavcodec/audioconvert.c
   trunk/libavcodec/qcelpdata.h
   trunk/libavcodec/qcelpdec.c
   trunk/libavcodec/ra288.c
   trunk/libavcodec/sipr.c
   trunk/libavcodec/sipr16k.c
   trunk/libavcodec/twinvq.c
   trunk/libavcodec/wmaprodec.c
   trunk/libavcodec/wmavoice.c
   trunk/libavutil/common.h

Modified: trunk/libavcodec/amrnbdec.c
==============================================================================
--- trunk/libavcodec/amrnbdec.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/amrnbdec.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -796,7 +796,7 @@ static int synthesis(AMRContext *p, floa
                      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 @@ static int synthesis(AMRContext *p, floa
     // 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 @@ static int amrnb_decode_frame(AVCodecCon
                                              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

Modified: trunk/libavcodec/atrac1.c
==============================================================================
--- trunk/libavcodec/atrac1.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/atrac1.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -305,20 +305,15 @@ static int atrac1_decode_frame(AVCodecCo
         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];
         }
     }
 

Modified: trunk/libavcodec/audioconvert.c
==============================================================================
--- trunk/libavcodec/audioconvert.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/audioconvert.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -209,7 +209,7 @@ if(ctx->fmt_pair == ofmt + SAMPLE_FMT_NB
 }
 
 //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 @@ if(ctx->fmt_pair == ofmt + SAMPLE_FMT_NB
         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;

Modified: trunk/libavcodec/qcelpdata.h
==============================================================================
--- trunk/libavcodec/qcelpdata.h	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/qcelpdata.h	Wed Apr 21 19:57:48 2010	(r22937)
@@ -425,16 +425,6 @@ static const qcelp_vector * const qcelp_
 #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

Modified: trunk/libavcodec/qcelpdec.c
==============================================================================
--- trunk/libavcodec/qcelpdec.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/qcelpdec.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -834,10 +834,6 @@ erasure:
 
     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;
 

Modified: trunk/libavcodec/ra288.c
==============================================================================
--- trunk/libavcodec/ra288.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/ra288.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -102,10 +102,6 @@ static void decode(RA288Context *ractx, 
     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.);
 }
 
 /**

Modified: trunk/libavcodec/sipr.c
==============================================================================
--- trunk/libavcodec/sipr.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/sipr.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -496,9 +496,6 @@ static void decode_frame(SiprContext *ct
                                              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)

Modified: trunk/libavcodec/sipr16k.c
==============================================================================
--- trunk/libavcodec/sipr16k.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/sipr16k.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -264,9 +264,6 @@ void ff_sipr_decode_frame_16k(SiprContex
     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)

Modified: trunk/libavcodec/twinvq.c
==============================================================================
--- trunk/libavcodec/twinvq.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/twinvq.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -850,9 +850,6 @@ static int twin_decode_frame(AVCodecCont
         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;

Modified: trunk/libavcodec/wmaprodec.c
==============================================================================
--- trunk/libavcodec/wmaprodec.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/wmaprodec.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -1351,8 +1351,9 @@ static int decode_frame(WMAProDecodeCtx 
         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;
         }
 

Modified: trunk/libavcodec/wmavoice.c
==============================================================================
--- trunk/libavcodec/wmavoice.c	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavcodec/wmavoice.c	Wed Apr 21 19:57:48 2010	(r22937)
@@ -1117,8 +1117,7 @@ static int synth_frame(AVCodecContext *c
         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++;

Modified: trunk/libavutil/common.h
==============================================================================
--- trunk/libavutil/common.h	Wed Apr 21 19:51:37 2010	(r22936)
+++ trunk/libavutil/common.h	Wed Apr 21 19:57:48 2010	(r22937)
@@ -145,6 +145,17 @@ static inline av_const int16_t av_clip_i
 }
 
 /**
+ * Clips a signed 64-bit integer value into the -2147483648,2147483647 range.
+ * @param a value to clip
+ * @return clipped value
+ */
+static inline av_const int32_t av_clipl_int32(int64_t a)
+{
+    if ((a+2147483648) & ~2147483647) return (a>>63) ^ 2147483647;
+    else                              return a;
+}
+
+/**
  * Clips a float value into the amin-amax range.
  * @param a value to clip
  * @param amin minimum value of the clip range



More information about the ffmpeg-cvslog mailing list