diff options
author | Aurelien Jacobs <aurel@gnuage.org> | 2007-08-11 23:17:03 +0000 |
---|---|---|
committer | Aurelien Jacobs <aurel@gnuage.org> | 2007-08-11 23:17:03 +0000 |
commit | 295f37379269e2df0e8983fbe89787ef1f49dc93 (patch) | |
tree | 917a4d87f90782008ce0de378f34cbbc623604c0 /libavcodec | |
parent | b0f3382873d275c4bd2e04f6f4f74f75162e5325 (diff) | |
download | ffmpeg-295f37379269e2df0e8983fbe89787ef1f49dc93.tar.gz |
various simplifications around recent av_clip_int16() usage
Originally committed as revision 10080 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/adpcm.c | 45 | ||||
-rw-r--r-- | libavcodec/adx.c | 10 | ||||
-rw-r--r-- | libavcodec/liba52.c | 9 | ||||
-rw-r--r-- | libavcodec/libvorbis.c | 9 | ||||
-rw-r--r-- | libavcodec/ra144.c | 8 | ||||
-rw-r--r-- | libavcodec/wmadec.c | 6 |
6 files changed, 30 insertions, 57 deletions
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 327787a5b9..0a1059e351 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -208,7 +208,7 @@ static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, sho { 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_compress_sample(ADPCMChannelStatus *c, shor 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_compress_sample(ADPCMChannelStatus *c, 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_nibble(ADPCMChannelStatus *c, char nibble, 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_nibble(ADPCMChannelStatus *c, char nibble) 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_nibble(ADPCMChannelStatus *c, char nibble) 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 unsigned char *in, 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 unsigned char *in, 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(AVCodecContext *avctx, 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(AVCodecContext *avctx, 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++; diff --git a/libavcodec/adx.c b/libavcodec/adx.c index 7185a32ce0..593c19de65 100644 --- a/libavcodec/adx.c +++ b/libavcodec/adx.c @@ -108,19 +108,17 @@ static void adx_decode(short *out,const unsigned char *in,PREV *prev) // 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; diff --git a/libavcodec/liba52.c b/libavcodec/liba52.c index ce0f822d93..68147a125e 100644 --- a/libavcodec/liba52.c +++ b/libavcodec/liba52.c @@ -120,12 +120,7 @@ static int a52_decode_init(AVCodecContext *avctx) 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 * _f, int16_t * s16, int nchannels) 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); } } diff --git a/libavcodec/libvorbis.c b/libavcodec/libvorbis.c index faaceb0ba7..5c78d2004b 100644 --- a/libavcodec/libvorbis.c +++ b/libavcodec/libvorbis.c @@ -295,7 +295,7 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) { 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, float **pcm, char *buf, int channels) { 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; } } diff --git a/libavcodec/ra144.c b/libavcodec/ra144.c index c820c732ba..e308c59e58 100644 --- a/libavcodec/ra144.c +++ b/libavcodec/ra144.c @@ -430,7 +430,6 @@ static int ra144_decode_frame(AVCodecContext * avctx, 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(AVCodecContext * avctx, 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; } diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c index 01bd47f8e1..1573e5d783 100644 --- a/libavcodec/wmadec.c +++ b/libavcodec/wmadec.c @@ -712,7 +712,7 @@ static int wma_decode_block(WMACodecContext *s) /* 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(WMACodecContext *s, int16_t *samples) 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 */ |