[FFmpeg-cvslog] r10080 - in trunk/libavcodec: adpcm.c adx.c liba52.c libvorbis.c ra144.c wmadec.c

aurel subversion
Sun Aug 12 01:17:03 CEST 2007


Author: aurel
Date: Sun Aug 12 01:17:03 2007
New Revision: 10080

Log:
various simplifications around recent av_clip_int16() usage

Modified:
   trunk/libavcodec/adpcm.c
   trunk/libavcodec/adx.c
   trunk/libavcodec/liba52.c
   trunk/libavcodec/libvorbis.c
   trunk/libavcodec/ra144.c
   trunk/libavcodec/wmadec.c

Modified: trunk/libavcodec/adpcm.c
==============================================================================
--- trunk/libavcodec/adpcm.c	(original)
+++ trunk/libavcodec/adpcm.c	Sun Aug 12 01:17:03 2007
@@ -208,7 +208,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);
+    c->prev_sample += ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8);
     c->prev_sample = av_clip_int16(c->prev_sample);
     c->step_index = av_clip(c->step_index + index_table[nibble], 0, 88);
     return nibble;
@@ -228,10 +228,9 @@ static inline unsigned char adpcm_ms_com
     nibble= av_clip(nibble, -8, 7)&0x0F;
 
     predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
-    predictor = av_clip_int16(predictor);
 
     c->sample2 = c->sample1;
-    c->sample1 = predictor;
+    c->sample1 = av_clip_int16(predictor);
 
     c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
     if (c->idelta < 16) c->idelta = 16;
@@ -252,7 +251,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);
+    c->predictor += ((c->step * yamaha_difflookup[nibble]) / 8);
     c->predictor = av_clip_int16(c->predictor);
     c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
     c->step = av_clip(c->step, 127, 24567);
@@ -670,11 +669,10 @@ static inline short adpcm_ima_expand_nib
     if (sign) predictor -= diff;
     else predictor += diff;
 
-    predictor = av_clip_int16(predictor);
-    c->predictor = predictor;
+    c->predictor = av_clip_int16(predictor);
     c->step_index = step_index;
 
-    return (short)predictor;
+    return (short)c->predictor;
 }
 
 static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
@@ -683,14 +681,13 @@ 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;
-    predictor = av_clip_int16(predictor);
 
     c->sample2 = c->sample1;
-    c->sample1 = predictor;
+    c->sample1 = av_clip_int16(predictor);
     c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
     if (c->idelta < 16) c->idelta = 16;
 
-    return (short)predictor;
+    return c->sample1;
 }
 
 static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
@@ -719,9 +716,8 @@ static inline short adpcm_ct_expand_nibb
     if(c->step > 32767)
         c->step = 32767;
 
-    predictor = av_clip_int16(predictor);
-    c->predictor = predictor;
-    return (short)predictor;
+    c->predictor = av_clip_int16(predictor);
+    return (short)c->predictor;
 }
 
 static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
