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 }
96 unsigned int min_channels = 1;
97 unsigned int max_channels = 2;
176 step_index = av_clip(step_index, 0, 88);
183 diff = ((2 * delta + 1) * step) >>
shift;
185 if (sign) predictor -=
diff;
186 else predictor +=
diff;
202 step_index = av_clip(step_index, 0, 88);
205 if (nibble & 4) diff += step;
206 if (nibble & 2) diff += step >> 1;
207 if (nibble & 1) diff += step >> 2;
225 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->
idelta;
228 c->
sample1 = av_clip_int16(predictor);
241 step_index = av_clip(step_index, 0, 48);
245 diff = ((2 * delta + 1) * step) >> 3;
247 if (sign) predictor -=
diff;
248 else predictor +=
diff;
250 c->
predictor = av_clip(predictor, -2048, 2047);
266 diff = ((2 * delta + 1) * c->
step) >> 3;
272 c->
step = av_clip(new_step, 511, 32767);
281 sign = nibble & (1<<(size-1));
282 delta = nibble & ((1<<(size-1))-1);
289 if (delta >= (2*size - 3) && c->
step < 3)
291 else if (delta == 0 && c->
step > 0)
307 c->
step = av_clip(c->
step, 127, 24567);
320 out0 += sample_offset;
324 out1 += sample_offset;
327 shift = 12 - (in[4+i*2] & 15);
328 filter = in[4+i*2] >> 4;
343 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
345 s_1 = av_clip_int16(s);
356 shift = 12 - (in[5+i*2] & 15);
357 filter = in[5+i*2] >> 4;
370 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
372 s_1 = av_clip_int16(s);
384 out0 += 28 * (3 - channels);
385 out1 += 28 * (3 - channels);
396 int k0, signmask, nb_bits, count;
397 int size = buf_size*8;
405 k0 = 1 << (nb_bits-2);
406 signmask = 1 << (nb_bits-1);
409 for (i = 0; i < avctx->
channels; i++) {
417 for (i = 0; i < avctx->
channels; i++) {
432 if (delta & signmask)
458 int buf_size,
int *coded_samples)
463 int has_coded_samples = 0;
474 if (buf_size < 76 * ch)
479 if (buf_size < 34 * ch)
490 nb_samples = buf_size * 2 / ch;
505 return (buf_size - header_size) * 2 / ch;
510 has_coded_samples = 1;
511 *coded_samples = bytestream2_get_le32(gb);
512 *coded_samples -= *coded_samples % 28;
513 nb_samples = (buf_size - 12) / 30 * 28;
516 has_coded_samples = 1;
517 *coded_samples = bytestream2_get_le32(gb);
518 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
521 nb_samples = (buf_size - ch) / ch * 2;
528 has_coded_samples = 1;
531 header_size = 4 + 9 * ch;
532 *coded_samples = bytestream2_get_le32(gb);
535 header_size = 4 + 5 * ch;
536 *coded_samples = bytestream2_get_le32(gb);
539 header_size = 4 + 5 * ch;
540 *coded_samples = bytestream2_get_be32(gb);
543 *coded_samples -= *coded_samples % 28;
544 nb_samples = (buf_size - header_size) * 2 / ch;
545 nb_samples -= nb_samples % 28;
550 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
555 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
560 nb_samples = 1 + (buf_size - 4 * ch) / (4 * ch) * 8;
565 nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch;
571 int samples_per_byte;
581 nb_samples += buf_size * samples_per_byte / ch;
586 int buf_bits = buf_size * 8 - 2;
587 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
588 int block_hdr_size = 22 * ch;
589 int block_size = block_hdr_size + nbits * ch * 4095;
590 int nblocks = buf_bits / block_size;
591 int bits_left = buf_bits - nblocks * block_size;
592 nb_samples = nblocks * 4096;
593 if (bits_left >= block_hdr_size)
594 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
598 has_coded_samples = 1;
600 *coded_samples = bytestream2_get_be32(gb);
601 *coded_samples -= *coded_samples % 14;
602 nb_samples = (buf_size - (8 + 36 * ch)) / (8 * ch) * 14;
605 nb_samples = buf_size / (9 * ch) * 16;
608 nb_samples = (buf_size / 128) * 224 / ch;
613 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
620 int *got_frame_ptr,
AVPacket *avpkt)
623 int buf_size = avpkt->
size;
626 int n,
m, channel, i;
635 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples);
636 if (nb_samples <= 0) {
653 if (coded_samples != nb_samples)
664 for (channel = 0; channel < avctx->
channels; channel++) {
667 cs = &(c->
status[channel]);
671 predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
672 step_index = predictor & 0x7F;
693 samples = samples_p[channel];
695 for (m = 0; m < 64; m += 2) {
696 int byte = bytestream2_get_byteu(&gb);
715 for (n = 0; n < (nb_samples - 1) / 8; n++) {
716 for (i = 0; i < avctx->
channels; i++) {
718 samples = &samples_p[i][1 + n * 8];
719 for (m = 0; m < 8; m += 2) {
720 int v = bytestream2_get_byteu(&gb);
728 for (i = 0; i < avctx->
channels; i++)
731 for (i = 0; i < avctx->
channels; i++) {
740 for (i = 0; i < avctx->
channels; i++) {
743 for (n = nb_samples >> 1; n > 0; n--) {
744 int v = bytestream2_get_byteu(&gb);
754 block_predictor = bytestream2_get_byteu(&gb);
755 if (block_predictor > 6) {
763 block_predictor = bytestream2_get_byteu(&gb);
764 if (block_predictor > 6) {
786 for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
787 int byte = bytestream2_get_byteu(&gb);
794 for (channel = 0; channel < avctx->
channels; channel++) {
804 for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
805 int v = bytestream2_get_byteu(&gb);
814 int decode_top_nibble_next = 0;
832 #define DK3_GET_NEXT_NIBBLE() \
833 if (decode_top_nibble_next) { \
834 nibble = last_byte >> 4; \
835 decode_top_nibble_next = 0; \
837 last_byte = bytestream2_get_byteu(&gb); \
838 nibble = last_byte & 0x0F; \
839 decode_top_nibble_next = 1; \
842 while (samples < samples_end) {
872 for (channel = 0; channel < avctx->
channels; channel++) {
883 for (n = nb_samples >> (1 - st); n > 0; n--) {
885 int v = bytestream2_get_byteu(&gb);
900 int v = bytestream2_get_byteu(&gb);
907 int v = bytestream2_get_byteu(&gb);
914 for (channel = 0; channel < avctx->
channels; channel++) {
915 int16_t *smp = samples_p[channel];
917 for (n = nb_samples / 2; n > 0; n--) {
918 int v = bytestream2_get_byteu(&gb);
924 for (n = nb_samples / 2; n > 0; n--) {
925 for (channel = 0; channel < avctx->
channels; channel++) {
926 int v = bytestream2_get_byteu(&gb);
937 int16_t *out0 = samples_p[0];
938 int16_t *out1 = samples_p[1];
939 int samples_per_block = 28 * (3 - avctx->
channels) * 4;
940 int sample_offset = 0;
944 avctx->
channels, sample_offset)) < 0)
947 sample_offset += samples_per_block;
952 for (i=0; i<=st; i++) {
960 for (i=0; i<=st; i++)
963 for (n = nb_samples >> (1 - st); n > 0; n--) {
964 int byte = bytestream2_get_byteu(&gb);
970 for (n = nb_samples >> (1 - st); n > 0; n--) {
971 int byte = bytestream2_get_byteu(&gb);
978 int previous_left_sample, previous_right_sample;
979 int current_left_sample, current_right_sample;
980 int next_left_sample, next_right_sample;
981 int coeff1l, coeff2l, coeff1r, coeff2r;
982 int shift_left, shift_right;
990 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
991 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
992 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
993 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
995 for (count1 = 0; count1 < nb_samples / 28; count1++) {
996 int byte = bytestream2_get_byteu(&gb);
1002 byte = bytestream2_get_byteu(&gb);
1003 shift_left = 20 - (byte >> 4);
1004 shift_right = 20 - (byte & 0x0F);
1006 for (count2 = 0; count2 < 28; count2++) {
1007 byte = bytestream2_get_byteu(&gb);
1008 next_left_sample =
sign_extend(byte >> 4, 4) << shift_left;
1009 next_right_sample =
sign_extend(byte, 4) << shift_right;
1011 next_left_sample = (next_left_sample +
1012 (current_left_sample * coeff1l) +
1013 (previous_left_sample * coeff2l) + 0x80) >> 8;
1014 next_right_sample = (next_right_sample +
1015 (current_right_sample * coeff1r) +
1016 (previous_right_sample * coeff2r) + 0x80) >> 8;
1018 previous_left_sample = current_left_sample;
1019 current_left_sample = av_clip_int16(next_left_sample);
1020 previous_right_sample = current_right_sample;
1021 current_right_sample = av_clip_int16(next_right_sample);
1022 *samples++ = current_left_sample;
1023 *samples++ = current_right_sample;
1035 for(channel = 0; channel < avctx->
channels; channel++) {
1036 int byte = bytestream2_get_byteu(&gb);
1039 shift[channel] = 20 - (byte & 0x0F);
1041 for (count1 = 0; count1 < nb_samples / 2; count1++) {
1044 byte[0] = bytestream2_get_byteu(&gb);
1045 if (st) byte[1] = bytestream2_get_byteu(&gb);
1046 for(i = 4; i >= 0; i-=4) {
1047 for(channel = 0; channel < avctx->
channels; channel++) {
1051 c->
status[channel].
sample2 * coeff[channel][1] + 0x80) >> 8;
1069 int previous_sample, current_sample, next_sample;
1072 unsigned int channel;
1077 for (channel=0; channel<avctx->
channels; channel++)
1078 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1079 bytestream2_get_le32(&gb)) +
1082 for (channel=0; channel<avctx->
channels; channel++) {
1084 samplesC = samples_p[channel];
1087 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1088 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1094 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1095 int byte = bytestream2_get_byte(&gb);
1097 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1098 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1100 for (count2=0; count2<28; count2++)
1101 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1105 shift = 20 - (byte & 0x0F);
1107 for (count2=0; count2<28; count2++) {
1111 byte = bytestream2_get_byte(&gb);
1115 next_sample += (current_sample * coeff1) +
1116 (previous_sample * coeff2);
1117 next_sample = av_clip_int16(next_sample >> 8);
1119 previous_sample = current_sample;
1120 current_sample = next_sample;
1121 *samplesC++ = current_sample;
1127 }
else if (count != count1) {
1129 count =
FFMAX(count, count1);
1143 for (channel=0; channel<avctx->
channels; channel++) {
1145 int16_t *s = samples_p[channel];
1146 for (n = 0; n < 4; n++, s += 32) {
1147 int val =
sign_extend(bytestream2_get_le16u(&gb), 16);
1152 val =
sign_extend(bytestream2_get_le16u(&gb), 16);
1153 shift[n] = 20 - (val & 0x0F);
1157 for (m=2; m<32; m+=2) {
1158 s = &samples_p[channel][
m];
1159 for (n = 0; n < 4; n++, s += 32) {
1161 int byte = bytestream2_get_byteu(&gb);
1164 pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
1165 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
1168 pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
1169 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
1184 for (n = nb_samples >> (1 - st); n > 0; n--) {
1185 int v = bytestream2_get_byteu(&gb);
1192 for (i = 0; i < avctx->
channels; i++) {
1203 for (n = nb_samples >> (1 - st); n > 0; n--) {
1204 int v = bytestream2_get_byteu(&gb);
1211 for (n = nb_samples >> (1 - st); n > 0; n--) {
1212 int v = bytestream2_get_byteu(&gb);
1222 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1224 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1229 for (n = nb_samples >> (1 - st); n > 0; n--) {
1230 int byte = bytestream2_get_byteu(&gb);
1237 for (n = nb_samples / 3; n > 0; n--) {
1238 int byte = bytestream2_get_byteu(&gb);
1242 (byte >> 2) & 0x07, 3, 0);
1247 for (n = nb_samples >> (2 - st); n > 0; n--) {
1248 int byte = bytestream2_get_byteu(&gb);
1252 (byte >> 4) & 0x03, 2, 2);
1254 (byte >> 2) & 0x03, 2, 2);
1265 for (n = nb_samples >> (1 - st); n > 0; n--) {
1266 int v = bytestream2_get_byteu(&gb);
1273 int samples_per_block;
1277 samples_per_block = avctx->
extradata[0] / 16;
1278 blocks = nb_samples / avctx->
extradata[0];
1280 samples_per_block = nb_samples / 16;
1284 for (m = 0; m < blocks; m++) {
1285 for (channel = 0; channel < avctx->
channels; channel++) {
1289 samples = samples_p[channel] + m * 16;
1291 for (i = 0; i < samples_per_block; i++) {
1292 int byte = bytestream2_get_byteu(&gb);
1293 int scale = 1 << (byte >> 4);
1294 int index = byte & 0xf;
1299 for (n = 0; n < 16; n++) {
1305 byte = bytestream2_get_byteu(&gb);
1309 sampledat = ((prev1 * factor1 + prev2 * factor2) +
1310 ((sampledat * scale) << 11)) >> 11;
1311 *samples = av_clip_int16(sampledat);
1329 for (i = 0; i < avctx->
channels; i++)
1330 for (n = 0; n < 16; n++)
1331 table[i][n] =
sign_extend(bytestream2_get_be16u(&gb), 16);
1334 for (i = 0; i < avctx->
channels; i++) {
1339 for (ch = 0; ch < avctx->
channels; ch++) {
1340 samples = samples_p[ch];
1343 for (i = 0; i < nb_samples / 14; i++) {
1344 int byte = bytestream2_get_byteu(&gb);
1345 int index = (byte >> 4) & 7;
1346 unsigned int exp = byte & 0x0F;
1347 int factor1 = table[ch][index * 2];
1348 int factor2 = table[ch][index * 2 + 1];
1351 for (n = 0; n < 14; n++) {
1357 byte = bytestream2_get_byteu(&gb);
1362 + c->
status[ch].
sample2 * factor2) >> 11) + (sampledat << exp);
1363 *samples = av_clip_int16(sampledat);
1396 #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \
1397 AVCodec ff_ ## name_ ## _decoder = { \
1399 .type = AVMEDIA_TYPE_AUDIO, \
1401 .priv_data_size = sizeof(ADPCMDecodeContext), \
1402 .init = adpcm_decode_init, \
1403 .decode = adpcm_decode_frame, \
1404 .capabilities = CODEC_CAP_DR1, \
1405 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
1406 .sample_fmts = sample_fmts_, \