[FFmpeg-cvslog] r10078 - in trunk/libavcodec: adpcm.c adx.c atrac3.c cook.c dpcm.c dsicinav.c liba52.c libvorbis.c mpegaudiodec.c ra144.c resample2.c sonic.c vmdav.c wmadec.c

aurel subversion
Sun Aug 12 00:48:56 CEST 2007


Author: aurel
Date: Sun Aug 12 00:48:55 2007
New Revision: 10078

Log:
use av_clip_int16() where it makes sens

Modified:
   trunk/libavcodec/adpcm.c
   trunk/libavcodec/adx.c
   trunk/libavcodec/atrac3.c
   trunk/libavcodec/cook.c
   trunk/libavcodec/dpcm.c
   trunk/libavcodec/dsicinav.c
   trunk/libavcodec/liba52.c
   trunk/libavcodec/libvorbis.c
   trunk/libavcodec/mpegaudiodec.c
   trunk/libavcodec/ra144.c
   trunk/libavcodec/resample2.c
   trunk/libavcodec/sonic.c
   trunk/libavcodec/vmdav.c
   trunk/libavcodec/wmadec.c

Modified: trunk/libavcodec/adpcm.c
==============================================================================
--- trunk/libavcodec/adpcm.c	(original)
+++ trunk/libavcodec/adpcm.c	Sun Aug 12 00:48:55 2007
@@ -50,12 +50,6 @@
 
 #define BLKSIZE 1024
 
-#define CLAMP_TO_SHORT(value) \
-if (value > 32767) \
-    value = 32767; \
-else if (value < -32768) \
-    value = -32768; \
-
 /* step_table[] and index_table[] are from the ADPCM reference source */
 /* This is the index table: */
 static const int index_table[16] = {
@@ -215,7 +209,7 @@ static inline unsigned char adpcm_ima_co
     int delta = sample - c->prev_sample;
     int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8;
     c->prev_sample = c->prev_sample + ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8);
-    CLAMP_TO_SHORT(c->prev_sample);
+    c->prev_sample = av_clip_int16(c->prev_sample);
     c->step_index = av_clip(c->step_index + index_table[nibble], 0, 88);
     return nibble;
 }
@@ -234,7 +228,7 @@ static inline unsigned char adpcm_ms_com
     nibble= av_clip(nibble, -8, 7)&0x0F;
 
     predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
-    CLAMP_TO_SHORT(predictor);
+    predictor = av_clip_int16(predictor);
 
     c->sample2 = c->sample1;
     c->sample1 = predictor;
@@ -259,7 +253,7 @@ static inline unsigned char adpcm_yamaha
     nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8;
 
     c->predictor = c->predictor + ((c->step * yamaha_difflookup[nibble]) / 8);
-    CLAMP_TO_SHORT(c->predictor);
+    c->predictor = av_clip_int16(c->predictor);
     c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
     c->step = av_clip(c->step, 127, 24567);
 
@@ -339,7 +333,7 @@ static void adpcm_compress_trellis(AVCod
 #define STORE_NODE(NAME, STEP_INDEX)\
                     int d;\
                     uint32_t ssd;\
-                    CLAMP_TO_SHORT(dec_sample);\
+                    dec_sample = av_clip_int16(dec_sample);\
                     d = sample - dec_sample;\
                     ssd = nodes[j]->ssd + d*d;\
                     if(nodes_next[frontier-1] && ssd >= nodes_next[frontier-1]->ssd)\
@@ -676,7 +670,7 @@ static inline short adpcm_ima_expand_nib
     if (sign) predictor -= diff;
     else predictor += diff;
 
-    CLAMP_TO_SHORT(predictor);
+    predictor = av_clip_int16(predictor);
     c->predictor = predictor;
     c->step_index = step_index;
 
@@ -689,7 +683,7 @@ static inline short adpcm_ms_expand_nibb
 
     predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
     predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
-    CLAMP_TO_SHORT(predictor);
+    predictor = av_clip_int16(predictor);
 
     c->sample2 = c->sample1;
     c->sample1 = predictor;
@@ -725,7 +719,7 @@ static inline short adpcm_ct_expand_nibb
     if(c->step > 32767)
         c->step = 32767;
 
-    CLAMP_TO_SHORT(predictor);
+    predictor = av_clip_int16(predictor);
     c->predictor = predictor;
     return (short)predictor;
 }
@@ -766,7 +760,7 @@ static inline short adpcm_yamaha_expand_
     }
 
     c->predictor += (c->step * yamaha_difflookup[nibble]) / 8;
