21 #define BITSTREAM_READER_LE 87 { 0, -1, -1, -1, -1 },
97 { 0, -1, -1, -1, -1 },
100 { 1, 2, -1, -1, -1 },
135 for (i = 0; i < 256; i++)
138 for (i = 0; i < 16; i++)
139 lpc_tab[i] = sin((i - 8) * (
M_PI / ((i < 8) ? 17 : 15)));
147 int i, ps, si,
code, step_i;
153 value = (((ps & 0x7fffff) ^ -si) + si) * (1.0
f / 0x7fffff);
156 if (step_i > step_max) {
163 for (i = 0; i < 64; i++) {
166 delta = step * 0.03125f;
170 delta += step * 0.5f;
172 delta += step * 0.25f;
174 delta += step * 0.125f;
176 delta += step * 0.0625f;
189 step_i =
av_clip(step_i, 0, step_max);
201 int i, ps, si,
code, step_i;
207 value = (((ps & 0x7fff) ^ -si) + si) * (1.0
f / 0x7fff);
210 if (step_i > step_max) {
217 for (i = 0; i < 64; i++) {
220 delta = step * 0.125f;
224 delta += step * 0.5f;
226 delta += step * 0.25f;
239 step_i =
av_clip(step_i, 0, step_max);
263 if (chunk->
len >= 52)
265 if (chunk->
len >= 35)
286 int sf, sf_idx, ch, main_ch, freq;
290 for (sf = 0; sf < 1 << group; sf += diff ? 8 : 1) {
291 sf_idx = ((s->
framenum << group) + sf) & 31;
295 for (freq = 1;; freq++) {
312 if (freq >> (5 - group) > s->
nsubbands * 4 - 6) {
322 amp[main_ch] = main_amp <
AMP_MAX ? main_amp : 0;
343 t->
x_freq = freq >> (5 - group);
344 t->
f_delt = (freq & ((1 << (5 - group)) - 1)) << group;
352 t->
phs[ch] = 128 - phs[ch] * 32 +
shift;
381 for (sb = 0; sb < 6; sb++)
387 for (group = 0; group < 5; group++) {
428 int i, sf, prev, next, dist;
437 for (sf = 0; sf < 7; sf += dist) {
457 next = prev + ((next + 1) >> 1);
459 next = prev - ( next >> 1);
465 scf[sf + 1] = prev + ((next - prev) >> 1);
467 scf[sf + 1] = prev - ((prev - next) >> 1);
472 scf[sf + 1] = prev + ( (next - prev) >> 2);
473 scf[sf + 2] = prev + ( (next - prev) >> 1);
474 scf[sf + 3] = prev + (((next - prev) * 3) >> 2);
476 scf[sf + 1] = prev - ( (prev - next) >> 2);
477 scf[sf + 2] = prev - ( (prev - next) >> 1);
478 scf[sf + 3] = prev - (((prev - next) * 3) >> 2);
483 for (i = 1; i < dist; i++)
484 scf[sf + i] = prev + (next - prev) * i / dist;
512 int ch, sb, sf, nsubbands,
ret;
523 for (sb = 2; sb < nsubbands; sb++) {
538 for (sb = 0; sb < s->
nsubbands - 4; sb++) {
564 for (sb = 0; sb < nsubbands; sb++)
565 for (ch = ch1; ch <= ch2; ch++)
566 for (sf = 1; sf <= 4; sf++)
580 int sb, nsubbands,
ret;
584 for (sb = 2; sb < nsubbands; sb++) {
593 for (sb = 0; sb < s->
nsubbands - 4; sb++) {
608 for (ch = ch1; ch <= ch2; ch++) {
615 for (i = 0; i < 8; i++) {
638 int i, j,
code, nblocks, coding_method;
645 switch (quant_level) {
648 for (i = 0; i < nblocks; i++, samples += 8) {
650 for (j = 0; j < 8; j++)
666 for (i = 0; i < nblocks; i++, samples += 5) {
668 for (j = 0; j < 5; j++)
677 for (i = 0; i < nblocks; i++, samples += 3) {
679 for (j = 0; j < 3; j++)
692 for (i = 0; i < nblocks; i++)
710 int start_sb,
int end_sb,
int flag)
712 int sb, sb_g3, sb_reorder, quant_level;
714 for (sb = start_sb; sb < end_sb; sb++) {
718 }
else if (flag && sb < s->max_mono_subband) {
735 }
else if (sb < 12 && sb_reorder >= 4) {
756 parse_ch(s, ch1, sb_reorder, quant_level, 0);
758 parse_ch(s, ch2, sb_reorder, quant_level, 1);
760 parse_ch(s, ch1, sb_reorder, quant_level, 0);
762 parse_ch(s, ch2, sb_reorder, quant_level, 0);
776 for (i = 0; i < 8; i++) {
778 for (j = 0; j < (i + 1) / 2; j++) {
779 float tmp1 = coeff[ j ];
780 float tmp2 = coeff[i - j - 1];
781 coeff[ j ] = tmp1 + rc * tmp2;
782 coeff[i - j - 1] = tmp2 + rc * tmp1;
791 int i, sb, ch, codes[16];
794 for (sb = start_sb; sb < end_sb; sb++) {
795 int ncodes = 8 * (1 + (sb < 2));
796 for (ch = ch1; ch <= ch2; ch++) {
799 for (i = 0; i < ncodes; i++)
801 for (i = 0; i < ncodes / 8; i++)
824 ol = (profile >> 3) & 7;
828 max_sb = profile & 7;
833 int a = 18000 / (12 * f / 1000 + 100 + 40 * st) + 20 * ol;
835 quant_levels[sb] = 1;
837 quant_levels[sb] = 2;
839 quant_levels[sb] = 3;
841 quant_levels[sb] = 4;
843 quant_levels[sb] = 5;
847 for (sb = 0; sb < 8; sb++)
858 ret =
parse_ts(s, ch1, ch2, 0, 2, 0);
863 for (sb = 0; sb < 2; sb++)
864 for (ch = ch1; ch <= ch2; ch++)
872 int start_sb,
int end_sb,
int flag)
874 int i, j, sb, ch, nsubbands;
877 if (end_sb > nsubbands)
880 for (sb = start_sb; sb < end_sb; sb++) {
881 for (ch = ch1; ch <= ch2; ch++) {
891 for (i = 0; i < 8; i++, g2_scf += 8) {
893 memset(g2_scf, 0, 64 - i * 8);
898 for (j = 0; j < 8; j++) {
904 memset(g2_scf, 0, 8);
920 if ((ret =
parse_lpc(s, ch1, ch2, 2, 3)) < 0)
922 if ((ret =
parse_ts(s, ch1, ch2, 2, 4, 0)) < 0)
926 if ((ret =
parse_ts(s, ch1, ch2, 4, 6, 0)) < 0)
956 double scale = (-1.0 / (1 << 17)) * sqrt(1 << (2 - s->
limited_range));
969 if (br_per_ch < 14000)
971 else if (br_per_ch < 32000)
972 scale = (br_per_ch - 14000) * (1.0 / 120000) + 0.85;
976 scale *= 1.0 / INT_MAX;
982 s->
sb_scf[
i] = (i - 1) * 0.25 * 0.785 * scale;
1022 unsigned int sr_code;
1025 sr_code = bytestream2_get_byte(gb);
1037 s->
ch_mask = bytestream2_get_le16(gb);
1048 version = bytestream2_get_le16(gb);
1049 if ((version & 0xff00) != 0x0800) {
1055 s->
flags = bytestream2_get_byte(gb);
1069 bit_rate_hi = bytestream2_get_byte(gb);
1072 s->
bit_rate_orig = bytestream2_get_le16(gb) | ((bit_rate_hi & 0x0F) << 16);
1075 s->
bit_rate_scaled = bytestream2_get_le16(gb) | ((bit_rate_hi & 0xF0) << 12);
1182 int i, ch, sb, sf,
ret, group, chunk_id, chunk_len;
1193 switch (bytestream2_get_byte(&gb)) {
1212 chunk_id = bytestream2_get_byte(&gb);
1213 chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
1224 switch (chunk_id & 0x7f) {
1227 int checksum = bytestream2_get_be16(&gb);
1228 uint16_t res = chunk_id;
1229 res += (chunk_len >> 8) & 0xff;
1230 res += chunk_len & 0xff;
1231 for (i = 0; i < chunk_len - 2; i++)
1233 if (checksum != res) {
1266 for (sb = 0; sb < s->
nsubbands / 4; sb++) {
1274 for (group = 0; group < 5; group++) {
1275 for (sf = 0; sf < 1 << group; sf++) {
1276 int sf_idx = ((s->
framenum << group) + sf) & 31;
1284 chunk_id = bytestream2_get_byte(&gb);
1285 chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
1297 chunk.lfe.len = chunk_len;
1298 chunk.lfe.data = gb.
buffer;
1304 chunk.tonal.id = chunk_id;
1305 chunk.tonal.len = chunk_len;
1306 chunk.tonal.data = gb.
buffer;
1315 chunk.tonal_grp[
i].id =
i;
1316 chunk.tonal_grp[
i].len = chunk_len;
1317 chunk.tonal_grp[
i].data = gb.
buffer;
1326 chunk.tonal_grp[
i].id =
i;
1327 chunk.tonal_grp[
i].len = chunk_len;
1328 chunk.tonal_grp[
i].data = gb.
buffer;
1335 chunk.grid1[
i].len = chunk_len;
1336 chunk.grid1[
i].data = gb.
buffer;
1343 chunk.hr_grid[
i].len = chunk_len;
1344 chunk.hr_grid[
i].data = gb.
buffer;
1351 chunk.ts1[
i].len = chunk_len;
1352 chunk.ts1[
i].data = gb.
buffer;
1359 chunk.ts2[
i].len = chunk_len;
1360 chunk.ts2[
i].data = gb.
buffer;
1372 for (i = 0; i < 5; i++)
1375 for (i = 0; i < (s->
nchannels + 1) / 2; i++) {
1386 if (!chunk.grid1[i].len || !chunk.hr_grid[i].len || !chunk.ts1[i].len)
1409 for (ch = ch1; ch <= ch2; ch++) {
1422 for (i = 0; i < 8; i++) {
1423 int scf = w1 * g1_scf_a[
i] + w2 * g1_scf_b[
i];
1424 hr_scf[
i] = scf >> 7;
1430 for (i = 0; i < 8; i++) {
1431 int scf = w1 * g1_scf_a[
i] + w2 * g1_scf_b[
i];
1432 hr_scf[
i] = (scf >> 7) - g3_avg - g3_scf[i];
1444 int i, j, k, ch, sb;
1446 for (ch = ch1; ch <= ch2; ch++) {
1456 }
else if (sb < 10) {
1461 float accum[8] = { 0 };
1464 for (k = 2; k < 6; k++) {
1466 for (j = 0; j < 8; j++)
1467 accum[j] +=
fabs(other[j]);
1470 for (j = 0; j < 8; j++)
1471 samples[j] = (accum[j] * 0.25
f + 0.5
f) *
lbr_rand(s, sb);
1482 for (i = 0; i < nsamples; i++) {
1484 for (j = 0; j < 8; j++)
1485 res += coeff[j] * samples[i - j - 1];
1495 for (ch = ch1; ch <= ch2; ch++) {
1498 if (!(s->
ch_pres[ch] & (1
U << sb)))
1518 for (ch = ch1; ch <= ch2; ch++) {
1523 unsigned int scf = hr_scf[
i];
1526 for (j = 0; j < 16; j++)
1532 unsigned int scf = hr_scf[i / 8] - g2_scf[
i];
1545 int ch2_pres = s->
ch_pres[ch2] & (1
U << sb);
1552 if (lrms && ch2_pres) {
1554 for (j = 0; j < 16; j++) {
1555 float tmp = samples_l[j];
1556 samples_l[j] = samples_r[j];
1557 samples_r[j] = -
tmp;
1560 for (j = 0; j < 16; j++) {
1561 float tmp = samples_l[j];
1562 samples_l[j] = samples_r[j];
1566 }
else if (!ch2_pres) {
1568 for (j = 0; j < 16; j++)
1569 samples_r[j] = -samples_l[j];
1571 for (j = 0; j < 16; j++)
1572 samples_r[j] = samples_l[j];
1575 }
else if (sbms && ch2_pres) {
1576 for (j = 0; j < 16; j++) {
1577 float tmp = samples_l[j];
1578 samples_l[j] = (tmp + samples_r[j]) * 0.5
f;
1579 samples_r[j] = (tmp - samples_r[j]) * 0.5
f;
1601 for (ch = ch1; ch <= ch2; ch++) {
1609 for (sf = 1; sf <= 4; sf++, samples += 32) {
1613 for (i = 0; i < 32; i++)
1614 samples[i] *= (32 - i) * prev + i * next;
1624 int group,
int group_sf,
int synth_idx)
1634 for (i = 0; i <
count; i++) {
1640 float s = amp *
cos_tab[(t->
phs[ch] + 64) & 255];
1648 values[3] += cf[0] * -
s;
1649 values[2] += cf[1] *
c;
1650 values[1] += cf[2] *
s;
1651 values[0] += cf[3] * -
c;
1654 values[2] += cf[0] * -
s;
1655 values[1] += cf[1] *
c;
1656 values[0] += cf[2] *
s;
1659 values[1] += cf[0] * -
s;
1660 values[0] += cf[1] *
c;
1663 values[0] += cf[0] * -
s;
1667 values[x_freq - 5] += cf[ 0] * -
s;
1668 p4: values[x_freq - 4] += cf[ 1] *
c;
1669 p3: values[x_freq - 3] += cf[ 2] *
s;
1670 p2: values[x_freq - 2] += cf[ 3] * -
c;
1671 p1: values[x_freq - 1] += cf[ 4] * -
s;
1672 p0: values[x_freq ] += cf[ 5] *
c;
1673 values[x_freq + 1] += cf[ 6] *
s;
1674 values[x_freq + 2] += cf[ 7] * -
c;
1675 values[x_freq + 3] += cf[ 8] * -
s;
1676 values[x_freq + 4] += cf[ 9] *
c;
1677 values[x_freq + 5] += cf[10] *
s;
1692 for (group = 0; group < 5; group++) {
1693 int group_sf = (s->
framenum << group) + ((sf - 22) >> (5 - group));
1694 int synth_idx = ((((sf - 22) & 31) << group) & 31) + (1 << group) - 1;
1696 synth_tones(s, ch, values, group, (group_sf - 1) & 31, 30 - synth_idx);
1697 synth_tones(s, ch, values, group, (group_sf ) & 31, synth_idx);
1708 if (nsubbands < noutsubbands)
1709 memset(
values[nsubbands], 0, (noutsubbands - nsubbands) *
sizeof(
values[0]));
1722 s->
history[ch], noutsubbands * 4);
1724 s->
window, noutsubbands * 4);
1725 output += noutsubbands * 4;
1729 for (sb = 0; sb < nsubbands; sb++) {
1738 int i,
ret, nchannels, ch_conf = (s->
ch_mask & 0x7) - 1;
1739 const int8_t *reorder;
1762 for (i = 0; i < (s->
nchannels + 1) / 2; i++) {
1775 if (ch1 < nchannels)
1778 if (ch1 != ch2 && ch2 < nchannels)
static void parse_grid_3(DCALbrDecoder *s, int ch1, int ch2, int sb, int flag)
int ntones
Circular buffer head position.
static int parse_grid_1_sec_ch(DCALbrDecoder *s, int ch2)
const float ff_dca_rsd_level_2b[2]
static int parse_tonal_chunk(DCALbrDecoder *s, LBRChunk *chunk)
float window[DCA_LBR_SUBBANDS *4]
Long window for IMDCT.
static void synth_lpc(DCALbrDecoder *s, int ch1, int ch2, int sb)
#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.
const float ff_dca_st_coeff[34]
void(* lbr_bank)(float output[32][4], float **input, const float *coeff, ptrdiff_t ofs, ptrdiff_t len)
int bit_rate_scaled
Scaled bit rate.
ptrdiff_t const GLvoid * data
int ff_dca_lbr_parse(DCALbrDecoder *s, uint8_t *data, DCAExssAsset *asset)
uint8_t grid_2_scf[DCA_LBR_CHANNELS][3][64]
Grid 2 scale factors.
uint32_t ch_pres[DCA_LBR_CHANNELS]
Subband allocation flags.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
const int8_t ff_dca_ph0_shift[8]
#define AV_CH_LAYOUT_SURROUND
#define DCA_LBR_CHANNELS_TOTAL
int max_mono_subband
Subband index where mono encoding ends.
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
unsigned int ts_size
Time sample buffer size.
const uint8_t ff_dca_scf_to_grid_1[32]
static float cos_tab[256]
static int parse_st_code(GetBitContext *s, int min_v)
int nchannels_total
Total number of fullband channels.
int freq_range
Frequency range of LBR audio.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
const float ff_dca_lfe_step_size_24[144]
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define FF_PROFILE_DTS_EXPRESS
uint8_t x_freq
Spectral line offset.
const uint16_t ff_dca_rsd_pack_5_in_8[256]
static int parse_lfe_16(DCALbrDecoder *s)
#define FF_ARRAY_ELEMS(a)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_CH_LAYOUT_STEREO
int bit_rate_orig
Original bit rate.
static int init_sample_rate(DCALbrDecoder *s)
const float ff_dca_quant_amp[57]
#define AV_CH_LAYOUT_5POINT0
static int parse_grid_1_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
float * ts_buffer
Time sample buffer base.
const uint8_t ff_dca_freq_ranges[16]
float sb_scf[DCA_LBR_SUBBANDS]
Subband randomization scale factors.
float lfe_scale
Scale factor of LFE samples before IIR filter.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int ensure_bits(GetBitContext *s, int n)
Check point to ensure that enough bits are left.
enum AVSampleFormat sample_fmt
audio sample format
static void filter_ts(DCALbrDecoder *s, int ch1, int ch2)
int ch_mask
LBR speaker mask.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
uint8_t part_stereo_pres
Partial stereo coefficients presence flags.
#define LOCAL_ALIGNED_32(t, v,...)
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
GLsizei GLboolean const GLfloat * value
static void random_ts(DCALbrDecoder *s, int ch1, int ch2)
Fill unallocated subbands with randomness.
#define AV_CH_LOW_FREQUENCY
static void parse_ch(DCALbrDecoder *s, int ch, int sb, int quant_level, int flag)
Parse time samples for one subband, filling truncated samples with randomness.
uint8_t phs[DCA_LBR_CHANNELS]
Per-channel phase.
static int parse_lfe_chunk(DCALbrDecoder *s, LBRChunk *chunk)
static void transform_channel(DCALbrDecoder *s, int ch, float *output)
int nchannels
Number of fullband channels to decode.
int sample_rate
Sample rate of LBR audio.
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static int get_bits_left(GetBitContext *gb)
static float lbr_rand(DCALbrDecoder *s, int sb)
const int8_t ff_dca_lfe_delta_index_16[8]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
DCALbrTone tones[DCA_LBR_TONES]
Circular buffer of tones.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
uint8_t tonal_scf[6]
Tonal scale factors.
static __device__ float fabs(float a)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
uint8_t ph_rot
Phase rotation.
int warned
Flags for warning suppression.
const float ff_dca_rsd_level_5[5]
static av_cold void init_tables(void)
float lfe_history[5][2]
LFE IIR filter history.
const uint32_t ff_dca_sampling_freqs[16]
uint8_t part_stereo[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS/4][5]
Partial stereo coefficients.
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
int lbr_offset
Offset to LBR component from start of substream.
uint8_t amp[DCA_LBR_CHANNELS]
Per-channel amplitude.
#define DCA_SPEAKER_LAYOUT_STEREO
static int parse_tonal_group(DCALbrDecoder *s, LBRChunk *chunk)
uint64_t channel_layout
Audio channel layout.
uint16_t tonal_bounds[5][32][2]
Per-group per-subframe start/end positions of tones.
static int alloc_sample_buffer(DCALbrDecoder *s)
const float ff_dca_synth_env[32]
static void base_func_synth(DCALbrDecoder *s, int ch, float *values, int sf)
Synthesise all tones in all groups for the given residual subframe.
audio channel layout utility functions
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
Allocate and clear a buffer, reusing the given one if large enough.
const float ff_dca_rsd_level_8[8]
const uint8_t ff_dca_scf_to_grid_2[32]
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
const uint16_t ff_dca_avg_g3_freqs[3]
int lbr_rand
Seed for subband randomization.
const float ff_dca_rsd_level_16[16]
uint8_t sec_ch_sbms[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Right channel inversion or mid/side decoding flags.
int8_t grid_3_avg[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS-4]
Grid 3 average values.
int nsubbands
Number of encoded subbands.
av_cold void ff_dca_lbr_flush(DCALbrDecoder *s)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
av_cold void ff_dca_lbr_close(DCALbrDecoder *s)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define AV_EF_EXPLODE
abort decoding on minor error detection
static int parse_lpc(DCALbrDecoder *s, int ch1, int ch2, int start_sb, int end_sb)
static int parse_ts(DCALbrDecoder *s, int ch1, int ch2, int start_sb, int end_sb, int flag)
#define AV_CH_FRONT_CENTER
uint8_t grid_1_scf[DCA_LBR_CHANNELS][12][8]
Grid 1 scale factors.
static volatile int checksum
const float ff_dca_bank_coeff[10]
VLC ff_dca_vlc_tnl_grp[5]
static const uint8_t channel_counts[7]
int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
static void predict(float *samples, const float *coeff, int nsamples)
static int parse_high_res_grid(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int parse_ts2_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
float lpc_coeff[2][DCA_LBR_CHANNELS][3][2][8]
Predictor coefficients.
static const int8_t channel_reorder_lfe[7][5]
const float ff_dca_corr_cf[32][11]
float history[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS *4]
IMDCT history.
const float ff_dca_lfe_iir[5][4]
int8_t grid_3_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS-4][8]
Grid 3 scale factors.
int sample_rate
samples per second
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
int band_limit
Band limit factor.
main external API structure.
static int parse_ts1_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int lbr_size
Size of LBR component in extension substream.
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2]...the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so...,+,-,+,-,+,+,-,+,-,+,...hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32-hcoeff[1]-hcoeff[2]-...a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2}an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||.........intra?||||:Block01:yes no||||:Block02:.................||||:Block03::y DC::ref index:||||:Block04::cb DC::motion x:||||.........:cr DC::motion y:||||.................|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------------------------------|||Y subbands||Cb subbands||Cr subbands||||------||------||------|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||------||------||------||||------||------||------|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||------||------||------||||------||------||------|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||------||------||------||||------||------||------|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------------------------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction------------|\Dequantization-------------------\||Reference frames|\IDWT|--------------|Motion\|||Frame 0||Frame 1||Compensation.OBMC v-------|--------------|--------------.\------> Frame n output Frame Frame<----------------------------------/|...|-------------------Range Coder:============Binary Range Coder:-------------------The implemented range coder is an adapted version based upon"Range encoding: an algorithm for removing redundancy from a digitised message."by G.N.N.Martin.The symbols encoded by the Snow range coder are bits(0|1).The associated probabilities are not fix but change depending on the symbol mix seen so far.bit seen|new state---------+-----------------------------------------------0|256-state_transition_table[256-old_state];1|state_transition_table[old_state];state_transition_table={0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:-------------------------FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1.the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
const uint8_t ff_dca_freq_to_sb[32]
#define AV_EF_CAREFUL
consider things that violate the spec, are fast to calculate and have not been seen in the wild as er...
static int parse_tonal(DCALbrDecoder *s, int group)
static unsigned int get_bits1(GetBitContext *s)
static const uint16_t channel_layouts[7]
int res_profile
Resolution profile.
const float ff_dca_long_window[128]
static void convert_lpc(float *coeff, const int *codes)
Convert from reflection coefficients to direct form coefficients.
uint8_t sb_indices[DCA_LBR_SUBBANDS]
Subband reordering indices.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data...
const uint8_t ff_dca_rsd_pack_3_in_7[128][3]
int limited_range
Band limited frequency range.
static int parse_lfe_24(DCALbrDecoder *s)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
const float ff_dca_rsd_level_3[3]
static int ff_dca_count_chs_for_mask(unsigned int mask)
Return number of individual channels in DCASpeakerPair mask.
uint8_t f_delt
Difference between original and center frequency.
#define DCA_LBR_TIME_HISTORY
int framenum
Lower 5 bits of current frame number.
int limited_rate
Band limited sample rate.
uint8_t sec_ch_lrms[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Flags indicating if left/right channel are swapped.
const uint8_t ff_dca_grid_1_to_scf[11]
float lfe_data[64]
Decimated LFE samples.
#define DCA_LBR_TIME_SAMPLES
uint32_t grid_3_pres[DCA_LBR_CHANNELS]
Grid 3 scale factors presence flags.
const float ff_dca_rsd_level_2a[2]
const uint16_t ff_dca_fst_amp[44]
const float ff_dca_lfe_step_size_16[101]
void(* vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len)
Calculate the entry wise product of two vectors of floats, add a third vector of floats and store the...
int request_channel_layout
Converted from avctx.request_channel_layout.
static int parse_grid_2(DCALbrDecoder *s, int ch1, int ch2, int start_sb, int end_sb, int flag)
static int parse_vlc(GetBitContext *s, VLC *vlc, int max_depth)
float * time_samples[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS]
Time samples.
VLC ff_dca_vlc_fst_rsd_amp
static av_always_inline int diff(const uint32_t a, const uint32_t b)
int channels
number of audio channels
VLC_TYPE(* table)[2]
code, bits
static int parse_scale_factors(DCALbrDecoder *s, uint8_t *scf)
static const double coeff[2][5]
const uint8_t ff_dca_sb_reorder[8][8]
static const int8_t channel_reorder_nolfe[7][5]
static void decode_part_stereo(DCALbrDecoder *s, int ch1, int ch2)
Modulate by interpolated partial stereo coefficients.
and forward the result(frame or status change) to the corresponding input.If nothing is possible
Filter the word “frame” indicates either a video frame or a group of audio samples
int flags
Flags for LBR decoder initialization.
static void synth_tones(DCALbrDecoder *s, int ch, float *values, int group, int group_sf, int synth_idx)
Synthesise tones in the given group for the given tonal subframe.
av_cold int ff_dca_lbr_init(DCALbrDecoder *s)
uint8_t quant_levels[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Quantization levels.
const int8_t ff_dca_lfe_delta_index_24[32]
static const uint8_t lfe_index[7]
int min_mono_subband
Subband index where mono encoding starts.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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.Frame references ownership and permissions
const uint8_t ff_dca_grid_2_to_scf[3]
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
void(* lfe_iir)(float *output, const float *input, const float iir[5][4], float hist[5][2], ptrdiff_t factor)
int nb_samples
number of audio samples (per channel) described by this frame
int g3_avg_only_start_sb
Subband index where grid 3 scale factors end.
static int parse_decoder_init(DCALbrDecoder *s, GetByteContext *gb)
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
uint8_t high_res_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS][8]
High-frequency resolution scale factors.
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
static void decode_grid(DCALbrDecoder *s, int ch1, int ch2)
Reconstruct high-frequency resolution grid from first and third grids.
const uint8_t ff_dca_grid_1_weights[12][32]
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats, and store the result in a vector of floats...