81 { -1, -1, -1, -1, 2, 4, 6, 8 },
82 { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
95 unsigned int min_channels = 1;
96 unsigned int max_channels = 2;
172 step_index = av_clip(step_index, 0, 88);
179 diff = ((2 * delta + 1) * step) >>
shift;
181 if (sign) predictor -=
diff;
182 else predictor +=
diff;
198 step_index = av_clip(step_index, 0, 88);
201 if (nibble & 4) diff += step;
202 if (nibble & 2) diff += step >> 1;
203 if (nibble & 1) diff += step >> 2;
221 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->
idelta;
224 c->
sample1 = av_clip_int16(predictor);
237 step_index = av_clip(step_index, 0, 48);
241 diff = ((2 * delta + 1) * step) >> 3;
243 if (sign) predictor -=
diff;
244 else predictor +=
diff;
246 c->
predictor = av_clip(predictor, -2048, 2047);
262 diff = ((2 * delta + 1) * c->
step) >> 3;
268 c->
step = av_clip(new_step, 511, 32767);
277 sign = nibble & (1<<(size-1));
278 delta = nibble & ((1<<(size-1))-1);
285 if (delta >= (2*size - 3) && c->
step < 3)
287 else if (delta == 0 && c->
step > 0)
303 c->
step = av_clip(c->
step, 127, 24567);
316 out0 += sample_offset;
320 out1 += sample_offset;
323 shift = 12 - (in[4+i*2] & 15);
324 filter = in[4+i*2] >> 4;
339 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
341 s_1 = av_clip_int16(s);
352 shift = 12 - (in[5+i*2] & 15);
353 filter = in[5+i*2] >> 4;
366 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
368 s_1 = av_clip_int16(s);
380 out0 += 28 * (3 - channels);
381 out1 += 28 * (3 - channels);
392 int k0, signmask, nb_bits, count;
393 int size = buf_size*8;
401 k0 = 1 << (nb_bits-2);
402 signmask = 1 << (nb_bits-1);
405 for (i = 0; i < avctx->
channels; i++) {
413 for (i = 0; i < avctx->
channels; i++) {
428 if (delta & signmask)
456 int buf_size,
int *coded_samples,
int *approx_nb_samples)
461 int has_coded_samples = 0;
465 *approx_nb_samples = 0;
473 if (buf_size < 76 * ch)
478 if (buf_size < 34 * ch)
489 nb_samples = buf_size * 2 / ch;
504 return (buf_size - header_size) * 2 / ch;
509 has_coded_samples = 1;
510 *coded_samples = bytestream2_get_le32(gb);
511 *coded_samples -= *coded_samples % 28;
512 nb_samples = (buf_size - 12) / 30 * 28;
515 has_coded_samples = 1;
516 *coded_samples = bytestream2_get_le32(gb);
517 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
520 nb_samples = (buf_size - ch) / ch * 2;
527 has_coded_samples = 1;
530 header_size = 4 + 9 * ch;
531 *coded_samples = bytestream2_get_le32(gb);
534 header_size = 4 + 5 * ch;
535 *coded_samples = bytestream2_get_le32(gb);
536 *approx_nb_samples = 1;
539 header_size = 4 + 5 * ch;
540 *coded_samples = bytestream2_get_be32(gb);
541 *approx_nb_samples = 1;
544 *coded_samples -= *coded_samples % 28;
545 nb_samples = (buf_size - header_size) * 2 / ch;
546 nb_samples -= nb_samples % 28;
551 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
556 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
561 nb_samples = 1 + (buf_size - 4 * ch) / (4 * ch) * 8;
566 nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch;
572 int samples_per_byte;
582 nb_samples += buf_size * samples_per_byte / ch;
587 int buf_bits = buf_size * 8 - 2;
588 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
589 int block_hdr_size = 22 * ch;
590 int block_size = block_hdr_size + nbits * ch * 4095;
591 int nblocks = buf_bits / block_size;
592 int bits_left = buf_bits - nblocks * block_size;
593 nb_samples = nblocks * 4096;
594 if (bits_left >= block_hdr_size)
595 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
599 has_coded_samples = 1;
601 *coded_samples = bytestream2_get_be32(gb);
602 *coded_samples -= *coded_samples % 14;
603 nb_samples = (buf_size - (8 + 36 * ch)) / (8 * ch) * 14;
606 nb_samples = buf_size / (9 * ch) * 16;
609 nb_samples = (buf_size / 128) * 224 / ch;
614 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
621 int *got_frame_ptr,
AVPacket *avpkt)
625 int buf_size = avpkt->
size;
628 int n,
m, channel, i;
633 int nb_samples, coded_samples, approx_nb_samples, ret;
637 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
638 if (nb_samples <= 0) {
649 samples = (
short *)frame->
data[0];
655 if (!approx_nb_samples && coded_samples != nb_samples)
657 frame->
nb_samples = nb_samples = coded_samples;
666 for (channel = 0; channel < avctx->
channels; channel++) {
669 cs = &(c->
status[channel]);
673 predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
674 step_index = predictor & 0x7F;
695 samples = samples_p[channel];
697 for (m = 0; m < 64; m += 2) {
698 int byte = bytestream2_get_byteu(&gb);
717 for (n = 0; n < (nb_samples - 1) / 8; n++) {
718 for (i = 0; i < avctx->
channels; i++) {
720 samples = &samples_p[i][1 + n * 8];
721 for (m = 0; m < 8; m += 2) {
722 int v = bytestream2_get_byteu(&gb);
730 for (i = 0; i < avctx->
channels; i++)
733 for (i = 0; i < avctx->
channels; i++) {
742 for (i = 0; i < avctx->
channels; i++) {
743 samples = (int16_t *)frame->
data[i];
745 for (n = nb_samples >> 1; n > 0; n--) {
746 int v = bytestream2_get_byteu(&gb);
756 block_predictor = bytestream2_get_byteu(&gb);
757 if (block_predictor > 6) {
765 block_predictor = bytestream2_get_byteu(&gb);
766 if (block_predictor > 6) {
788 for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
789 int byte = bytestream2_get_byteu(&gb);
796 for (channel = 0; channel < avctx->
channels; channel++) {
806 for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
807 int v = bytestream2_get_byteu(&gb);
816 int decode_top_nibble_next = 0;
834 #define DK3_GET_NEXT_NIBBLE() \
835 if (decode_top_nibble_next) { \
836 nibble = last_byte >> 4; \
837 decode_top_nibble_next = 0; \
839 last_byte = bytestream2_get_byteu(&gb); \
840 nibble = last_byte & 0x0F; \
841 decode_top_nibble_next = 1; \
844 while (samples < samples_end) {
877 for (channel = 0; channel < avctx->
channels; channel++) {
888 for (n = nb_samples >> (1 - st); n > 0; n--) {
890 int v = bytestream2_get_byteu(&gb);
905 int v = bytestream2_get_byteu(&gb);
912 int v = bytestream2_get_byteu(&gb);
919 for (channel = 0; channel < avctx->
channels; channel++) {
920 int16_t *smp = samples_p[channel];
922 for (n = nb_samples / 2; n > 0; n--) {
923 int v = bytestream2_get_byteu(&gb);
929 for (n = nb_samples / 2; n > 0; n--) {
930 for (channel = 0; channel < avctx->
channels; channel++) {
931 int v = bytestream2_get_byteu(&gb);
942 int16_t *out0 = samples_p[0];
943 int16_t *out1 = samples_p[1];
944 int samples_per_block = 28 * (3 - avctx->
channels) * 4;
945 int sample_offset = 0;
949 avctx->
channels, sample_offset)) < 0)
952 sample_offset += samples_per_block;
957 for (i=0; i<=st; i++) {
965 for (i=0; i<=st; i++)
968 for (n = nb_samples >> (1 - st); n > 0; n--) {
969 int byte = bytestream2_get_byteu(&gb);
975 for (n = nb_samples >> (1 - st); n > 0; n--) {
976 int byte = bytestream2_get_byteu(&gb);
983 int previous_left_sample, previous_right_sample;
984 int current_left_sample, current_right_sample;
985 int next_left_sample, next_right_sample;
986 int coeff1l, coeff2l, coeff1r, coeff2r;
987 int shift_left, shift_right;
995 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
996 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
997 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
998 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1000 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1001 int byte = bytestream2_get_byteu(&gb);
1007 byte = bytestream2_get_byteu(&gb);
1008 shift_left = 20 - (byte >> 4);
1009 shift_right = 20 - (byte & 0x0F);
1011 for (count2 = 0; count2 < 28; count2++) {
1012 byte = bytestream2_get_byteu(&gb);
1013 next_left_sample =
sign_extend(byte >> 4, 4) << shift_left;
1014 next_right_sample =
sign_extend(byte, 4) << shift_right;
1016 next_left_sample = (next_left_sample +
1017 (current_left_sample * coeff1l) +
1018 (previous_left_sample * coeff2l) + 0x80) >> 8;
1019 next_right_sample = (next_right_sample +
1020 (current_right_sample * coeff1r) +
1021 (previous_right_sample * coeff2r) + 0x80) >> 8;
1023 previous_left_sample = current_left_sample;
1024 current_left_sample = av_clip_int16(next_left_sample);
1025 previous_right_sample = current_right_sample;
1026 current_right_sample = av_clip_int16(next_right_sample);
1027 *samples++ = current_left_sample;
1028 *samples++ = current_right_sample;
1040 for(channel = 0; channel < avctx->
channels; channel++) {
1041 int byte = bytestream2_get_byteu(&gb);
1044 shift[channel] = 20 - (byte & 0x0F);
1046 for (count1 = 0; count1 < nb_samples / 2; count1++) {
1049 byte[0] = bytestream2_get_byteu(&gb);
1050 if (st) byte[1] = bytestream2_get_byteu(&gb);
1051 for(i = 4; i >= 0; i-=4) {
1052 for(channel = 0; channel < avctx->
channels; channel++) {
1056 c->
status[channel].
sample2 * coeff[channel][1] + 0x80) >> 8;
1074 int previous_sample, current_sample, next_sample;
1077 unsigned int channel;
1082 for (channel=0; channel<avctx->
channels; channel++)
1083 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1084 bytestream2_get_le32(&gb)) +
1087 for (channel=0; channel<avctx->
channels; channel++) {
1089 samplesC = samples_p[channel];
1092 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1093 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1099 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1100 int byte = bytestream2_get_byte(&gb);
1102 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1103 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1105 for (count2=0; count2<28; count2++)
1106 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1110 shift = 20 - (byte & 0x0F);
1112 for (count2=0; count2<28; count2++) {
1116 byte = bytestream2_get_byte(&gb);
1120 next_sample += (current_sample * coeff1) +
1121 (previous_sample * coeff2);
1122 next_sample = av_clip_int16(next_sample >> 8);
1124 previous_sample = current_sample;
1125 current_sample = next_sample;
1126 *samplesC++ = current_sample;
1132 }
else if (count != count1) {
1134 count =
FFMAX(count, count1);
1148 for (channel=0; channel<avctx->
channels; channel++) {
1150 int16_t *s = samples_p[channel];
1151 for (n = 0; n < 4; n++, s += 32) {
1152 int val =
sign_extend(bytestream2_get_le16u(&gb), 16);
1157 val =
sign_extend(bytestream2_get_le16u(&gb), 16);
1158 shift[n] = 20 - (val & 0x0F);
1162 for (m=2; m<32; m+=2) {
1163 s = &samples_p[channel][
m];
1164 for (n = 0; n < 4; n++, s += 32) {
1166 int byte = bytestream2_get_byteu(&gb);
1169 pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
1170 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
1173 pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
1174 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
1189 for (n = nb_samples >> (1 - st); n > 0; n--) {
1190 int v = bytestream2_get_byteu(&gb);
1197 for (i = 0; i < avctx->
channels; i++) {
1208 for (n = nb_samples >> (1 - st); n > 0; n--) {
1209 int v = bytestream2_get_byteu(&gb);
1216 for (n = nb_samples >> (1 - st); n > 0; n--) {
1217 int v = bytestream2_get_byteu(&gb);
1227 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1229 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1234 for (n = nb_samples >> (1 - st); n > 0; n--) {
1235 int byte = bytestream2_get_byteu(&gb);
1242 for (n = nb_samples / 3; n > 0; n--) {
1243 int byte = bytestream2_get_byteu(&gb);
1247 (byte >> 2) & 0x07, 3, 0);
1252 for (n = nb_samples >> (2 - st); n > 0; n--) {
1253 int byte = bytestream2_get_byteu(&gb);
1257 (byte >> 4) & 0x03, 2, 2);
1259 (byte >> 2) & 0x03, 2, 2);
1270 for (n = nb_samples >> (1 - st); n > 0; n--) {
1271 int v = bytestream2_get_byteu(&gb);
1278 int samples_per_block;
1282 samples_per_block = avctx->
extradata[0] / 16;
1283 blocks = nb_samples / avctx->
extradata[0];
1285 samples_per_block = nb_samples / 16;
1289 for (m = 0; m < blocks; m++) {
1290 for (channel = 0; channel < avctx->
channels; channel++) {
1294 samples = samples_p[channel] + m * 16;
1296 for (i = 0; i < samples_per_block; i++) {
1297 int byte = bytestream2_get_byteu(&gb);
1298 int scale = 1 << (byte >> 4);
1299 int index = byte & 0xf;
1304 for (n = 0; n < 16; n++) {
1310 byte = bytestream2_get_byteu(&gb);
1314 sampledat = ((prev1 * factor1 + prev2 * factor2) +
1315 ((sampledat * scale) << 11)) >> 11;
1316 *samples = av_clip_int16(sampledat);
1334 for (i = 0; i < avctx->
channels; i++)
1335 for (n = 0; n < 16; n++)
1336 table[i][n] =
sign_extend(bytestream2_get_be16u(&gb), 16);
1339 for (i = 0; i < avctx->
channels; i++) {
1344 for (ch = 0; ch < avctx->
channels; ch++) {
1345 samples = samples_p[ch];
1348 for (i = 0; i < nb_samples / 14; i++) {
1349 int byte = bytestream2_get_byteu(&gb);
1350 int index = (byte >> 4) & 7;
1351 unsigned int exp = byte & 0x0F;
1352 int factor1 = table[ch][index * 2];
1353 int factor2 = table[ch][index * 2 + 1];
1356 for (n = 0; n < 14; n++) {
1362 byte = bytestream2_get_byteu(&gb);
1367 + c->
status[ch].
sample2 * factor2) >> 11) + (sampledat << exp);
1368 *samples = av_clip_int16(sampledat);
1400 #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \
1401 AVCodec ff_ ## name_ ## _decoder = { \
1403 .type = AVMEDIA_TYPE_AUDIO, \
1405 .priv_data_size = sizeof(ADPCMDecodeContext), \
1406 .init = adpcm_decode_init, \
1407 .decode = adpcm_decode_frame, \
1408 .capabilities = CODEC_CAP_DR1, \
1409 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
1410 .sample_fmts = sample_fmts_, \