59 #define FREEZE_INTERVAL 128
81 int frontier = 1 << avctx->
trellis;
84 max_paths *
sizeof(*s->
paths), error);
86 2 * frontier *
sizeof(*s->
node_buf), error);
88 2 * frontier *
sizeof(*s->
nodep_buf), error);
120 bytestream_put_le16(&extradata, avctx->
frame_size);
121 bytestream_put_le16(&extradata, 7);
122 for (i = 0; i < 7; i++) {
147 #if FF_API_OLD_ENCODE_AUDIO
161 #if FF_API_OLD_ENCODE_AUDIO
177 int nibble =
FFMIN(7, abs(delta) * 4 /
191 int nibble = 8*(delta < 0);
194 diff = delta + (step >> 3);
237 nibble = (nibble + bias) / c->
idelta;
238 nibble = av_clip(nibble, -8, 7) & 0x0F;
240 predictor += ((nibble & 0x08) ? (nibble - 0x10) : nibble) * c->
idelta;
243 c->
sample1 = av_clip_int16(predictor);
264 nibble =
FFMIN(7, abs(delta) * 4 / c->
step) + (delta < 0) * 8;
269 c->
step = av_clip(c->
step, 127, 24567);
280 const int frontier = 1 << avctx->
trellis;
287 int pathn = 0, froze = -1, i, j, k, generation = 0;
289 memset(hash, 0xff, 65536 *
sizeof(*hash));
291 memset(nodep_buf, 0, 2 * frontier *
sizeof(*nodep_buf));
292 nodes[0] = node_buf + frontier;
306 nodes[0]->
step = 127;
314 for (i = 0; i < n; i++) {
319 memset(nodes_next, 0, frontier *
sizeof(
TrellisNode*));
320 for (j = 0; j < frontier && nodes[j]; j++) {
323 const int range = (j < frontier / 2) ? 1 : 0;
324 const int step = nodes[j]->step;
328 (nodes[j]->sample2 * c->
coeff2)) / 64;
329 const int div = (sample -
predictor) / step;
330 const int nmin = av_clip(div-range, -8, 6);
331 const int nmax = av_clip(div+range, -7, 7);
332 for (nidx = nmin; nidx <= nmax; nidx++) {
333 const int nibble = nidx & 0xf;
334 int dec_sample = predictor + nidx * step;
335 #define STORE_NODE(NAME, STEP_INDEX)\
341 dec_sample = av_clip_int16(dec_sample);\
342 d = sample - dec_sample;\
343 ssd = nodes[j]->ssd + d*d;\
348 if (ssd < nodes[j]->ssd)\
361 h = &hash[(uint16_t) dec_sample];\
362 if (*h == generation)\
364 if (heap_pos < frontier) {\
369 pos = (frontier >> 1) +\
370 (heap_pos & ((frontier >> 1) - 1));\
371 if (ssd > nodes_next[pos]->ssd)\
376 u = nodes_next[pos];\
378 av_assert1(pathn < FREEZE_INTERVAL << avctx->trellis);\
380 nodes_next[pos] = u;\
384 u->step = STEP_INDEX;\
385 u->sample2 = nodes[j]->sample1;\
386 u->sample1 = dec_sample;\
387 paths[u->path].nibble = nibble;\
388 paths[u->path].prev = nodes[j]->path;\
392 int parent = (pos - 1) >> 1;\
393 if (nodes_next[parent]->ssd <= ssd)\
395 FFSWAP(TrellisNode*, nodes_next[parent], nodes_next[pos]);\
405 #define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
406 const int predictor = nodes[j]->sample1;\
407 const int div = (sample - predictor) * 4 / STEP_TABLE;\
408 int nmin = av_clip(div - range, -7, 6);\
409 int nmax = av_clip(div + range, -6, 7);\
414 for (nidx = nmin; nidx <= nmax; nidx++) {\
415 const int nibble = nidx < 0 ? 7 - nidx : nidx;\
416 int dec_sample = predictor +\
418 ff_adpcm_yamaha_difflookup[nibble]) / 8;\
419 STORE_NODE(NAME, STEP_INDEX);\
437 if (generation == 255) {
438 memset(hash, 0xff, 65536 *
sizeof(*hash));
443 if (nodes[0]->ssd > (1 << 28)) {
444 for (j = 1; j < frontier && nodes[j]; j++)
445 nodes[j]->ssd -= nodes[0]->ssd;
451 p = &paths[nodes[0]->path];
452 for (k = i; k > froze; k--) {
461 memset(nodes + 1, 0, (frontier - 1) *
sizeof(
TrellisNode*));
465 p = &paths[nodes[0]->
path];
466 for (i = n - 1; i > froze; i--) {
472 c->
sample1 = nodes[0]->sample1;
473 c->
sample2 = nodes[0]->sample2;
475 c->
step = nodes[0]->step;
476 c->
idelta = nodes[0]->step;
482 int n, i, ch, st, pkt_size, ret;
489 samples = (
const int16_t *)frame->
data[0];
508 for (ch = 0; ch < avctx->
channels; ch++) {
521 for (ch = 0; ch < avctx->
channels; ch++) {
523 buf + ch * blocks * 8, &c->
status[ch],
526 for (i = 0; i < blocks; i++) {
527 for (ch = 0; ch < avctx->
channels; ch++) {
528 uint8_t *buf1 = buf + ch * blocks * 8 + i * 8;
529 for (j = 0; j < 8; j += 2)
530 *dst++ = buf1[j] | (buf1[j + 1] << 4);
535 for (i = 0; i < blocks; i++) {
536 for (ch = 0; ch < avctx->
channels; ch++) {
538 const int16_t *smp = &samples_p[ch][1 + i * 8];
539 for (j = 0; j < 8; j += 2) {
554 for (ch = 0; ch < avctx->
channels; ch++) {
562 for (i = 0; i < 64; i++)
565 for (i = 0; i < 64; i += 2) {
589 for (i = 0; i < avctx->
channels; i++) {
603 buf + n, &c->
status[1], n,
605 for (i = 0; i < n; i++) {
617 samples[2 * i + 1]));
624 for (i = 0; i < avctx->
channels; i++) {
630 for (i = 0; i < avctx->
channels; i++) {
635 for (i = 0; i < avctx->
channels; i++)
641 for (i = 0; i < avctx->
channels; i++)
650 for (i = 0; i < n; i += 2)
651 *dst++ = (buf[i] << 4) | buf[i + 1];
657 for (i = 0; i < n; i++)
658 *dst++ = (buf[i] << 4) | buf[n + i];
662 for (i = 7 * avctx->
channels; i < avctx->block_align; i++) {
678 for (i = 0; i < n; i += 2)
679 *dst++ = buf[i] | (buf[i + 1] << 4);
685 for (i = 0; i < n; i++)
686 *dst++ = buf[i] | (buf[n + i] << 4);
690 for (n *= avctx->
channels; n > 0; n--) {
716 #define ADPCM_ENCODER(id_, name_, sample_fmts_, long_name_) \
717 AVCodec ff_ ## name_ ## _encoder = { \
719 .type = AVMEDIA_TYPE_AUDIO, \
721 .priv_data_size = sizeof(ADPCMEncodeContext), \
722 .init = adpcm_encode_init, \
723 .encode2 = adpcm_encode_frame, \
724 .close = adpcm_encode_close, \
725 .sample_fmts = sample_fmts_, \
726 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \