Mercurial > libavcodec.hg
comparison adpcm.c @ 5527:8b6ffd245ee2 libavcodec
more usage of av_clip()
author | aurel |
---|---|
date | Sat, 11 Aug 2007 23:29:21 +0000 |
parents | 9c37f7a3ff48 |
children | b97f9b97e454 |
comparison
equal
deleted
inserted
replaced
5526:9c37f7a3ff48 | 5527:8b6ffd245ee2 |
---|---|
704 /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */ | 704 /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */ |
705 c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff); | 705 c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff); |
706 c->predictor = av_clip_int16(c->predictor); | 706 c->predictor = av_clip_int16(c->predictor); |
707 /* calculate new step and clamp it to range 511..32767 */ | 707 /* calculate new step and clamp it to range 511..32767 */ |
708 new_step = (ct_adpcm_table[nibble & 7] * c->step) >> 8; | 708 new_step = (ct_adpcm_table[nibble & 7] * c->step) >> 8; |
709 c->step = new_step; | 709 c->step = av_clip(new_step, 511, 32767); |
710 if(c->step < 511) | |
711 c->step = 511; | |
712 if(c->step > 32767) | |
713 c->step = 32767; | |
714 | 710 |
715 return (short)c->predictor; | 711 return (short)c->predictor; |
716 } | 712 } |
717 | 713 |
718 static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift) | 714 static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift) |
721 | 717 |
722 sign = nibble & (1<<(size-1)); | 718 sign = nibble & (1<<(size-1)); |
723 delta = nibble & ((1<<(size-1))-1); | 719 delta = nibble & ((1<<(size-1))-1); |
724 diff = delta << (7 + c->step + shift); | 720 diff = delta << (7 + c->step + shift); |
725 | 721 |
726 if (sign) | |
727 c->predictor -= diff; | |
728 else | |
729 c->predictor += diff; | |
730 | |
731 /* clamp result */ | 722 /* clamp result */ |
732 if (c->predictor > 16256) | 723 c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256); |
733 c->predictor = 16256; | |
734 else if (c->predictor < -16384) | |
735 c->predictor = -16384; | |
736 | 724 |
737 /* calculate new step */ | 725 /* calculate new step */ |
738 if (delta >= (2*size - 3) && c->step < 3) | 726 if (delta >= (2*size - 3) && c->step < 3) |
739 c->step++; | 727 c->step++; |
740 else if (delta == 0 && c->step > 0) | 728 else if (delta == 0 && c->step > 0) |