Revision 35d3d44a

View differences:

libavcodec/adpcm.c
271 271
    return nibble;
272 272
}
273 273

  
274
static inline unsigned char adpcm_ima_qt_compress_sample(ADPCMChannelStatus *c, short sample)
275
{
276
    int delta = sample - c->prev_sample;
277
    int mask, step = step_table[c->step_index];
278
    int diff = step >> 3;
279
    int nibble = 0;
280

  
281
    if (delta < 0) {
282
        nibble = 8;
283
        delta = -delta;
284
    }
285

  
286
    for (mask = 4; mask;) {
287
        if (delta >= step) {
288
            nibble |= mask;
289
            delta -= step;
290
            diff += step;
291
        }
292
        step >>= 1;
293
        mask >>= 1;
294
    }
295

  
296
    if (nibble & 8)
297
        c->prev_sample -= diff;
298
    else
299
        c->prev_sample += diff;
300

  
301
    c->prev_sample = av_clip_int16(c->prev_sample);
302
    c->step_index = av_clip(c->step_index + index_table[nibble], 0, 88);
303

  
304
    return nibble;
305
}
306

  
274 307
static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample)
275 308
{
276 309
    int predictor, nibble, bias;
......
604 637
                adpcm_compress_trellis(avctx, samples+ch, buf, &c->status[ch], 64);
605 638
                for(i=0; i<64; i++)
606 639
                    put_bits(&pb, 4, buf[i^1]);
607
                c->status[ch].prev_sample = c->status[ch].predictor & ~0x7F;
608 640
            } else {
609 641
                for (i=0; i<64; i+=2){
610 642
                    int t1, t2;
611
                    t1 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+0)+ch]);
612
                    t2 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+1)+ch]);
643
                    t1 = adpcm_ima_qt_compress_sample(&c->status[ch], samples[avctx->channels*(i+0)+ch]);
644
                    t2 = adpcm_ima_qt_compress_sample(&c->status[ch], samples[avctx->channels*(i+1)+ch]);
613 645
                    put_bits(&pb, 4, t2);
614 646
                    put_bits(&pb, 4, t1);
615 647
                }
616
                c->status[ch].prev_sample &= ~0x7F;
617 648
            }
618 649
        }
619 650

  
tests/ref/acodec/adpcm_ima_qt
1
019564da45949d0b5278bd75ee9a4ac2 *./tests/data/acodec/adpcm_qt.aiff
1
057d27978b35888776512e4e9669a63b *./tests/data/acodec/adpcm_qt.aiff
2 2
281252 ./tests/data/acodec/adpcm_qt.aiff
3
a7fb054f7bd82270c8fd476eb9f5677c *./tests/data/adpcm_ima_qt.acodec.out.wav
4
stddev:  920.19 PSNR: 37.05 MAXDIFF:34029 bytes:  1058560/  1058400
3
3890343c0c20934e014d7ac93f5d65bd *./tests/data/adpcm_ima_qt.acodec.out.wav
4
stddev:  918.61 PSNR: 37.07 MAXDIFF:34029 bytes:  1058560/  1058400

Also available in: Unified diff