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)
454 int buf_size,
int *coded_samples)
459 int has_coded_samples = 0;
470 if (buf_size < 76 * ch)
475 if (buf_size < 34 * ch)
486 nb_samples = buf_size * 2 / ch;
501 return (buf_size - header_size) * 2 / ch;
506 has_coded_samples = 1;
507 *coded_samples = bytestream2_get_le32(gb);
508 *coded_samples -= *coded_samples % 28;
509 nb_samples = (buf_size - 12) / 30 * 28;
512 has_coded_samples = 1;
513 *coded_samples = bytestream2_get_le32(gb);
514 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
517 nb_samples = (buf_size - ch) / ch * 2;
524 has_coded_samples = 1;
527 header_size = 4 + 9 * ch;
528 *coded_samples = bytestream2_get_le32(gb);
531 header_size = 4 + 5 * ch;
532 *coded_samples = bytestream2_get_le32(gb);
535 header_size = 4 + 5 * ch;
536 *coded_samples = bytestream2_get_be32(gb);
539 *coded_samples -= *coded_samples % 28;
540 nb_samples = (buf_size - header_size) * 2 / ch;
541 nb_samples -= nb_samples % 28;
546 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
551 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
556 nb_samples = 1 + (buf_size - 4 * ch) / (4 * ch) * 8;
561 nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch;
567 int samples_per_byte;
577 nb_samples += buf_size * samples_per_byte / ch;
582 int buf_bits = buf_size * 8 - 2;
583 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
584 int block_hdr_size = 22 * ch;
585 int block_size = block_hdr_size + nbits * ch * 4095;
586 int nblocks = buf_bits / block_size;
587 int bits_left = buf_bits - nblocks * block_size;
588 nb_samples = nblocks * 4096;
589 if (bits_left >= block_hdr_size)
590 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
594 has_coded_samples = 1;
596 *coded_samples = bytestream2_get_be32(gb);
597 *coded_samples -= *coded_samples % 14;
598 nb_samples = (buf_size - (8 + 36 * ch)) / (8 * ch) * 14;
601 nb_samples = buf_size / (9 * ch) * 16;
604 nb_samples = (buf_size / 128) * 224 / ch;
609 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
616 int *got_frame_ptr,
AVPacket *avpkt)
620 int buf_size = avpkt->
size;
623 int n,
m, channel, i;
632 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples);
633 if (nb_samples <= 0) {
644 samples = (
short *)frame->
data[0];
650 if (coded_samples != nb_samples)
652 frame->
nb_samples = nb_samples = coded_samples;
661 for (channel = 0; channel < avctx->
channels; channel++) {
664 cs = &(c->
status[channel]);
668 predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
669 step_index = predictor & 0x7F;
690 samples = samples_p[channel];
692 for (m = 0; m < 64; m += 2) {
693 int byte = bytestream2_get_byteu(&gb);
712 for (n = 0; n < (nb_samples - 1) / 8; n++) {
713 for (i = 0; i < avctx->
channels; i++) {
715 samples = &samples_p[i][1 + n * 8];
716 for (m = 0; m < 8; m += 2) {
717 int v = bytestream2_get_byteu(&gb);
725 for (i = 0; i < avctx->
channels; i++)
728 for (i = 0; i < avctx->
channels; i++) {
737 for (i = 0; i < avctx->
channels; i++) {
738 samples = (int16_t *)frame->
data[i];
740 for (n = nb_samples >> 1; n > 0; n--) {
741 int v = bytestream2_get_byteu(&gb);
751 block_predictor = bytestream2_get_byteu(&gb);
752 if (block_predictor > 6) {
760 block_predictor = bytestream2_get_byteu(&gb);
761 if (block_predictor > 6) {
783 for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
784 int byte = bytestream2_get_byteu(&gb);
791 for (channel = 0; channel < avctx->
channels; channel++) {
801 for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
802 int v = bytestream2_get_byteu(&gb);
811 int decode_top_nibble_next = 0;
829 #define DK3_GET_NEXT_NIBBLE() \
830 if (decode_top_nibble_next) { \
831 nibble = last_byte >> 4; \
832 decode_top_nibble_next = 0; \
834 last_byte = bytestream2_get_byteu(&gb); \
835 nibble = last_byte & 0x0F; \
836 decode_top_nibble_next = 1; \
839 while (samples < samples_end) {
869 for (channel = 0; channel < avctx->
channels; channel++) {
880 for (n = nb_samples >> (1 - st); n > 0; n--) {
882 int v = bytestream2_get_byteu(&gb);
897 int v = bytestream2_get_byteu(&gb);
904 int v = bytestream2_get_byteu(&gb);
911 for (channel = 0; channel < avctx->
channels; channel++) {
912 int16_t *smp = samples_p[channel];
914 for (n = nb_samples / 2; n > 0; n--) {
915 int v = bytestream2_get_byteu(&gb);
921 for (n = nb_samples / 2; n > 0; n--) {
922 for (channel = 0; channel < avctx->
channels; channel++) {
923 int v = bytestream2_get_byteu(&gb);
934 int16_t *out0 = samples_p[0];
935 int16_t *out1 = samples_p[1];
936 int samples_per_block = 28 * (3 - avctx->
channels) * 4;
937 int sample_offset = 0;
941 avctx->
channels, sample_offset)) < 0)
944 sample_offset += samples_per_block;
949 for (i=0; i<=st; i++) {
957 for (i=0; i<=st; i++)
960 for (n = nb_samples >> (1 - st); n > 0; n--) {
961 int byte = bytestream2_get_byteu(&gb);
967 for (n = nb_samples >> (1 - st); n > 0; n--) {
968 int byte = bytestream2_get_byteu(&gb);
975 int previous_left_sample, previous_right_sample;
976 int current_left_sample, current_right_sample;
977 int next_left_sample, next_right_sample;
978 int coeff1l, coeff2l, coeff1r, coeff2r;
979 int shift_left, shift_right;
987 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
988 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
989 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
990 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
992 for (count1 = 0; count1 < nb_samples / 28; count1++) {
993 int byte = bytestream2_get_byteu(&gb);
999 byte = bytestream2_get_byteu(&gb);
1000 shift_left = 20 - (byte >> 4);
1001 shift_right = 20 - (byte & 0x0F);
1003 for (count2 = 0; count2 < 28; count2++) {
1004 byte = bytestream2_get_byteu(&gb);
1005 next_left_sample =
sign_extend(byte >> 4, 4) << shift_left;
1006 next_right_sample =
sign_extend(byte, 4) << shift_right;
1008 next_left_sample = (next_left_sample +
1009 (current_left_sample * coeff1l) +
1010 (previous_left_sample * coeff2l) + 0x80) >> 8;
1011 next_right_sample = (next_right_sample +
1012 (current_right_sample * coeff1r) +
1013 (previous_right_sample * coeff2r) + 0x80) >> 8;
1015 previous_left_sample = current_left_sample;
1016 current_left_sample = av_clip_int16(next_left_sample);
1017 previous_right_sample = current_right_sample;
1018 current_right_sample = av_clip_int16(next_right_sample);
1019 *samples++ = current_left_sample;
1020 *samples++ = current_right_sample;
1032 for(channel = 0; channel < avctx->
channels; channel++) {
1033 int byte = bytestream2_get_byteu(&gb);
1036 shift[channel] = 20 - (byte & 0x0F);
1038 for (count1 = 0; count1 < nb_samples / 2; count1++) {
1041 byte[0] = bytestream2_get_byteu(&gb);
1042 if (st) byte[1] = bytestream2_get_byteu(&gb);
1043 for(i = 4; i >= 0; i-=4) {
1044 for(channel = 0; channel < avctx->
channels; channel++) {
1048 c->
status[channel].
sample2 * coeff[channel][1] + 0x80) >> 8;
1066 int previous_sample, current_sample, next_sample;
1069 unsigned int channel;
1074 for (channel=0; channel<avctx->
channels; channel++)
1075 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1076 bytestream2_get_le32(&gb)) +
1079 for (channel=0; channel<avctx->
channels; channel++) {
1081 samplesC = samples_p[channel];
1084 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1085 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1091 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1092 int byte = bytestream2_get_byte(&gb);
1094 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1095 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1097 for (count2=0; count2<28; count2++)
1098 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1102 shift = 20 - (byte & 0x0F);
1104 for (count2=0; count2<28; count2++) {
1108 byte = bytestream2_get_byte(&gb);
1112 next_sample += (current_sample * coeff1) +
1113 (previous_sample * coeff2);
1114 next_sample = av_clip_int16(next_sample >> 8);
1116 previous_sample = current_sample;
1117 current_sample = next_sample;
1118 *samplesC++ = current_sample;
1124 }
else if (count != count1) {
1126 count =
FFMAX(count, count1);
1140 for (channel=0; channel<avctx->
channels; channel++) {
1142 int16_t *s = samples_p[channel];
1143 for (n = 0; n < 4; n++, s += 32) {
1144 int val =
sign_extend(bytestream2_get_le16u(&gb), 16);
1149 val =
sign_extend(bytestream2_get_le16u(&gb), 16);
1150 shift[n] = 20 - (val & 0x0F);
1154 for (m=2; m<32; m+=2) {
1155 s = &samples_p[channel][
m];
1156 for (n = 0; n < 4; n++, s += 32) {
1158 int byte = bytestream2_get_byteu(&gb);
1161 pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
1162 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
1165 pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
1166 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
1181 for (n = nb_samples >> (1 - st); n > 0; n--) {
1182 int v = bytestream2_get_byteu(&gb);
1189 for (i = 0; i < avctx->
channels; i++) {
1200 for (n = nb_samples >> (1 - st); n > 0; n--) {
1201 int v = bytestream2_get_byteu(&gb);
1208 for (n = nb_samples >> (1 - st); n > 0; n--) {
1209 int v = bytestream2_get_byteu(&gb);
1219 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1221 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1226 for (n = nb_samples >> (1 - st); n > 0; n--) {
1227 int byte = bytestream2_get_byteu(&gb);
1234 for (n = nb_samples / 3; n > 0; n--) {
1235 int byte = bytestream2_get_byteu(&gb);
1239 (byte >> 2) & 0x07, 3, 0);
1244 for (n = nb_samples >> (2 - st); n > 0; n--) {
1245 int byte = bytestream2_get_byteu(&gb);
1249 (byte >> 4) & 0x03, 2, 2);
1251 (byte >> 2) & 0x03, 2, 2);
1262 for (n = nb_samples >> (1 - st); n > 0; n--) {
1263 int v = bytestream2_get_byteu(&gb);
1270 int samples_per_block;
1274 samples_per_block = avctx->
extradata[0] / 16;
1275 blocks = nb_samples / avctx->
extradata[0];
1277 samples_per_block = nb_samples / 16;
1281 for (m = 0; m < blocks; m++) {
1282 for (channel = 0; channel < avctx->
channels; channel++) {
1286 samples = samples_p[channel] + m * 16;
1288 for (i = 0; i < samples_per_block; i++) {
1289 int byte = bytestream2_get_byteu(&gb);
1290 int scale = 1 << (byte >> 4);
1291 int index = byte & 0xf;
1296 for (n = 0; n < 16; n++) {
1302 byte = bytestream2_get_byteu(&gb);
1306 sampledat = ((prev1 * factor1 + prev2 * factor2) +
1307 ((sampledat * scale) << 11)) >> 11;
1308 *samples = av_clip_int16(sampledat);
1326 for (i = 0; i < avctx->
channels; i++)
1327 for (n = 0; n < 16; n++)
1328 table[i][n] =
sign_extend(bytestream2_get_be16u(&gb), 16);
1331 for (i = 0; i < avctx->
channels; i++) {
1336 for (ch = 0; ch < avctx->
channels; ch++) {
1337 samples = samples_p[ch];
1340 for (i = 0; i < nb_samples / 14; i++) {
1341 int byte = bytestream2_get_byteu(&gb);
1342 int index = (byte >> 4) & 7;
1343 unsigned int exp = byte & 0x0F;
1344 int factor1 = table[ch][index * 2];
1345 int factor2 = table[ch][index * 2 + 1];
1348 for (n = 0; n < 14; n++) {
1354 byte = bytestream2_get_byteu(&gb);
1359 + c->
status[ch].
sample2 * factor2) >> 11) + (sampledat << exp);
1360 *samples = av_clip_int16(sampledat);
1392 #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \
1393 AVCodec ff_ ## name_ ## _decoder = { \
1395 .type = AVMEDIA_TYPE_AUDIO, \
1397 .priv_data_size = sizeof(ADPCMDecodeContext), \
1398 .init = adpcm_decode_init, \
1399 .decode = adpcm_decode_frame, \
1400 .capabilities = CODEC_CAP_DR1, \
1401 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
1402 .sample_fmts = sample_fmts_, \