Revision d0fa156f libavcodec/adpcm.c

View differences:

libavcodec/adpcm.c
1287 1287
        signmask = 1 << (nb_bits-1);
1288 1288

  
1289 1289
        while (get_bits_count(&gb) <= size - 22*avctx->channels) {
1290
        for (i = 0; i < avctx->channels; i++) {
1291
            *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
1292
            c->status[i].step_index = get_bits(&gb, 6);
1293
        }
1294

  
1295
        for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++)
1296
        {
1297
            int i;
1298

  
1299 1290
            for (i = 0; i < avctx->channels; i++) {
1300
                // similar to IMA adpcm
1301
                int delta = get_bits(&gb, nb_bits);
1302
                int step = step_table[c->status[i].step_index];
1303
                long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
1304
                int k = k0;
1305

  
1306
                do {
1307
                    if (delta & k)
1308
                        vpdiff += step;
1309
                    step >>= 1;
1310
                    k >>= 1;
1311
                } while(k);
1312
                vpdiff += step;
1313

  
1314
                if (delta & signmask)
1315
                    c->status[i].predictor -= vpdiff;
1316
                else
1317
                    c->status[i].predictor += vpdiff;
1318

  
1319
                c->status[i].step_index += table[delta & (~signmask)];
1320

  
1321
                c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
1322
                c->status[i].predictor = av_clip(c->status[i].predictor, -32768, 32767);
1323

  
1324
                *samples++ = c->status[i].predictor;
1325
                if (samples >= samples_end) {
1326
                    av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
1327
                    return -1;
1291
                *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
1292
                c->status[i].step_index = get_bits(&gb, 6);
1293
            }
1294

  
1295
            for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
1296
                int i;
1297

  
1298
                for (i = 0; i < avctx->channels; i++) {
1299
                    // similar to IMA adpcm
1300
                    int delta = get_bits(&gb, nb_bits);
1301
                    int step = step_table[c->status[i].step_index];
1302
                    long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
1303
                    int k = k0;
1304

  
1305
                    do {
1306
                        if (delta & k)
1307
                            vpdiff += step;
1308
                        step >>= 1;
1309
                        k >>= 1;
1310
                    } while(k);
1311
                    vpdiff += step;
1312

  
1313
                    if (delta & signmask)
1314
                        c->status[i].predictor -= vpdiff;
1315
                    else
1316
                        c->status[i].predictor += vpdiff;
1317

  
1318
                    c->status[i].step_index += table[delta & (~signmask)];
1319

  
1320
                    c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
1321
                    c->status[i].predictor = av_clip(c->status[i].predictor, -32768, 32767);
1322

  
1323
                    *samples++ = c->status[i].predictor;
1324
                    if (samples >= samples_end) {
1325
                        av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
1326
                        return -1;
1327
                    }
1328 1328
                }
1329 1329
            }
1330 1330
        }
1331
        }
1332 1331
        src += buf_size;
1333 1332
        break;
1334 1333
    }

Also available in: Unified diff