summaryrefslogtreecommitdiff
path: root/libavcodec/adpcm.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-05-08 13:20:22 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-05-08 13:21:51 +0200
commitaf3c8f823018ef8c07b25c8834d8032093a49418 (patch)
treec0ee4c360abec940332b300244826574b8b5d24a /libavcodec/adpcm.c
parent35d3d44a84870eefbc57bde80bd52a46b598bfa7 (diff)
adpcmenc:Optimize adpcm_ima_qt_compress_sample()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/adpcm.c')
-rw-r--r--libavcodec/adpcm.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 2d231e862a..ba312558b0 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -274,24 +274,27 @@ static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, sho
static inline unsigned char adpcm_ima_qt_compress_sample(ADPCMChannelStatus *c, short sample)
{
int delta = sample - c->prev_sample;
- int mask, step = step_table[c->step_index];
- int diff = step >> 3;
- int nibble = 0;
+ int diff, step = step_table[c->step_index];
+ int nibble = 8*(delta < 0);
- if (delta < 0) {
- nibble = 8;
- delta = -delta;
- }
+ delta= abs(delta);
+ diff = delta + (step >> 3);
- for (mask = 4; mask;) {
- if (delta >= step) {
- nibble |= mask;
- delta -= step;
- diff += step;
- }
- step >>= 1;
- mask >>= 1;
+ if (delta >= step) {
+ nibble |= 4;
+ delta -= step;
+ }
+ step >>= 1;
+ if (delta >= step) {
+ nibble |= 2;
+ delta -= step;
+ }
+ step >>= 1;
+ if (delta >= step) {
+ nibble |= 1;
+ delta -= step;
}
+ diff -= delta;
if (nibble & 8)
c->prev_sample -= diff;