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;
187 add = (delta * 2 + 1) * step;
191 if ((nibble & 8) == 0)
192 pred = av_clip(pred + (add >> 3), -32767, 32767);
194 pred = av_clip(pred - (add >> 3), -32767, 32767);
201 c->
step = av_clip(c->
step * 2, 127, 24576);
219 c->
step = av_clip(c->
step, 127, 24576);
232 step_index = av_clip(step_index, 0, 88);
239 diff = ((2 * delta + 1) * step) >>
shift;
241 if (sign) predictor -=
diff;
242 else predictor +=
diff;
252 int nibble, step_index, predictor, sign,
delta,
diff, step,
shift;
258 step_index = av_clip(step_index, 0, 88);
260 sign = nibble & (1 <<
shift);
261 delta = av_mod_uintp2(nibble, shift);
262 diff = ((2 * delta + 1) * step) >>
shift;
264 if (sign) predictor -=
diff;
265 else predictor +=
diff;
281 step_index = av_clip(step_index, 0, 88);
284 if (nibble & 4) diff += step;
285 if (nibble & 2) diff += step >> 1;
286 if (nibble & 1) diff += step >> 2;
304 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->
idelta;
307 c->
sample1 = av_clip_int16(predictor);
310 if (c->
idelta > INT_MAX/768) {
320 int step_index, predictor, sign,
delta,
diff, step;
324 step_index = av_clip(step_index, 0, 48);
328 diff = ((2 * delta + 1) * step) >> 3;
330 if (sign) predictor -=
diff;
331 else predictor +=
diff;
333 c->
predictor = av_clip_intp2(predictor, 11);
349 diff = ((2 * delta + 1) * c->
step) >> 3;
355 c->
step = av_clip(new_step, 511, 32767);
364 sign = nibble & (1<<(size-1));
365 delta = nibble & ((1<<(size-1))-1);
372 if (delta >= (2*size - 3) && c->
step < 3)
374 else if (delta == 0 && c->
step > 0)
390 c->
step = av_clip(c->
step, 127, 24576);
399 c->
step = av_clip_uintp2(c->
step, 5);
412 out0 += sample_offset;
416 out1 += sample_offset;
419 shift = 12 - (in[4+i*2] & 15);
420 filter = in[4+i*2] >> 4;
435 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
437 s_1 = av_clip_int16(s);
448 shift = 12 - (in[5+i*2] & 15);
449 filter = in[5+i*2] >> 4;
462 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
464 s_1 = av_clip_int16(s);
488 int k0, signmask, nb_bits,
count;
489 int size = buf_size*8;
497 k0 = 1 << (nb_bits-2);
498 signmask = 1 << (nb_bits-1);
501 for (i = 0; i < avctx->
channels; i++) {
509 for (i = 0; i < avctx->
channels; i++) {
524 if (delta & signmask)
552 int buf_size,
int *coded_samples,
int *approx_nb_samples)
557 int has_coded_samples = 0;
561 *approx_nb_samples = 0;
569 if (buf_size < 76 * ch)
574 if (buf_size < 34 * ch)
586 nb_samples = buf_size * 2 /
ch;
603 return (buf_size - header_size) * 2 /
ch;
608 has_coded_samples = 1;
609 *coded_samples = bytestream2_get_le32(gb);
610 *coded_samples -= *coded_samples % 28;
611 nb_samples = (buf_size - 12) / 30 * 28;
614 has_coded_samples = 1;
615 *coded_samples = bytestream2_get_le32(gb);
616 nb_samples = (buf_size - (4 + 8 *
ch)) * 2 /
ch;
619 nb_samples = (buf_size -
ch) / ch * 2;
626 has_coded_samples = 1;
629 header_size = 4 + 9 *
ch;
630 *coded_samples = bytestream2_get_le32(gb);
633 header_size = 4 + 5 *
ch;
634 *coded_samples = bytestream2_get_le32(gb);
637 header_size = 4 + 5 *
ch;
638 *coded_samples = bytestream2_get_be32(gb);
641 *coded_samples -= *coded_samples % 28;
642 nb_samples = (buf_size - header_size) * 2 / ch;
643 nb_samples -= nb_samples % 28;
644 *approx_nb_samples = 1;
649 nb_samples = ((buf_size - 16) * 2 / 3 * 4) /
ch;
654 if (buf_size < 4 * ch)
656 nb_samples = 1 + (buf_size - 4 *
ch) * 2 / ch;
661 nb_samples = (buf_size - 4 *
ch) * 2 / ch;
669 if (buf_size < 4 * ch)
671 nb_samples = 1 + (buf_size - 4 *
ch) / (bsize * ch) * bsamples;
677 nb_samples = (buf_size - 6 *
ch) * 2 / ch;
682 nb_samples = (buf_size - 16 * (ch / 2)) * 2 /
ch;
688 int samples_per_byte;
700 nb_samples += buf_size * samples_per_byte /
ch;
705 int buf_bits = buf_size * 8 - 2;
706 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
707 int block_hdr_size = 22 *
ch;
708 int block_size = block_hdr_size + nbits * ch * 4095;
709 int nblocks = buf_bits / block_size;
710 int bits_left = buf_bits - nblocks * block_size;
711 nb_samples = nblocks * 4096;
712 if (bits_left >= block_hdr_size)
713 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
719 nb_samples = buf_size * 14 / (8 *
ch);
722 has_coded_samples = 1;
725 bytestream2_get_le32(gb) :
726 bytestream2_get_be32(gb);
727 buf_size -= 8 + 36 *
ch;
729 nb_samples = buf_size / 8 * 14;
730 if (buf_size % 8 > 1)
731 nb_samples += (buf_size % 8 - 1) * 2;
732 *approx_nb_samples = 1;
735 nb_samples = buf_size / (9 *
ch) * 16;
738 nb_samples = (buf_size / 128) * 224 / ch;
742 nb_samples = buf_size / (16 *
ch) * 28;
747 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
754 int *got_frame_ptr,
AVPacket *avpkt)
758 int buf_size = avpkt->
size;
766 int nb_samples, coded_samples, approx_nb_samples, ret;
770 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
771 if (nb_samples <= 0) {
780 samples = (int16_t *)frame->
data[0];
786 if (!approx_nb_samples && coded_samples != nb_samples)
788 frame->
nb_samples = nb_samples = coded_samples;
797 for (channel = 0; channel < avctx->
channels; channel++) {
804 predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
805 step_index = predictor & 0x7F;
828 for (m = 0; m < 64; m += 2) {
829 int byte = bytestream2_get_byteu(&gb);
854 for (n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
855 for (i = 0; i < avctx->
channels; i++) {
859 samples = &samples_p[
i][1 + n * samples_per_block];
860 for (j = 0; j < block_size; j++) {
862 (j % 4) + (j / 4) * (avctx->
channels * 4) + i * 4];
867 for (m = 0; m < samples_per_block; m++) {
875 for (n = 0; n < (nb_samples - 1) / 8; n++) {
876 for (i = 0; i < avctx->
channels; i++) {
878 samples = &samples_p[
i][1 + n * 8];
879 for (m = 0; m < 8; m += 2) {
880 int v = bytestream2_get_byteu(&gb);
889 for (i = 0; i < avctx->
channels; i++)
892 for (i = 0; i < avctx->
channels; i++) {
901 for (i = 0; i < avctx->
channels; i++) {
902 samples = (int16_t *)frame->
data[i];
904 for (n = nb_samples >> 1; n > 0; n--) {
905 int v = bytestream2_get_byteu(&gb);
912 for (i = 0; i < avctx->
channels; i++)
914 for (i = 0; i < avctx->
channels; i++)
917 for (n = 0; n < nb_samples >> (1 - st); n++) {
918 int v = bytestream2_get_byteu(&gb);
927 block_predictor = bytestream2_get_byteu(&gb);
928 if (block_predictor > 6) {
936 block_predictor = bytestream2_get_byteu(&gb);
937 if (block_predictor > 6) {
959 for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
960 int byte = bytestream2_get_byteu(&gb);
967 for (channel = 0; channel < avctx->
channels; channel+=2) {
970 c->
status[channel + 1].
step = bytestream2_get_le16u(&gb) & 0x1f;
975 for (n = 0; n < nb_samples; n+=2) {
976 int v = bytestream2_get_byteu(&gb);
980 for (n = 0; n < nb_samples; n+=2) {
981 int v = bytestream2_get_byteu(&gb);
988 for (channel = 0; channel < avctx->
channels; channel++) {
998 for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
999 int v = bytestream2_get_byteu(&gb);
1008 int decode_top_nibble_next = 0;
1010 const int16_t *samples_end = samples + avctx->
channels * nb_samples;
1026 #define DK3_GET_NEXT_NIBBLE() \ 1027 if (decode_top_nibble_next) { \ 1028 nibble = last_byte >> 4; \ 1029 decode_top_nibble_next = 0; \ 1031 last_byte = bytestream2_get_byteu(&gb); \ 1032 nibble = last_byte & 0x0F; \ 1033 decode_top_nibble_next = 1; \ 1036 while (samples < samples_end) {
1069 for (channel = 0; channel < avctx->
channels; channel++) {
1080 for (n = nb_samples >> (1 - st); n > 0; n--) {
1082 int v = bytestream2_get_byteu(&gb);
1096 for (channel = 0; channel < avctx->
channels; channel++) {
1100 for (n = 0; n < nb_samples; n += 2) {
1101 int v = bytestream2_get_byteu(&gb);
1109 int v = bytestream2_get_byteu(&gb);
1116 int v = bytestream2_get_byteu(&gb);
1122 for (channel = 0; channel < avctx->
channels; channel++) {
1132 for (n = 0; n < nb_samples / 2; n++) {
1135 byte[0] = bytestream2_get_byteu(&gb);
1137 byte[1] = bytestream2_get_byteu(&gb);
1138 for(channel = 0; channel < avctx->
channels; channel++) {
1141 for(channel = 0; channel < avctx->
channels; channel++) {
1148 for (channel = 0; channel < avctx->
channels; channel++) {
1149 int16_t *smp = samples_p[
channel];
1151 for (n = nb_samples / 2; n > 0; n--) {
1152 int v = bytestream2_get_byteu(&gb);
1158 for (n = nb_samples / 2; n > 0; n--) {
1159 for (channel = 0; channel < avctx->
channels; channel++) {
1160 int v = bytestream2_get_byteu(&gb);
1171 int16_t *out0 = samples_p[0];
1172 int16_t *out1 = samples_p[1];
1173 int samples_per_block = 28 * (3 - avctx->
channels) * 4;
1174 int sample_offset = 0;
1175 int bytes_remaining;
1179 avctx->
channels, sample_offset)) < 0)
1182 sample_offset += samples_per_block;
1187 if (bytes_remaining > 0) {
1193 for (i=0; i<=st; i++) {
1201 for (i=0; i<=st; i++)
1204 for (n = nb_samples >> (1 - st); n > 0; n--) {
1205 int byte = bytestream2_get_byteu(&gb);
1211 for (n = nb_samples >> (1 - st); n > 0; n--) {
1212 int byte = bytestream2_get_byteu(&gb);
1219 int previous_left_sample, previous_right_sample;
1220 int current_left_sample, current_right_sample;
1221 int next_left_sample, next_right_sample;
1222 int coeff1l, coeff2l, coeff1r, coeff2r;
1223 int shift_left, shift_right;
1231 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1232 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1233 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1234 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1236 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1237 int byte = bytestream2_get_byteu(&gb);
1243 byte = bytestream2_get_byteu(&gb);
1244 shift_left = 20 - (byte >> 4);
1245 shift_right = 20 - (byte & 0x0F);
1247 for (count2 = 0; count2 < 28; count2++) {
1248 byte = bytestream2_get_byteu(&gb);
1249 next_left_sample =
sign_extend(byte >> 4, 4) << shift_left;
1250 next_right_sample =
sign_extend(byte, 4) << shift_right;
1252 next_left_sample = (next_left_sample +
1253 (current_left_sample * coeff1l) +
1254 (previous_left_sample * coeff2l) + 0x80) >> 8;
1255 next_right_sample = (next_right_sample +
1256 (current_right_sample * coeff1r) +
1257 (previous_right_sample * coeff2r) + 0x80) >> 8;
1259 previous_left_sample = current_left_sample;
1260 current_left_sample = av_clip_int16(next_left_sample);
1261 previous_right_sample = current_right_sample;
1262 current_right_sample = av_clip_int16(next_right_sample);
1263 *samples++ = current_left_sample;
1264 *samples++ = current_right_sample;
1276 for(channel = 0; channel < avctx->
channels; channel++) {
1277 int byte = bytestream2_get_byteu(&gb);
1280 shift[
channel] = 20 - (byte & 0x0F);
1282 for (count1 = 0; count1 < nb_samples / 2; count1++) {
1285 byte[0] = bytestream2_get_byteu(&gb);
1286 if (st) byte[1] = bytestream2_get_byteu(&gb);
1287 for(i = 4; i >= 0; i-=4) {
1288 for(channel = 0; channel < avctx->
channels; channel++) {
1310 int previous_sample, current_sample, next_sample;
1318 for (channel=0; channel<avctx->
channels; channel++)
1319 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1320 bytestream2_get_le32(&gb)) +
1323 for (channel=0; channel<avctx->
channels; channel++) {
1325 samplesC = samples_p[
channel];
1328 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1329 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1335 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1336 int byte = bytestream2_get_byte(&gb);
1338 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1339 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1341 for (count2=0; count2<28; count2++)
1342 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1346 shift = 20 - (byte & 0x0F);
1348 for (count2=0; count2<28; count2++) {
1352 byte = bytestream2_get_byte(&gb);
1356 next_sample += (current_sample * coeff1) +
1357 (previous_sample * coeff2);
1358 next_sample = av_clip_int16(next_sample >> 8);
1360 previous_sample = current_sample;
1361 current_sample = next_sample;
1362 *samplesC++ = current_sample;
1368 }
else if (count != count1) {
1370 count =
FFMAX(count, count1);
1384 for (channel=0; channel<avctx->
channels; channel++) {
1387 for (n = 0; n < 4; n++, s += 32) {
1393 val =
sign_extend(bytestream2_get_le16u(&gb), 16);
1394 shift[
n] = 20 - (val & 0x0F);
1398 for (m=2; m<32; m+=2) {
1400 for (n = 0; n < 4; n++, s += 32) {
1402 int byte = bytestream2_get_byteu(&gb);
1405 pred = s[-1] * coeff[0][
n] + s[-2] * coeff[1][
n];
1406 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
1409 pred = s[0] * coeff[0][
n] + s[-1] * coeff[1][
n];
1410 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
1425 for (n = nb_samples >> (1 - st); n > 0; n--) {
1426 int v = bytestream2_get_byteu(&gb);
1433 for (i = 0; i < avctx->
channels; i++) {
1444 for (n = nb_samples >> (1 - st); n > 0; n--) {
1445 int v = bytestream2_get_byteu(&gb);
1452 for (n = nb_samples >> (1 - st); n > 0; n--) {
1453 int v = bytestream2_get_byteu(&gb);
1463 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1465 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1470 for (n = nb_samples >> (1 - st); n > 0; n--) {
1471 int byte = bytestream2_get_byteu(&gb);
1478 for (n = (nb_samples<<st) / 3; n > 0; n--) {
1479 int byte = bytestream2_get_byteu(&gb);
1483 (byte >> 2) & 0x07, 3, 0);
1488 for (n = nb_samples >> (2 - st); n > 0; n--) {
1489 int byte = bytestream2_get_byteu(&gb);
1493 (byte >> 4) & 0x03, 2, 2);
1495 (byte >> 2) & 0x03, 2, 2);
1506 for (n = nb_samples >> (1 - st); n > 0; n--) {
1507 int v = bytestream2_get_byteu(&gb);
1514 for (channel = 0; channel < avctx->
channels; channel++)
1518 for (channel = 0; channel < avctx->
channels; channel++) {
1520 for (n = nb_samples >> 1; n > 0; n--) {
1521 int v = bytestream2_get_byteu(&gb);
1529 int samples_per_block;
1533 samples_per_block = avctx->
extradata[0] / 16;
1534 blocks = nb_samples / avctx->
extradata[0];
1536 samples_per_block = nb_samples / 16;
1540 for (m = 0; m < blocks; m++) {
1541 for (channel = 0; channel < avctx->
channels; channel++) {
1545 samples = samples_p[
channel] + m * 16;
1547 for (i = 0; i < samples_per_block; i++) {
1548 int byte = bytestream2_get_byteu(&gb);
1549 int scale = 1 << (byte >> 4);
1550 int index = byte & 0xf;
1555 for (n = 0; n < 16; n++) {
1561 byte = bytestream2_get_byteu(&gb);
1565 sampledat = ((prev1 * factor1 + prev2 * factor2) +
1566 ((sampledat * scale) << 11)) >> 11;
1567 *samples = av_clip_int16(sampledat);
1586 #define THP_GET16(g) \ 1588 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \ 1589 bytestream2_get_le16u(&(g)) : \ 1590 bytestream2_get_be16u(&(g)), 16) 1600 for (i = 0; i < avctx->
channels; i++)
1601 for (n = 0; n < 16; n++)
1604 for (i = 0; i < avctx->
channels; i++)
1605 for (n = 0; n < 16; n++)
1610 for (i = 0; i < avctx->
channels; i++) {
1620 for (ch = 0; ch < avctx->
channels; ch++) {
1621 samples = samples_p[
ch];
1624 for (i = 0; i < (nb_samples + 13) / 14; i++) {
1625 int byte = bytestream2_get_byteu(&gb);
1626 int index = (byte >> 4) & 7;
1627 unsigned int exp = byte & 0x0F;
1628 int factor1 = table[
ch][index * 2];
1629 int factor2 = table[
ch][index * 2 + 1];
1632 for (n = 0; n < 14 && (i * 14 + n < nb_samples); n++) {
1638 byte = bytestream2_get_byteu(&gb);
1644 *samples = av_clip_int16(sampledat);
1653 for (channel = 0; channel < avctx->
channels; channel++) {
1657 for (i = 0; i < nb_samples / 28; i++) {
1661 header = bytestream2_get_byteu(&gb);
1665 for (n = 0; n < 28; n++) {
1668 switch (header >> 4) {
1682 prev = av_clip_intp2((prev + 0x20) >> 6, 21);
1684 byte = bytestream2_get_byteu(&gb);
1690 sampledat = (((sampledat << 12) >> (header & 0xf)) << 6) + prev;
1691 *samples++ = av_clip_int16(sampledat >> 6);
1701 for (channel = 0; channel < avctx->
channels; channel++) {
1705 for (i = 0; i < nb_samples / 28; i++) {
1708 filter = bytestream2_get_byteu(&gb);
1709 shift = filter & 0xf;
1710 filter = filter >> 4;
1713 flag = bytestream2_get_byteu(&gb);
1716 for (n = 0; n < 28; n++) {
1723 byte = bytestream2_get_byteu(&gb);
1727 scale = scale << 12;
1730 *samples++ = av_clip_int16(sample);
1772 #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \ 1773 AVCodec ff_ ## name_ ## _decoder = { \ 1775 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ 1776 .type = AVMEDIA_TYPE_AUDIO, \ 1778 .priv_data_size = sizeof(ADPCMDecodeContext), \ 1779 .init = adpcm_decode_init, \ 1780 .decode = adpcm_decode_frame, \ 1781 .flush = adpcm_flush, \ 1782 .capabilities = AV_CODEC_CAP_DR1, \ 1783 .sample_fmts = sample_fmts_, \
const struct AVCodec * codec
const char const char void * val
static const int16_t ea_adpcm_table[]
#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)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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 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)
static const int8_t xa_adpcm_table[5][2]
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 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]
static const int8_t swf_index_tables[4][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[]
const int16_t ff_adpcm_oki_step_table[49]
#define FF_ARRAY_ELEMS(a)
static const float pred[4]
static const uint8_t ff_adpcm_ima_block_samples[4]
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.
static int16_t adpcm_agm_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
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_)