60 #define FREEZE_INTERVAL 128
82 int frontier = 1 << avctx->
trellis;
85 max_paths *
sizeof(*s->
paths), error);
87 2 * frontier *
sizeof(*s->
node_buf), error);
89 2 * frontier *
sizeof(*s->
nodep_buf), error);
121 bytestream_put_le16(&extradata, avctx->
frame_size);
122 bytestream_put_le16(&extradata, 7);
123 for (i = 0; i < 7; i++) {
148 #if FF_API_OLD_ENCODE_AUDIO
162 #if FF_API_OLD_ENCODE_AUDIO
178 int nibble =
FFMIN(7, abs(delta) * 4 /
192 int nibble = 8*(delta < 0);
195 diff = delta + (step >> 3);
238 nibble = (nibble + bias) / c->
idelta;
239 nibble = av_clip(nibble, -8, 7) & 0x0F;
241 predictor += ((nibble & 0x08) ? (nibble - 0x10) : nibble) * c->
idelta;
244 c->
sample1 = av_clip_int16(predictor);
265 nibble =
FFMIN(7, abs(delta) * 4 / c->
step) + (delta < 0) * 8;
270 c->
step = av_clip(c->
step, 127, 24567);
281 const int frontier = 1 << avctx->
trellis;
288 int pathn = 0, froze = -1, i, j, k, generation = 0;
290 memset(hash, 0xff, 65536 *
sizeof(*hash));
292 memset(nodep_buf, 0, 2 * frontier *
sizeof(*nodep_buf));
293 nodes[0] = node_buf + frontier;
307 nodes[0]->
step = 127;
315 for (i = 0; i < n; i++) {
320 memset(nodes_next, 0, frontier *
sizeof(
TrellisNode*));
321 for (j = 0; j < frontier && nodes[j]; j++) {
324 const int range = (j < frontier / 2) ? 1 : 0;
325 const int step = nodes[j]->step;
329 (nodes[j]->sample2 * c->
coeff2)) / 64;
330 const int div = (sample -
predictor) / step;
331 const int nmin = av_clip(div-range, -8, 6);
332 const int nmax = av_clip(div+range, -7, 7);
333 for (nidx = nmin; nidx <= nmax; nidx++) {
334 const int nibble = nidx & 0xf;
335 int dec_sample = predictor + nidx * step;
336 #define STORE_NODE(NAME, STEP_INDEX)\
342 dec_sample = av_clip_int16(dec_sample);\
343 d = sample - dec_sample;\
344 ssd = nodes[j]->ssd + d*d;\
349 if (ssd < nodes[j]->ssd)\
362 h = &hash[(uint16_t) dec_sample];\
363 if (*h == generation)\
365 if (heap_pos < frontier) {\
370 pos = (frontier >> 1) +\
371 (heap_pos & ((frontier >> 1) - 1));\
372 if (ssd > nodes_next[pos]->ssd)\
377 u = nodes_next[pos];\
379 av_assert1(pathn < FREEZE_INTERVAL << avctx->trellis);\
381 nodes_next[pos] = u;\
385 u->step = STEP_INDEX;\
386 u->sample2 = nodes[j]->sample1;\
387 u->sample1 = dec_sample;\
388 paths[u->path].nibble = nibble;\
389 paths[u->path].prev = nodes[j]->path;\
393 int parent = (pos - 1) >> 1;\
394 if (nodes_next[parent]->ssd <= ssd)\
396 FFSWAP(TrellisNode*, nodes_next[parent], nodes_next[pos]);\
406 #define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
407 const int predictor = nodes[j]->sample1;\
408 const int div = (sample - predictor) * 4 / STEP_TABLE;\
409 int nmin = av_clip(div - range, -7, 6);\
410 int nmax = av_clip(div + range, -6, 7);\
415 for (nidx = nmin; nidx <= nmax; nidx++) {\
416 const int nibble = nidx < 0 ? 7 - nidx : nidx;\
417 int dec_sample = predictor +\
419 ff_adpcm_yamaha_difflookup[nibble]) / 8;\
420 STORE_NODE(NAME, STEP_INDEX);\
438 if (generation == 255) {
439 memset(hash, 0xff, 65536 *
sizeof(*hash));
444 if (nodes[0]->ssd > (1 << 28)) {
445 for (j = 1; j < frontier && nodes[j]; j++)
446 nodes[j]->ssd -= nodes[0]->ssd;
452 p = &paths[nodes[0]->path];
453 for (k = i; k > froze; k--) {
462 memset(nodes + 1, 0, (frontier - 1) *
sizeof(
TrellisNode*));
466 p = &paths[nodes[0]->
path];
467 for (i = n - 1; i > froze; i--) {
473 c->
sample1 = nodes[0]->sample1;
474 c->
sample2 = nodes[0]->sample2;
476 c->
step = nodes[0]->step;
477 c->
idelta = nodes[0]->step;
483 int n, i, ch, st, pkt_size, ret;
490 samples = (
const int16_t *)frame->
data[0];
509 for (ch = 0; ch < avctx->
channels; ch++) {
522 for (ch = 0; ch < avctx->
channels; ch++) {
524 buf + ch * blocks * 8, &c->
status[ch],
527 for (i = 0; i < blocks; i++) {
528 for (ch = 0; ch < avctx->
channels; ch++) {
529 uint8_t *buf1 = buf + ch * blocks * 8 + i * 8;
530 for (j = 0; j < 8; j += 2)
531 *dst++ = buf1[j] | (buf1[j + 1] << 4);
536 for (i = 0; i < blocks; i++) {
537 for (ch = 0; ch < avctx->
channels; ch++) {
539 const int16_t *smp = &samples_p[ch][1 + i * 8];
540 for (j = 0; j < 8; j += 2) {
555 for (ch = 0; ch < avctx->
channels; ch++) {
563 for (i = 0; i < 64; i++)
566 for (i = 0; i < 64; i += 2) {
590 for (i = 0; i < avctx->
channels; i++) {
604 buf + n, &c->
status[1], n,
606 for (i = 0; i < n; i++) {
618 samples[2 * i + 1]));
625 for (i = 0; i < avctx->
channels; i++) {
631 for (i = 0; i < avctx->
channels; i++) {
636 for (i = 0; i < avctx->
channels; i++)
642 for (i = 0; i < avctx->
channels; i++)
651 for (i = 0; i < n; i += 2)
652 *dst++ = (buf[i] << 4) | buf[i + 1];
658 for (i = 0; i < n; i++)
659 *dst++ = (buf[i] << 4) | buf[n + i];
663 for (i = 7 * avctx->
channels; i < avctx->block_align; i++) {
679 for (i = 0; i < n; i += 2)
680 *dst++ = buf[i] | (buf[i + 1] << 4);
686 for (i = 0; i < n; i++)
687 *dst++ = buf[i] | (buf[n + i] << 4);
691 for (n *= avctx->
channels; n > 0; n--) {
717 #define ADPCM_ENCODER(id_, name_, sample_fmts_, long_name_) \
718 AVCodec ff_ ## name_ ## _encoder = { \
720 .type = AVMEDIA_TYPE_AUDIO, \
722 .priv_data_size = sizeof(ADPCMEncodeContext), \
723 .init = adpcm_encode_init, \
724 .encode2 = adpcm_encode_frame, \
725 .close = adpcm_encode_close, \
726 .sample_fmts = sample_fmts_, \
727 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \