80 { -1, -1, -1, -1, 2, 4, 6, 8 },
81 { -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;
192 step_index = av_clip(step_index, 0, 88);
199 diff = ((2 * delta + 1) * step) >>
shift;
201 if (sign) predictor -=
diff;
202 else predictor +=
diff;
212 int nibble, step_index, predictor, sign,
delta,
diff, step,
shift;
218 step_index = av_clip(step_index, 0, 88);
220 sign = nibble & (1 <<
shift);
221 delta = av_mod_uintp2(nibble, shift);
222 diff = ((2 * delta + 1) * step) >>
shift;
224 if (sign) predictor -=
diff;
225 else predictor +=
diff;
241 step_index = av_clip(step_index, 0, 88);
244 if (nibble & 4) diff += step;
245 if (nibble & 2) diff += step >> 1;
246 if (nibble & 1) diff += step >> 2;
264 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->
idelta;
267 c->
sample1 = av_clip_int16(predictor);
270 if (c->
idelta > INT_MAX/768) {
280 int step_index, predictor, sign,
delta,
diff, step;
284 step_index = av_clip(step_index, 0, 48);
288 diff = ((2 * delta + 1) * step) >> 3;
290 if (sign) predictor -=
diff;
291 else predictor +=
diff;
293 c->
predictor = av_clip_intp2(predictor, 11);
309 diff = ((2 * delta + 1) * c->
step) >> 3;
315 c->
step = av_clip(new_step, 511, 32767);
324 sign = nibble & (1<<(size-1));
325 delta = nibble & ((1<<(size-1))-1);
332 if (delta >= (2*size - 3) && c->
step < 3)
334 else if (delta == 0 && c->
step > 0)
350 c->
step = av_clip(c->
step, 127, 24576);
359 c->
step = av_clip_uintp2(c->
step, 5);
372 out0 += sample_offset;
376 out1 += sample_offset;
379 shift = 12 - (in[4+i*2] & 15);
380 filter = in[4+i*2] >> 4;
395 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
397 s_1 = av_clip_int16(s);
408 shift = 12 - (in[5+i*2] & 15);
409 filter = in[5+i*2] >> 4;
422 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
424 s_1 = av_clip_int16(s);
448 int k0, signmask, nb_bits,
count;
449 int size = buf_size*8;
457 k0 = 1 << (nb_bits-2);
458 signmask = 1 << (nb_bits-1);
461 for (i = 0; i < avctx->
channels; i++) {
469 for (i = 0; i < avctx->
channels; i++) {
484 if (delta & signmask)
512 int buf_size,
int *coded_samples,
int *approx_nb_samples)
517 int has_coded_samples = 0;
521 *approx_nb_samples = 0;
529 if (buf_size < 76 * ch)
534 if (buf_size < 34 * ch)
546 nb_samples = buf_size * 2 /
ch;
562 return (buf_size - header_size) * 2 /
ch;
567 has_coded_samples = 1;
568 *coded_samples = bytestream2_get_le32(gb);
569 *coded_samples -= *coded_samples % 28;
570 nb_samples = (buf_size - 12) / 30 * 28;
573 has_coded_samples = 1;
574 *coded_samples = bytestream2_get_le32(gb);
575 nb_samples = (buf_size - (4 + 8 *
ch)) * 2 /
ch;
578 nb_samples = (buf_size -
ch) / ch * 2;
585 has_coded_samples = 1;
588 header_size = 4 + 9 *
ch;
589 *coded_samples = bytestream2_get_le32(gb);
592 header_size = 4 + 5 *
ch;
593 *coded_samples = bytestream2_get_le32(gb);
596 header_size = 4 + 5 *
ch;
597 *coded_samples = bytestream2_get_be32(gb);
600 *coded_samples -= *coded_samples % 28;
601 nb_samples = (buf_size - header_size) * 2 / ch;
602 nb_samples -= nb_samples % 28;
603 *approx_nb_samples = 1;
608 nb_samples = ((buf_size - 16) * 2 / 3 * 4) /
ch;
613 if (buf_size < 4 * ch)
615 nb_samples = 1 + (buf_size - 4 *
ch) * 2 / ch;
620 nb_samples = (buf_size - 4 *
ch) * 2 / ch;
628 if (buf_size < 4 * ch)
630 nb_samples = 1 + (buf_size - 4 *
ch) / (bsize * ch) * bsamples;
636 nb_samples = (buf_size - 6 *
ch) * 2 / ch;
641 nb_samples = (buf_size - 16 * (ch / 2)) * 2 /
ch;
647 int samples_per_byte;
659 nb_samples += buf_size * samples_per_byte /
ch;
664 int buf_bits = buf_size * 8 - 2;
665 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
666 int block_hdr_size = 22 *
ch;
667 int block_size = block_hdr_size + nbits * ch * 4095;
668 int nblocks = buf_bits / block_size;
669 int bits_left = buf_bits - nblocks * block_size;
670 nb_samples = nblocks * 4096;
671 if (bits_left >= block_hdr_size)
672 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
678 nb_samples = buf_size * 14 / (8 *
ch);
681 has_coded_samples = 1;
684 bytestream2_get_le32(gb) :
685 bytestream2_get_be32(gb);
686 buf_size -= 8 + 36 *
ch;
688 nb_samples = buf_size / 8 * 14;
689 if (buf_size % 8 > 1)
690 nb_samples += (buf_size % 8 - 1) * 2;
691 *approx_nb_samples = 1;
694 nb_samples = buf_size / (9 *
ch) * 16;
697 nb_samples = (buf_size / 128) * 224 / ch;
701 nb_samples = buf_size / (16 *
ch) * 28;
706 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
713 int *got_frame_ptr,
AVPacket *avpkt)
717 int buf_size = avpkt->
size;
725 int nb_samples, coded_samples, approx_nb_samples, ret;
729 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
730 if (nb_samples <= 0) {
739 samples = (int16_t *)frame->
data[0];
745 if (!approx_nb_samples && coded_samples != nb_samples)
747 frame->
nb_samples = nb_samples = coded_samples;
756 for (channel = 0; channel < avctx->
channels; channel++) {
763 predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
764 step_index = predictor & 0x7F;
787 for (m = 0; m < 64; m += 2) {
788 int byte = bytestream2_get_byteu(&gb);
813 for (n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
814 for (i = 0; i < avctx->
channels; i++) {
818 samples = &samples_p[
i][1 + n * samples_per_block];
819 for (j = 0; j < block_size; j++) {
821 (j % 4) + (j / 4) * (avctx->
channels * 4) + i * 4];
826 for (m = 0; m < samples_per_block; m++) {
834 for (n = 0; n < (nb_samples - 1) / 8; n++) {
835 for (i = 0; i < avctx->
channels; i++) {
837 samples = &samples_p[
i][1 + n * 8];
838 for (m = 0; m < 8; m += 2) {
839 int v = bytestream2_get_byteu(&gb);
848 for (i = 0; i < avctx->
channels; i++)
851 for (i = 0; i < avctx->
channels; i++) {
860 for (i = 0; i < avctx->
channels; i++) {
861 samples = (int16_t *)frame->
data[i];
863 for (n = nb_samples >> 1; n > 0; n--) {
864 int v = bytestream2_get_byteu(&gb);
874 block_predictor = bytestream2_get_byteu(&gb);
875 if (block_predictor > 6) {
883 block_predictor = bytestream2_get_byteu(&gb);
884 if (block_predictor > 6) {
906 for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
907 int byte = bytestream2_get_byteu(&gb);
914 for (channel = 0; channel < avctx->
channels; channel+=2) {
917 c->
status[channel + 1].
step = bytestream2_get_le16u(&gb) & 0x1f;
922 for (n = 0; n < nb_samples; n+=2) {
923 int v = bytestream2_get_byteu(&gb);
927 for (n = 0; n < nb_samples; n+=2) {
928 int v = bytestream2_get_byteu(&gb);
935 for (channel = 0; channel < avctx->
channels; channel++) {
945 for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
946 int v = bytestream2_get_byteu(&gb);
955 int decode_top_nibble_next = 0;
957 const int16_t *samples_end = samples + avctx->
channels * nb_samples;
973 #define DK3_GET_NEXT_NIBBLE() \ 974 if (decode_top_nibble_next) { \ 975 nibble = last_byte >> 4; \ 976 decode_top_nibble_next = 0; \ 978 last_byte = bytestream2_get_byteu(&gb); \ 979 nibble = last_byte & 0x0F; \ 980 decode_top_nibble_next = 1; \ 983 while (samples < samples_end) {
1016 for (channel = 0; channel < avctx->
channels; channel++) {
1027 for (n = nb_samples >> (1 - st); n > 0; n--) {
1029 int v = bytestream2_get_byteu(&gb);
1043 for (channel = 0; channel < avctx->
channels; channel++) {
1047 for (n = 0; n < nb_samples; n += 2) {
1048 int v = bytestream2_get_byteu(&gb);
1056 int v = bytestream2_get_byteu(&gb);
1063 int v = bytestream2_get_byteu(&gb);
1069 for (channel = 0; channel < avctx->
channels; channel++) {
1079 for (n = 0; n < nb_samples / 2; n++) {
1082 byte[0] = bytestream2_get_byteu(&gb);
1084 byte[1] = bytestream2_get_byteu(&gb);
1085 for(channel = 0; channel < avctx->
channels; channel++) {
1088 for(channel = 0; channel < avctx->
channels; channel++) {
1095 for (channel = 0; channel < avctx->
channels; channel++) {
1096 int16_t *smp = samples_p[
channel];
1098 for (n = nb_samples / 2; n > 0; n--) {
1099 int v = bytestream2_get_byteu(&gb);
1105 for (n = nb_samples / 2; n > 0; n--) {
1106 for (channel = 0; channel < avctx->
channels; channel++) {
1107 int v = bytestream2_get_byteu(&gb);
1118 int16_t *out0 = samples_p[0];
1119 int16_t *out1 = samples_p[1];
1120 int samples_per_block = 28 * (3 - avctx->
channels) * 4;
1121 int sample_offset = 0;
1122 int bytes_remaining;
1126 avctx->
channels, sample_offset)) < 0)
1129 sample_offset += samples_per_block;
1134 if (bytes_remaining > 0) {
1140 for (i=0; i<=st; i++) {
1148 for (i=0; i<=st; i++) {
1154 for (n = nb_samples >> (1 - st); n > 0; n--) {
1155 int byte = bytestream2_get_byteu(&gb);
1161 for (n = nb_samples >> (1 - st); n > 0; n--) {
1162 int byte = bytestream2_get_byteu(&gb);
1169 int previous_left_sample, previous_right_sample;
1170 int current_left_sample, current_right_sample;
1171 int next_left_sample, next_right_sample;
1172 int coeff1l, coeff2l, coeff1r, coeff2r;
1173 int shift_left, shift_right;
1181 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1182 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1183 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1184 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1186 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1187 int byte = bytestream2_get_byteu(&gb);
1193 byte = bytestream2_get_byteu(&gb);
1194 shift_left = 20 - (byte >> 4);
1195 shift_right = 20 - (byte & 0x0F);
1197 for (count2 = 0; count2 < 28; count2++) {
1198 byte = bytestream2_get_byteu(&gb);
1199 next_left_sample =
sign_extend(byte >> 4, 4) << shift_left;
1200 next_right_sample =
sign_extend(byte, 4) << shift_right;
1202 next_left_sample = (next_left_sample +
1203 (current_left_sample * coeff1l) +
1204 (previous_left_sample * coeff2l) + 0x80) >> 8;
1205 next_right_sample = (next_right_sample +
1206 (current_right_sample * coeff1r) +
1207 (previous_right_sample * coeff2r) + 0x80) >> 8;
1209 previous_left_sample = current_left_sample;
1210 current_left_sample = av_clip_int16(next_left_sample);
1211 previous_right_sample = current_right_sample;
1212 current_right_sample = av_clip_int16(next_right_sample);
1213 *samples++ = current_left_sample;
1214 *samples++ = current_right_sample;
1226 for(channel = 0; channel < avctx->
channels; channel++) {
1227 int byte = bytestream2_get_byteu(&gb);
1230 shift[
channel] = 20 - (byte & 0x0F);
1232 for (count1 = 0; count1 < nb_samples / 2; count1++) {
1235 byte[0] = bytestream2_get_byteu(&gb);
1236 if (st) byte[1] = bytestream2_get_byteu(&gb);
1237 for(i = 4; i >= 0; i-=4) {
1238 for(channel = 0; channel < avctx->
channels; channel++) {
1260 int previous_sample, current_sample, next_sample;
1268 for (channel=0; channel<avctx->
channels; channel++)
1269 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1270 bytestream2_get_le32(&gb)) +
1273 for (channel=0; channel<avctx->
channels; channel++) {
1275 samplesC = samples_p[
channel];
1278 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1279 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1285 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1286 int byte = bytestream2_get_byte(&gb);
1288 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1289 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1291 for (count2=0; count2<28; count2++)
1292 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1296 shift = 20 - (byte & 0x0F);
1298 for (count2=0; count2<28; count2++) {
1302 byte = bytestream2_get_byte(&gb);
1306 next_sample += (current_sample * coeff1) +
1307 (previous_sample * coeff2);
1308 next_sample = av_clip_int16(next_sample >> 8);
1310 previous_sample = current_sample;
1311 current_sample = next_sample;
1312 *samplesC++ = current_sample;
1318 }
else if (count != count1) {
1320 count =
FFMAX(count, count1);
1334 for (channel=0; channel<avctx->
channels; channel++) {
1337 for (n = 0; n < 4; n++, s += 32) {
1343 val =
sign_extend(bytestream2_get_le16u(&gb), 16);
1344 shift[
n] = 20 - (val & 0x0F);
1348 for (m=2; m<32; m+=2) {
1350 for (n = 0; n < 4; n++, s += 32) {
1352 int byte = bytestream2_get_byteu(&gb);
1355 pred = s[-1] * coeff[0][
n] + s[-2] * coeff[1][
n];
1356 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
1359 pred = s[0] * coeff[0][
n] + s[-1] * coeff[1][
n];
1360 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
1375 for (n = nb_samples >> (1 - st); n > 0; n--) {
1376 int v = bytestream2_get_byteu(&gb);
1383 for (i = 0; i < avctx->
channels; i++) {
1394 for (n = nb_samples >> (1 - st); n > 0; n--) {
1395 int v = bytestream2_get_byteu(&gb);
1402 for (n = nb_samples >> (1 - st); n > 0; n--) {
1403 int v = bytestream2_get_byteu(&gb);
1413 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1415 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1420 for (n = nb_samples >> (1 - st); n > 0; n--) {
1421 int byte = bytestream2_get_byteu(&gb);
1428 for (n = (nb_samples<<st) / 3; n > 0; n--) {
1429 int byte = bytestream2_get_byteu(&gb);
1433 (byte >> 2) & 0x07, 3, 0);
1438 for (n = nb_samples >> (2 - st); n > 0; n--) {
1439 int byte = bytestream2_get_byteu(&gb);
1443 (byte >> 4) & 0x03, 2, 2);
1445 (byte >> 2) & 0x03, 2, 2);
1456 for (n = nb_samples >> (1 - st); n > 0; n--) {
1457 int v = bytestream2_get_byteu(&gb);
1464 for (channel = 0; channel < avctx->
channels; channel++)
1468 for (channel = 0; channel < avctx->
channels; channel++) {
1470 for (n = nb_samples >> 1; n > 0; n--) {
1471 int v = bytestream2_get_byteu(&gb);
1479 int samples_per_block;
1483 samples_per_block = avctx->
extradata[0] / 16;
1484 blocks = nb_samples / avctx->
extradata[0];
1486 samples_per_block = nb_samples / 16;
1490 for (m = 0; m < blocks; m++) {
1491 for (channel = 0; channel < avctx->
channels; channel++) {
1495 samples = samples_p[
channel] + m * 16;
1497 for (i = 0; i < samples_per_block; i++) {
1498 int byte = bytestream2_get_byteu(&gb);
1499 int scale = 1 << (byte >> 4);
1500 int index = byte & 0xf;
1505 for (n = 0; n < 16; n++) {
1511 byte = bytestream2_get_byteu(&gb);
1515 sampledat = ((prev1 * factor1 + prev2 * factor2) +
1516 ((sampledat * scale) << 11)) >> 11;
1517 *samples = av_clip_int16(sampledat);
1536 #define THP_GET16(g) \ 1538 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \ 1539 bytestream2_get_le16u(&(g)) : \ 1540 bytestream2_get_be16u(&(g)), 16) 1550 for (i = 0; i < avctx->
channels; i++)
1551 for (n = 0; n < 16; n++)
1554 for (i = 0; i < avctx->
channels; i++)
1555 for (n = 0; n < 16; n++)
1560 for (i = 0; i < avctx->
channels; i++) {
1570 for (ch = 0; ch < avctx->
channels; ch++) {
1571 samples = samples_p[
ch];
1574 for (i = 0; i < (nb_samples + 13) / 14; i++) {
1575 int byte = bytestream2_get_byteu(&gb);
1576 int index = (byte >> 4) & 7;
1577 unsigned int exp = byte & 0x0F;
1578 int factor1 = table[
ch][index * 2];
1579 int factor2 = table[
ch][index * 2 + 1];
1582 for (n = 0; n < 14 && (i * 14 + n < nb_samples); n++) {
1588 byte = bytestream2_get_byteu(&gb);
1594 *samples = av_clip_int16(sampledat);
1603 for (channel = 0; channel < avctx->
channels; channel++) {
1607 for (i = 0; i < nb_samples / 28; i++) {
1611 header = bytestream2_get_byteu(&gb);
1615 for (n = 0; n < 28; n++) {
1618 switch (header >> 4) {
1632 prev = av_clip_intp2((prev + 0x20) >> 6, 21);
1634 byte = bytestream2_get_byteu(&gb);
1640 sampledat = ((sampledat * (1 << 12)) >> (header & 0xf)) * (1 << 6) + prev;
1641 *samples++ = av_clip_int16(sampledat >> 6);
1651 for (channel = 0; channel < avctx->
channels; channel++) {
1655 for (i = 0; i < nb_samples / 28; i++) {
1658 filter = bytestream2_get_byteu(&gb);
1659 shift = filter & 0xf;
1660 filter = filter >> 4;
1663 flag = bytestream2_get_byteu(&gb);
1666 for (n = 0; n < 28; n++) {
1673 byte = bytestream2_get_byteu(&gb);
1677 scale = scale << 12;
1680 *samples++ = av_clip_int16(sample);
1722 #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \ 1723 AVCodec ff_ ## name_ ## _decoder = { \ 1725 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ 1726 .type = AVMEDIA_TYPE_AUDIO, \ 1728 .priv_data_size = sizeof(ADPCMDecodeContext), \ 1729 .init = adpcm_decode_init, \ 1730 .decode = adpcm_decode_frame, \ 1731 .flush = adpcm_flush, \ 1732 .capabilities = AV_CODEC_CAP_DR1, \ 1733 .sample_fmts = sample_fmts_, \
const struct AVCodec * codec
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
static int16_t adpcm_mtaf_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define avpriv_request_sample(...)
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static enum AVSampleFormat sample_fmts_s16[]
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static int get_sbits(GetBitContext *s, int n)
static int16_t adpcm_ms_expand_nibble(ADPCMChannelStatus *c, int nibble)
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
const uint8_t ff_adpcm_AdaptCoeff1[]
Divided by 4 to fit in 8-bit integers.
enum AVSampleFormat sample_fmt
audio sample format
static av_cold int adpcm_decode_init(AVCodecContext *avctx)
static void adpcm_flush(AVCodecContext *avctx)
static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int16_t *samples)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define u(width, name, range_min, range_max)
static const int xa_adpcm_table[5][2]
static int get_bits_count(const GetBitContext *s)
static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, int buf_size, int *coded_samples, int *approx_nb_samples)
Get the number of samples that will be decoded from the packet.
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
bitstream reader API header.
static const uint8_t header[24]
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static const uint16_t table[]
#define i(width, name, range_min, range_max)
const uint16_t ff_adpcm_afc_coeffs[2][16]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
ADPCM encoder/decoder common header.
static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
static const int ea_adpcm_table[]
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
const int8_t *const ff_adpcm_index_tables[4]
const int16_t ff_adpcm_step_table[89]
This is the step table.
static int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
static int16_t adpcm_ima_oki_expand_nibble(ADPCMChannelStatus *c, int nibble)
static int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitContext *gb, int bps)
const int8_t ff_adpcm_index_table[16]
const int16_t ff_adpcm_mtaf_stepsize[32][16]
static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1, const uint8_t *in, ADPCMChannelStatus *left, ADPCMChannelStatus *right, int channels, int sample_offset)
const int8_t ff_adpcm_AdaptCoeff2[]
Divided by 4 to fit in 8-bit integers.
int vqa_version
VQA version.
static const uint8_t ff_adpcm_ima_block_sizes[4]
static enum AVSampleFormat sample_fmts_s16p[]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
const int16_t ff_adpcm_oki_step_table[49]
#define FF_ARRAY_ELEMS(a)
static const float pred[4]
static const int swf_index_tables[4][16]
static const uint8_t ff_adpcm_ima_block_samples[4]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static av_always_inline int bytestream2_tell(GetByteContext *g)
const int16_t ff_adpcm_AdaptationTable[]
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
main external API structure.
static int16_t adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
#define DK3_GET_NEXT_NIBBLE()
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static int16_t adpcm_ima_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
ADPCMChannelStatus status[14]
static av_const int sign_extend(int val, unsigned bits)
static int16_t adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int size, int shift)
static unsigned int get_bits_le(GetBitContext *s, int n)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const int8_t ff_adpcm_yamaha_difflookup[]
common internal api header.
const int16_t ff_adpcm_yamaha_indexscale[]
static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
channel
Use these values when setting the channel map with ebur128_set_channel().
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define xf(width, name, var, range_min, range_max, subs,...)
int channels
number of audio channels
static const double coeff[2][5]
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static int16_t adpcm_ct_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
static enum AVSampleFormat sample_fmts_both[]
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_)