-    CLAMP_TO_SHORT(c->predictor);
+    c->predictor = av_clip_int16(c->predictor);
     c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
     c->step = av_clip(c->step, 127, 24567);
     return c->predictor;
@@ -795,7 +789,7 @@ static void xa_decode(short *out, const 
 
             t = (signed char)(d<<4)>>4;
             s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
-            CLAMP_TO_SHORT(s);
+            s = av_clip_int16(s);
             *out = s;
             out += inc;
             s_2 = s_1;
@@ -821,7 +815,7 @@ static void xa_decode(short *out, const 
 
             t = (signed char)d >> 4;
             s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
-            CLAMP_TO_SHORT(s);
+            s = av_clip_int16(s);
             *out = s;
             out += inc;
             s_2 = s_1;
@@ -915,7 +909,7 @@ static int adpcm_decode_frame(AVCodecCon
         if(cs->predictor & 0x8000)
             cs->predictor -= 0x10000;
 
-        CLAMP_TO_SHORT(cs->predictor);
+        cs->predictor = av_clip_int16(cs->predictor);
 
         cs->step_index = (*src++) & 0x7F;
 
@@ -1187,8 +1181,8 @@ static int adpcm_decode_frame(AVCodecCon
                 next_right_sample = (next_right_sample +
                     (current_right_sample * coeff1r) +
                     (previous_right_sample * coeff2r) + 0x80) >> 8;
-                CLAMP_TO_SHORT(next_left_sample);
-                CLAMP_TO_SHORT(next_right_sample);
+                next_left_sample = av_clip_int16(next_left_sample);
+                next_right_sample = av_clip_int16(next_right_sample);
 
                 previous_left_sample = current_left_sample;
                 current_left_sample = next_left_sample;
@@ -1318,7 +1312,7 @@ static int adpcm_decode_frame(AVCodecCon
                     c->status[i].step_index += table[delta & (~signmask)];
 
                     c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
-                    c->status[i].predictor = av_clip(c->status[i].predictor, -32768, 32767);
+                    c->status[i].predictor = av_clip_int16(c->status[i].predictor);
 
                     *samples++ = c->status[i].predictor;
                     if (samples >= samples_end) {
@@ -1392,7 +1386,7 @@ static int adpcm_decode_frame(AVCodecCon
 
                     sampledat = ((prev[ch][0]*factor1
                                 + prev[ch][1]*factor2) >> 11) + (sampledat>>exp);
-                    CLAMP_TO_SHORT(sampledat);
+                    sampledat = av_clip_int16(sampledat);
                     *samples = sampledat;
                     prev[ch][1] = prev[ch][0];
                     prev[ch][0] = *samples++;

Modified: trunk/libavcodec/adx.c
==============================================================================
--- trunk/libavcodec/adx.c	(original)
+++ trunk/libavcodec/adx.c	Sun Aug 12 00:48:55 2007
@@ -46,8 +46,6 @@ typedef struct {
 #define    SCALE1    0x7298
 #define    SCALE2    0x3350
 
-#define    CLIP(s)    if (s>32767) s=32767; else if (s<-32768) s=-32768
-
 /* 18 bytes <-> 32 samples */
 
 #ifdef CONFIG_ENCODERS
@@ -110,7 +108,7 @@ static void adx_decode(short *out,const 
         // d>>=4; if (d&8) d-=16;
         d = ((signed char)d >> 4);
         s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14;
-        CLIP(s0);
+        s0 = av_clip_int16(s0);
         *out++=s0;
         s2 = s1;
         s1 = s0;
@@ -119,7 +117,7 @@ static void adx_decode(short *out,const 
         //d&=15; if (d&8) d-=16;
         d = ((signed char)(d<<4) >> 4);
         s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14;
-        CLIP(s0);
+        s0 = av_clip_int16(s0);
         *out++=s0;
         s2 = s1;
         s1 = s0;

Modified: trunk/libavcodec/atrac3.c
==============================================================================
--- trunk/libavcodec/atrac3.c	(original)
+++ trunk/libavcodec/atrac3.c	Sun Aug 12 00:48:55 2007
@@ -895,13 +895,13 @@ static int atrac3_decode_frame(AVCodecCo
     if (q->channels == 1) {
         /* mono */
         for (i = 0; i<1024; i++)
-            samples[i] = av_clip(round(q->outSamples[i]), -32768, 32767);
+            samples[i] = av_clip_int16(round(q->outSamples[i]));
         *data_size = 1024 * sizeof(int16_t);
     } else {
         /* stereo */
         for (i = 0; i < 1024; i++) {
-            samples[i*2] = av_clip(round(q->outSamples[i]), -32768, 32767);
-            samples[i*2+1] = av_clip(round(q->outSamples[1024+i]), -32768, 32767);
+            samples[i*2] = av_clip_int16(round(q->outSamples[i]));
+            samples[i*2+1] = av_clip_int16(round(q->outSamples[1024+i]));
         }
         *data_size = 2048 * sizeof(int16_t);
     }

Modified: trunk/libavcodec/cook.c
==============================================================================
--- trunk/libavcodec/cook.c	(original)
+++ trunk/libavcodec/cook.c	Sun Aug 12 00:48:55 2007
@@ -906,7 +906,7 @@ saturate_output_float (COOKContext *q, i
      */
     for (j = 0; j < q->samples_per_channel; j++) {
         out[chan + q->nb_channels * j] =
-          av_clip(lrintf(output[j]), -32768, 32767);
+          av_clip_int16(lrintf(output[j]));
     }
 }
 

Modified: trunk/libavcodec/dpcm.c
==============================================================================
--- trunk/libavcodec/dpcm.c	(original)
+++ trunk/libavcodec/dpcm.c	Sun Aug 12 00:48:55 2007
@@ -46,8 +46,6 @@ typedef struct DPCMContext {
     const int *sol_table;//for SOL_DPCM
 } DPCMContext;
 
-#define SATURATE_S16(x)  if (x < -32768) x = -32768; \
-  else if (x > 32767) x = 32767;
 #define SE_16BIT(x)  if (x & 0x8000) x -= 0x10000;
 
 static int interplay_delta_table[] = {
@@ -190,7 +188,7 @@ static int dpcm_decode_frame(AVCodecCont
         /* decode the samples */
         for (in = 8, out = 0; in < buf_size; in++, out++) {
             predictor[channel_number] += s->roq_square_array[buf[in]];
-            SATURATE_S16(predictor[channel_number]);
+            predictor[channel_number] = av_clip_int16(predictor[channel_number]);
             output_samples[out] = predictor[channel_number];
 
             /* toggle channel */
@@ -213,7 +211,7 @@ static int dpcm_decode_frame(AVCodecCont
 
         while (in < buf_size) {
             predictor[channel_number] += interplay_delta_table[buf[in++]];
-            SATURATE_S16(predictor[channel_number]);
+            predictor[channel_number] = av_clip_int16(predictor[channel_number]);
             output_samples[out++] = predictor[channel_number];
 
             /* toggle channel */
@@ -248,7 +246,7 @@ static int dpcm_decode_frame(AVCodecCont
             diff >>= shift[channel_number];
             predictor[channel_number] += diff;
 
-            SATURATE_S16(predictor[channel_number]);
+            predictor[channel_number] = av_clip_int16(predictor[channel_number]);
             output_samples[out++] = predictor[channel_number];
 
             /* toggle channel */
@@ -277,7 +275,7 @@ static int dpcm_decode_frame(AVCodecCont
                 n = buf[in++];
                 if (n & 0x80) s->sample[channel_number] -= s->sol_table[n & 0x7F];
                 else s->sample[channel_number] += s->sol_table[n & 0x7F];
-                SATURATE_S16(s->sample[channel_number]);
+                s->sample[channel_number] = av_clip_int16(s->sample[channel_number]);
                 output_samples[out++] = s->sample[channel_number];
                 /* toggle channel */
                 channel_number ^= s->channels - 1;

Modified: trunk/libavcodec/dsicinav.c
==============================================================================
--- trunk/libavcodec/dsicinav.c	(original)
+++ trunk/libavcodec/dsicinav.c	Sun Aug 12 00:48:55 2007
@@ -325,7 +325,7 @@ static int cinaudio_decode_frame(AVCodec
     }
     while (buf_size > 0) {
         cin->delta += cinaudio_delta16_table[*src++];
-        cin->delta = av_clip(cin->delta, -32768, 32767);
+        cin->delta = av_clip_int16(cin->delta);
         *samples++ = cin->delta;
         --buf_size;
     }

Modified: trunk/libavcodec/liba52.c
==============================================================================
--- trunk/libavcodec/liba52.c	(original)
+++ trunk/libavcodec/liba52.c	Sun Aug 12 00:48:55 2007
@@ -123,11 +123,7 @@ static int a52_decode_init(AVCodecContex
 /**** the following two functions comes from a52dec */
 static inline int blah (int32_t i)
 {
-    if (i > 0x43c07fff)
-        return 32767;
-    else if (i < 0x43bf8000)
-        return -32768;
-    return i - 0x43c00000;
+    return av_clip_int16(i - 0x43c00000);
 }
 
 static inline void float_to_int (float * _f, int16_t * s16, int nchannels)

Modified: trunk/libavcodec/libvorbis.c
==============================================================================
--- trunk/libavcodec/libvorbis.c	(original)
+++ trunk/libavcodec/libvorbis.c	Sun Aug 12 00:48:55 2007
@@ -307,8 +307,7 @@ static inline int conv(int samples, floa
 
             val = mono[j] * 32767.f;
 
-            if(val > 32767) val = 32767 ;
-            if(val < -32768) val = -32768 ;
+            val = av_clip_int16(val);
 
             *ptr = val ;
             ptr += channels;

Modified: trunk/libavcodec/mpegaudiodec.c
==============================================================================
--- trunk/libavcodec/mpegaudiodec.c	(original)
+++ trunk/libavcodec/mpegaudiodec.c	Sun Aug 12 00:48:55 2007
@@ -822,10 +822,7 @@ void ff_mpa_synth_filter(MPA_INT *synth_
 #if FRAC_BITS <= 15
         /* NOTE: can cause a loss in precision if very high amplitude
            sound */
-        if (v > 32767)
-            v = 32767;
-        else if (v < -32768)
-            v = -32768;
+        v = av_clip_int16(v);
 #endif
         synth_buf[j] = v;
     }

Modified: trunk/libavcodec/ra144.c
==============================================================================
--- trunk/libavcodec/ra144.c	(original)
+++ trunk/libavcodec/ra144.c	Sun Aug 12 00:48:55 2007
@@ -486,9 +486,7 @@ static int ra144_decode_frame(AVCodecCon
     shptr=glob->output_buffer;
     while (shptr<glob->output_buffer+BLOCKSIZE) {
       s=*(shptr++)<<2;
-      *data=s;
-      if (s>32767) *data=32767;
-      if (s<-32767) *data=-32768;
+      *data=av_clip_int16(s);
       data++;
     }
     b+=30;

Modified: trunk/libavcodec/resample2.c
==============================================================================
--- trunk/libavcodec/resample2.c	(original)
+++ trunk/libavcodec/resample2.c	Sun Aug 12 00:48:55 2007
@@ -279,7 +279,7 @@ int av_resample(AVResampleContext *c, sh
         }
 
 #ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
-        dst[dst_index] = av_clip(lrintf(val), -32768, 32767);
+        dst[dst_index] = av_clip_int16(lrintf(val));
 #else
         val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;
         dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val;

Modified: trunk/libavcodec/sonic.c
==============================================================================
--- trunk/libavcodec/sonic.c	(original)
+++ trunk/libavcodec/sonic.c	Sun Aug 12 00:48:55 2007
@@ -926,14 +926,7 @@ static int sonic_decode_frame(AVCodecCon
 
     // internal -> short
     for (i = 0; i < s->frame_size; i++)
-    {
-        if (s->int_samples[i] > 32767)
-            samples[i] = 32767;
-        else if (s->int_samples[i] < -32768)
-            samples[i] = -32768;
-        else
-            samples[i] = s->int_samples[i];
-    }
+        samples[i] = av_clip_int16(s->int_samples[i]);
 
     align_get_bits(&gb);
 

Modified: trunk/libavcodec/vmdav.c
==============================================================================
--- trunk/libavcodec/vmdav.c	(original)
+++ trunk/libavcodec/vmdav.c	Sun Aug 12 00:48:55 2007
@@ -458,7 +458,7 @@ static void vmdaudio_decode_audio(VmdAud
             s->predictors[chan] -= vmdaudio_table[buf[i] & 0x7F];
         else
             s->predictors[chan] += vmdaudio_table[buf[i]];
-        s->predictors[chan] = av_clip(s->predictors[chan], -32768, 32767);
+        s->predictors[chan] = av_clip_int16(s->predictors[chan]);
         out[i] = s->predictors[chan];
         chan ^= stereo;
     }

Modified: trunk/libavcodec/wmadec.c
==============================================================================
--- trunk/libavcodec/wmadec.c	(original)
+++ trunk/libavcodec/wmadec.c	Sun Aug 12 00:48:55 2007
@@ -740,10 +740,7 @@ static int wma_decode_frame(WMACodecCont
 
         for(i=0;i<n;i++) {
             a = lrintf(*iptr++);
-            if (a > 32767)
-                a = 32767;
-            else if (a < -32768)
-                a = -32768;
+            a = av_clip_int16(a);
             *ptr = a;
             ptr += incr;
         }




More information about the ffmpeg-cvslog mailing list