@@ -789,11 +785,10 @@ static void xa_decode(short *out, const 
 
             t = (signed char)(d<<4)>>4;
             s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
-            s = av_clip_int16(s);
-            *out = s;
-            out += inc;
             s_2 = s_1;
-            s_1 = s;
+            s_1 = av_clip_int16(s);
+            *out = s_1;
+            out += inc;
         }
 
         if (inc==2) { /* stereo */
@@ -815,11 +810,10 @@ static void xa_decode(short *out, const 
 
             t = (signed char)d >> 4;
             s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
-            s = av_clip_int16(s);
-            *out = s;
-            out += inc;
             s_2 = s_1;
-            s_1 = s;
+            s_1 = av_clip_int16(s);
+            *out = s_1;
+            out += inc;
         }
 
         if (inc==2) { /* stereo */
@@ -1181,13 +1175,11 @@ static int adpcm_decode_frame(AVCodecCon
                 next_right_sample = (next_right_sample +
                     (current_right_sample * coeff1r) +
                     (previous_right_sample * coeff2r) + 0x80) >> 8;
-                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;
+                current_left_sample = av_clip_int16(next_left_sample);
                 previous_right_sample = current_right_sample;
-                current_right_sample = next_right_sample;
+                current_right_sample = av_clip_int16(next_right_sample);
                 *samples++ = (unsigned short)current_left_sample;
                 *samples++ = (unsigned short)current_right_sample;
             }
@@ -1386,8 +1378,7 @@ static int adpcm_decode_frame(AVCodecCon
 
                     sampledat = ((prev[ch][0]*factor1
                                 + prev[ch][1]*factor2) >> 11) + (sampledat>>exp);
-                    sampledat = av_clip_int16(sampledat);
-                    *samples = sampledat;
+                    *samples = av_clip_int16(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 01:17:03 2007
@@ -108,19 +108,17 @@ 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;
-        s0 = av_clip_int16(s0);
-        *out++=s0;
         s2 = s1;
-        s1 = s0;
+        s1 = av_clip_int16(s0);
+        *out++=s1;
 
         d = in[i];
         //d&=15; if (d&8) d-=16;
         d = ((signed char)(d<<4) >> 4);
         s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14;
-        s0 = av_clip_int16(s0);
-        *out++=s0;
         s2 = s1;
-        s1 = s0;
+        s1 = av_clip_int16(s0);
+        *out++=s1;
     }
     prev->s1 = s1;
     prev->s2 = s2;

Modified: trunk/libavcodec/liba52.c
==============================================================================
--- trunk/libavcodec/liba52.c	(original)
+++ trunk/libavcodec/liba52.c	Sun Aug 12 01:17:03 2007
@@ -120,12 +120,7 @@ static int a52_decode_init(AVCodecContex
     return 0;
 }
 
-/**** the following two functions comes from a52dec */
-static inline int blah (int32_t i)
-{
-    return av_clip_int16(i - 0x43c00000);
-}
-
+/**** the following function comes from a52dec */
 static inline void float_to_int (float * _f, int16_t * s16, int nchannels)
 {
     int i, j, c;
@@ -135,7 +130,7 @@ static inline void float_to_int (float *
     nchannels *= 256;
     for (i = 0; i < 256; i++) {
         for (c = 0; c < nchannels; c += 256)
-            s16[j++] = blah (f[i + c]);
+            s16[j++] = av_clip_int16(f[i + c] - 0x43c00000);
     }
 }
 

Modified: trunk/libavcodec/libvorbis.c
==============================================================================
--- trunk/libavcodec/libvorbis.c	(original)
+++ trunk/libavcodec/libvorbis.c	Sun Aug 12 01:17:03 2007
@@ -295,7 +295,7 @@ static int oggvorbis_decode_init(AVCodec
 
 
 static inline int conv(int samples, float **pcm, char *buf, int channels) {
-    int i, j, val ;
+    int i, j;
     ogg_int16_t *ptr, *data = (ogg_int16_t*)buf ;
     float *mono ;
 
@@ -304,12 +304,7 @@ static inline int conv(int samples, floa
         mono = pcm[i] ;
 
         for(j = 0 ; j < samples ; j++) {
-
-            val = mono[j] * 32767.f;
-
-            val = av_clip_int16(val);
-
-            *ptr = val ;
+            *ptr = av_clip_int16(mono[j] * 32767.f);
             ptr += channels;
         }
     }

Modified: trunk/libavcodec/ra144.c
==============================================================================
--- trunk/libavcodec/ra144.c	(original)
+++ trunk/libavcodec/ra144.c	Sun Aug 12 01:17:03 2007
@@ -430,7 +430,6 @@ static int ra144_decode_frame(AVCodecCon
             uint8_t * buf, int buf_size)
 {
   unsigned int a,b,c;
-  long s;
   signed short *shptr;
   unsigned int *lptr,*temp;
   const short **dptr;
@@ -484,11 +483,8 @@ static int ra144_decode_frame(AVCodecCon
     glob->resetflag=0;
 
     shptr=glob->output_buffer;
-    while (shptr<glob->output_buffer+BLOCKSIZE) {
-      s=*(shptr++)<<2;
-      *data=av_clip_int16(s);
-      data++;
-    }
+    while (shptr<glob->output_buffer+BLOCKSIZE)
+      *data++=av_clip_int16(*(shptr++)<<2);
     b+=30;
   }
 

Modified: trunk/libavcodec/wmadec.c
==============================================================================
--- trunk/libavcodec/wmadec.c	(original)
+++ trunk/libavcodec/wmadec.c	Sun Aug 12 01:17:03 2007
@@ -712,7 +712,7 @@ static int wma_decode_block(WMACodecCont
 /* decode a frame of frame_len samples */
 static int wma_decode_frame(WMACodecContext *s, int16_t *samples)
 {
-    int ret, i, n, a, ch, incr;
+    int ret, i, n, ch, incr;
     int16_t *ptr;
     float *iptr;
 
@@ -739,9 +739,7 @@ static int wma_decode_frame(WMACodecCont
         iptr = s->frame_out[ch];
 
         for(i=0;i<n;i++) {
-            a = lrintf(*iptr++);
-            a = av_clip_int16(a);
-            *ptr = a;
+            *ptr = av_clip_int16(lrintf(*iptr++));
             ptr += incr;
         }
         /* prepare for next block */




More information about the ffmpeg-cvslog mailing list