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;
628 int nb_samples, coded_samples,
ret;
632 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples);
633 if (nb_samples <= 0) {
642 samples = (
short *)frame->
data[0];
648 if (coded_samples != nb_samples)
650 frame->
nb_samples = nb_samples = coded_samples;
659 for (channel = 0; channel < avctx->
channels; channel++) {
662 cs = &(c->
status[channel]);
666 predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
667 step_index = predictor & 0x7F;
688 samples = samples_p[channel];
690 for (m = 0; m < 64; m += 2) {
691 int byte = bytestream2_get_byteu(&gb);
710 for (n = 0; n < (nb_samples - 1) / 8; n++) {
711 for (i = 0; i < avctx->
channels; i++) {
713 samples = &samples_p[
i][1 + n * 8];
714 for (m = 0; m < 8; m += 2) {
715 int v = bytestream2_get_byteu(&gb);
723 for (i = 0; i < avctx->
channels; i++)
726 for (i = 0; i < avctx->
channels; i++) {
735 for (i = 0; i < avctx->
channels; i++) {
736 samples = (int16_t *)frame->
data[i];
738 for (n = nb_samples >> 1; n > 0; n--) {
739 int v = bytestream2_get_byteu(&gb);
749 block_predictor = bytestream2_get_byteu(&gb);
750 if (block_predictor > 6) {
758 block_predictor = bytestream2_get_byteu(&gb);
759 if (block_predictor > 6) {
781 for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
782 int byte = bytestream2_get_byteu(&gb);
789 for (channel = 0; channel < avctx->
channels; channel++) {
799 for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
800 int v = bytestream2_get_byteu(&gb);
809 int decode_top_nibble_next = 0;
811 const int16_t *samples_end = samples + avctx->
channels * nb_samples;
827 #define DK3_GET_NEXT_NIBBLE() \ 828 if (decode_top_nibble_next) { \ 829 nibble = last_byte >> 4; \ 830 decode_top_nibble_next = 0; \ 832 last_byte = bytestream2_get_byteu(&gb); \ 833 nibble = last_byte & 0x0F; \ 834 decode_top_nibble_next = 1; \ 837 while (samples < samples_end) {
867 for (channel = 0; channel < avctx->
channels; channel++) {
878 for (n = nb_samples >> (1 - st); n > 0; n--) {
880 int v = bytestream2_get_byteu(&gb);
895 int v = bytestream2_get_byteu(&gb);
902 int v = bytestream2_get_byteu(&gb);
909 for (channel = 0; channel < avctx->
channels; channel++) {
910 int16_t *smp = samples_p[channel];
912 for (n = nb_samples / 2; n > 0; n--) {
913 int v = bytestream2_get_byteu(&gb);
919 for (n = nb_samples / 2; n > 0; n--) {
920 for (channel = 0; channel < avctx->
channels; channel++) {
921 int v = bytestream2_get_byteu(&gb);
932 int16_t *out0 = samples_p[0];
933 int16_t *out1 = samples_p[1];
934 int samples_per_block = 28 * (3 - avctx->
channels) * 4;
935 int sample_offset = 0;
939 avctx->
channels, sample_offset)) < 0)
942 sample_offset += samples_per_block;
947 for (i=0; i<=st; i++) {
955 for (i=0; i<=st; i++)
958 for (n = nb_samples >> (1 - st); n > 0; n--) {
959 int byte = bytestream2_get_byteu(&gb);
965 for (n = nb_samples >> (1 - st); n > 0; n--) {
966 int byte = bytestream2_get_byteu(&gb);
973 int previous_left_sample, previous_right_sample;
974 int current_left_sample, current_right_sample;
975 int next_left_sample, next_right_sample;
976 int coeff1l, coeff2l, coeff1r, coeff2r;
977 int shift_left, shift_right;
985 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
986 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
987 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
988 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
990 for (count1 = 0; count1 < nb_samples / 28; count1++) {
991 int byte = bytestream2_get_byteu(&gb);
997 byte = bytestream2_get_byteu(&gb);
998 shift_left = 20 - (byte >> 4);
999 shift_right = 20 - (byte & 0x0F);
1001 for (count2 = 0; count2 < 28; count2++) {
1002 byte = bytestream2_get_byteu(&gb);
1003 next_left_sample =
sign_extend(byte >> 4, 4) << shift_left;
1004 next_right_sample =
sign_extend(byte, 4) << shift_right;
1006 next_left_sample = (next_left_sample +
1007 (current_left_sample * coeff1l) +
1008 (previous_left_sample * coeff2l) + 0x80) >> 8;
1009 next_right_sample = (next_right_sample +
1010 (current_right_sample * coeff1r) +
1011 (previous_right_sample * coeff2r) + 0x80) >> 8;
1013 previous_left_sample = current_left_sample;
1014 current_left_sample = av_clip_int16(next_left_sample);
1015 previous_right_sample = current_right_sample;
1016 current_right_sample = av_clip_int16(next_right_sample);
1017 *samples++ = current_left_sample;
1018 *samples++ = current_right_sample;
1030 for(channel = 0; channel < avctx->
channels; channel++) {
1031 int byte = bytestream2_get_byteu(&gb);
1034 shift[channel] = 20 - (byte & 0x0F);
1036 for (count1 = 0; count1 < nb_samples / 2; count1++) {
1039 byte[0] = bytestream2_get_byteu(&gb);
1040 if (st) byte[1] = bytestream2_get_byteu(&gb);
1041 for(i = 4; i >= 0; i-=4) {
1042 for(channel = 0; channel < avctx->
channels; channel++) {
1046 c->
status[channel].
sample2 * coeff[channel][1] + 0x80) >> 8;
1064 int previous_sample, current_sample, next_sample;
1067 unsigned int channel;
1072 for (channel=0; channel<avctx->
channels; channel++)
1073 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1074 bytestream2_get_le32(&gb)) +
1077 for (channel=0; channel<avctx->
channels; channel++) {
1079 samplesC = samples_p[channel];
1082 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1083 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1089 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1090 int byte = bytestream2_get_byte(&gb);
1092 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1093 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1095 for (count2=0; count2<28; count2++)
1096 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1100 shift = 20 - (byte & 0x0F);
1102 for (count2=0; count2<28; count2++) {
1106 byte = bytestream2_get_byte(&gb);
1110 next_sample += (current_sample * coeff1) +
1111 (previous_sample * coeff2);
1112 next_sample = av_clip_int16(next_sample >> 8);
1114 previous_sample = current_sample;
1115 current_sample = next_sample;
1116 *samplesC++ = current_sample;
1122 }
else if (count != count1) {
1124 count =
FFMAX(count, count1);
1138 for (channel=0; channel<avctx->
channels; channel++) {
1140 int16_t *
s = samples_p[channel];
1141 for (n = 0; n < 4; n++, s += 32) {
1147 val =
sign_extend(bytestream2_get_le16u(&gb), 16);
1148 shift[
n] = 20 - (val & 0x0F);
1152 for (m=2; m<32; m+=2) {
1153 s = &samples_p[channel][
m];
1154 for (n = 0; n < 4; n++, s += 32) {
1156 int byte = bytestream2_get_byteu(&gb);
1159 pred = s[-1] * coeff[0][
n] + s[-2] * coeff[1][
n];
1160 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
1163 pred = s[0] * coeff[0][
n] + s[-1] * coeff[1][
n];
1164 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
1179 for (n = nb_samples >> (1 - st); n > 0; n--) {
1180 int v = bytestream2_get_byteu(&gb);
1187 for (i = 0; i < avctx->
channels; i++) {
1198 for (n = nb_samples >> (1 - st); n > 0; n--) {
1199 int v = bytestream2_get_byteu(&gb);
1206 for (n = nb_samples >> (1 - st); n > 0; n--) {
1207 int v = bytestream2_get_byteu(&gb);
1217 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1219 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1224 for (n = nb_samples >> (1 - st); n > 0; n--) {
1225 int byte = bytestream2_get_byteu(&gb);
1232 for (n = nb_samples / 3; n > 0; n--) {
1233 int byte = bytestream2_get_byteu(&gb);
1237 (byte >> 2) & 0x07, 3, 0);
1242 for (n = nb_samples >> (2 - st); n > 0; n--) {
1243 int byte = bytestream2_get_byteu(&gb);
1247 (byte >> 4) & 0x03, 2, 2);
1249 (byte >> 2) & 0x03, 2, 2);
1260 for (n = nb_samples >> (1 - st); n > 0; n--) {
1261 int v = bytestream2_get_byteu(&gb);
1268 int samples_per_block;
1272 samples_per_block = avctx->
extradata[0] / 16;
1273 blocks = nb_samples / avctx->
extradata[0];
1275 samples_per_block = nb_samples / 16;
1279 for (m = 0; m < blocks; m++) {
1280 for (channel = 0; channel < avctx->
channels; channel++) {
1284 samples = samples_p[channel] + m * 16;
1286 for (i = 0; i < samples_per_block; i++) {
1287 int byte = bytestream2_get_byteu(&gb);
1288 int scale = 1 << (byte >> 4);
1289 int index = byte & 0xf;
1294 for (n = 0; n < 16; n++) {
1300 byte = bytestream2_get_byteu(&gb);
1304 sampledat = ((prev1 * factor1 + prev2 * factor2) +
1305 ((sampledat * scale) << 11)) >> 11;
1306 *samples = av_clip_int16(sampledat);
1324 for (i = 0; i < avctx->
channels; i++)
1325 for (n = 0; n < 16; n++)
1326 table[i][n] =
sign_extend(bytestream2_get_be16u(&gb), 16);
1329 for (i = 0; i < avctx->
channels; i++) {
1334 for (ch = 0; ch < avctx->
channels; ch++) {
1335 samples = samples_p[ch];
1338 for (i = 0; i < nb_samples / 14; i++) {
1339 int byte = bytestream2_get_byteu(&gb);
1340 int index = (byte >> 4) & 7;
1341 unsigned int exp = byte & 0x0F;
1342 int factor1 = table[ch][index * 2];
1343 int factor2 = table[ch][index * 2 + 1];
1346 for (n = 0; n < 14; n++) {
1352 byte = bytestream2_get_byteu(&gb);
1358 *samples = av_clip_int16(sampledat);
1390 #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \ 1391 AVCodec ff_ ## name_ ## _decoder = { \ 1393 .type = AVMEDIA_TYPE_AUDIO, \ 1395 .priv_data_size = sizeof(ADPCMDecodeContext), \ 1396 .init = adpcm_decode_init, \ 1397 .decode = adpcm_decode_frame, \ 1398 .capabilities = CODEC_CAP_DR1, \ 1399 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ 1400 .sample_fmts = sample_fmts_, \ struct ADPCMDecodeContext ADPCMDecodeContext
const struct AVCodec * codec
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
const int16_t ff_adpcm_afc_coeffs[2][16]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static enum AVSampleFormat sample_fmts_s16[]
#define FF_ARRAY_ELEMS(a)
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)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
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_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.
static const int xa_adpcm_table[5][2]
the mask is usually to keep the same permissions Filters should remove permissions on reference they give to output whenever necessary It can be automatically done by setting the rej_perms field on the output pad Here are a few guidelines corresponding to common then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
static int get_bits_count(const GetBitContext *s)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
bitstream reader API header.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static void predictor(uint8_t *src, int size)
ADPCM encoder/decoder common header.
static short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
static const int ea_adpcm_table[]
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static const struct endianess table[]
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)
void av_log(void *avcl, int level, const char *fmt,...)
ADPCMChannelStatus status[6]
const int8_t ff_adpcm_index_table[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 enum AVSampleFormat sample_fmts_s16p[]
#define diff(a, as, b, bs)
FIXME Range Coding of cr are level
const int16_t ff_adpcm_oki_step_table[49]
static short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift)
static const float pred[4]
static const int swf_index_tables[4][16]
static av_always_inline int bytestream2_tell(GetByteContext *g)
const int16_t ff_adpcm_AdaptationTable[]
static short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, int nibble)
main external API structure.
#define DK3_GET_NEXT_NIBBLE()
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
synthesis window for stochastic i
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static const double coeff[2][5]
static short adpcm_ima_oki_expand_nibble(ADPCMChannelStatus *c, int nibble)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
static av_const int sign_extend(int val, unsigned bits)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, int buf_size, int *coded_samples)
Get the number of samples that will be decoded from the packet.
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)
AVSampleFormat
Audio Sample Formats.
int channels
number of audio channels
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static enum AVSampleFormat sample_fmts_both[]
Filter the word “frame” indicates either a video frame or a group of audio samples
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
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
#define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_)