21 #define BITSTREAM_READER_LE
86 { 0, -1, -1, -1, -1 },
96 { 0, -1, -1, -1, -1 },
134 for (i = 0; i < 256; i++)
137 for (i = 0; i < 16; i++)
138 lpc_tab[i] = sin((i - 8) * (
M_PI / ((i < 8) ? 17 : 15)));
146 int i, ps, si, code, step_i;
152 value = (((ps & 0x7fffff) ^ -si) + si) * (1.0f / 0x7fffff);
155 if (step_i > step_max) {
162 for (i = 0; i < 64; i++) {
165 delta = step * 0.03125f;
169 delta += step * 0.5f;
171 delta += step * 0.25f;
173 delta += step * 0.125f;
175 delta += step * 0.0625f;
188 step_i = av_clip(step_i, 0, step_max);
200 int i, ps, si, code, step_i;
206 value = (((ps & 0x7fff) ^ -si) + si) * (1.0f / 0x7fff);
209 if (step_i > step_max) {
216 for (i = 0; i < 64; i++) {
219 delta = step * 0.125f;
223 delta += step * 0.5f;
225 delta += step * 0.25f;
238 step_i = av_clip(step_i, 0, step_max);
259 if (chunk->
len >= 52)
261 if (chunk->
len >= 35)
282 int sf, sf_idx,
ch, main_ch, freq;
286 for (sf = 0; sf < 1 << group; sf += diff ? 8 : 1) {
287 sf_idx = ((s->
framenum << group) + sf) & 31;
291 for (freq = 1;; freq++) {
308 if (freq >> (5 - group) > s->
nsubbands * 4 - 6) {
318 amp[main_ch] = main_amp <
AMP_MAX ? main_amp : 0;
339 t->
x_freq = freq >> (5 - group);
340 t->
f_delt = (freq & ((1 << (5 - group)) - 1)) << group;
375 for (sb = 0; sb < 6; sb++)
381 for (group = 0; group < 5; group++)
417 int i, sf, prev, next, dist;
426 for (sf = 0; sf < 7; sf += dist) {
446 next = prev + ((next + 1) >> 1);
448 next = prev - ( next >> 1);
454 scf[sf + 1] = prev + ((next - prev) >> 1);
456 scf[sf + 1] = prev - ((prev - next) >> 1);
461 scf[sf + 1] = prev + ( (next - prev) >> 2);
462 scf[sf + 2] = prev + ( (next - prev) >> 1);
463 scf[sf + 3] = prev + (((next - prev) * 3) >> 2);
465 scf[sf + 1] = prev - ( (prev - next) >> 2);
466 scf[sf + 2] = prev - ( (prev - next) >> 1);
467 scf[sf + 3] = prev - (((prev - next) * 3) >> 2);
472 for (i = 1; i < dist; i++)
473 scf[sf + i] = prev + (next - prev) * i / dist;
501 int ch, sb, sf, nsubbands;
511 for (sb = 2; sb < nsubbands; sb++) {
523 for (sb = 0; sb < s->
nsubbands - 4; sb++) {
549 for (sb = 0; sb < nsubbands; sb++)
550 for (ch = ch1; ch <= ch2; ch++)
551 for (sf = 1; sf <= 4; sf++)
569 for (sb = 2; sb < nsubbands; sb++) {
576 for (sb = 0; sb < s->
nsubbands - 4; sb++) {
591 for (ch = ch1; ch <= ch2; ch++) {
598 for (i = 0; i < 8; i++) {
621 int i, j, code, nblocks, coding_method;
628 switch (quant_level) {
631 for (i = 0; i < nblocks; i++, samples += 8) {
633 for (j = 0; j < 8; j++)
649 for (i = 0; i < nblocks; i++, samples += 5) {
651 for (j = 0; j < 5; j++)
660 for (i = 0; i < nblocks; i++, samples += 3) {
662 for (j = 0; j < 3; j++)
675 for (i = 0; i < nblocks; i++)
693 int start_sb,
int end_sb,
int flag)
695 int sb, sb_g3, sb_reorder, quant_level;
697 for (sb = start_sb; sb < end_sb; sb++) {
701 }
else if (flag && sb < s->max_mono_subband) {
718 }
else if (sb < 12 && sb_reorder >= 4) {
739 parse_ch(s, ch1, sb_reorder, quant_level, 0);
741 parse_ch(s, ch2, sb_reorder, quant_level, 1);
743 parse_ch(s, ch1, sb_reorder, quant_level, 0);
745 parse_ch(s, ch2, sb_reorder, quant_level, 0);
759 for (i = 0; i < 8; i++) {
761 for (j = 0; j < (i + 1) / 2; j++) {
762 float tmp1 = coeff[ j ];
763 float tmp2 = coeff[i - j - 1];
764 coeff[ j ] = tmp1 + rc * tmp2;
765 coeff[i - j - 1] = tmp2 + rc * tmp1;
774 int i, sb,
ch, codes[16];
777 for (sb = start_sb; sb < end_sb; sb++) {
778 int ncodes = 8 * (1 + (sb < 2));
779 for (ch = ch1; ch <= ch2; ch++) {
782 for (i = 0; i < ncodes; i++)
784 for (i = 0; i < ncodes / 8; i++)
806 ol = (profile >> 3) & 7;
810 max_sb = profile & 7;
815 int a = 18000 / (12 * f / 1000 + 100 + 40 * st) + 20 * ol;
817 quant_levels[sb] = 1;
819 quant_levels[sb] = 2;
821 quant_levels[sb] = 3;
823 quant_levels[sb] = 4;
825 quant_levels[sb] = 5;
829 for (sb = 0; sb < 8; sb++)
839 if (
parse_ts(s, ch1, ch2, 0, 2, 0) < 0)
843 for (sb = 0; sb < 2; sb++)
844 for (ch = ch1; ch <= ch2; ch++)
852 int start_sb,
int end_sb,
int flag)
854 int i, j, sb,
ch, nsubbands;
857 if (end_sb > nsubbands)
860 for (sb = start_sb; sb < end_sb; sb++) {
861 for (ch = ch1; ch <= ch2; ch++) {
871 for (i = 0; i < 8; i++, g2_scf += 8) {
873 memset(g2_scf, 0, 64 - i * 8);
878 for (j = 0; j < 8; j++) {
884 memset(g2_scf, 0, 8);
901 if (
parse_ts(s, ch1, ch2, 2, 4, 0) < 0)
905 if (
parse_ts(s, ch1, ch2, 4, 6, 0) < 0)
933 double scale = (-1.0 / (1 << 17)) * sqrt(1 << (2 - s->
limited_range));
944 if (br_per_ch < 14000)
946 else if (br_per_ch < 32000)
947 scale = (br_per_ch - 14000) * (1.0 / 120000) + 0.85;
951 scale *= 1.0 / INT_MAX;
957 s->
sb_scf[i] = (i - 1) * 0.25 * 0.785 * scale;
959 s->
sb_scf[i] = 0.785 * scale;
997 unsigned int sr_code;
1000 sr_code = bytestream2_get_byte(gb);
1012 s->
ch_mask = bytestream2_get_le16(gb);
1023 version = bytestream2_get_le16(gb);
1024 if ((version & 0xff00) != 0x0800) {
1030 s->
flags = bytestream2_get_byte(gb);
1044 bit_rate_hi = bytestream2_get_byte(gb);
1047 s->
bit_rate_orig = bytestream2_get_le16(gb) | ((bit_rate_hi & 0x0F) << 16);
1050 s->
bit_rate_scaled = bytestream2_get_le16(gb) | ((bit_rate_hi & 0xF0) << 12);
1157 int i,
ch, sb, sf, ret, group, chunk_id, chunk_len;
1168 switch (bytestream2_get_byte(&gb)) {
1187 chunk_id = bytestream2_get_byte(&gb);
1188 chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
1199 switch (chunk_id & 0x7f) {
1202 int checksum = bytestream2_get_be16(&gb);
1203 uint16_t res = chunk_id;
1204 res += (chunk_len >> 8) & 0xff;
1205 res += chunk_len & 0xff;
1206 for (i = 0; i < chunk_len - 2; i++)
1208 if (checksum != res) {
1241 for (sb = 0; sb < s->
nsubbands / 4; sb++) {
1249 for (group = 0; group < 5; group++) {
1250 for (sf = 0; sf < 1 << group; sf++) {
1251 int sf_idx = ((s->
framenum << group) + sf) & 31;
1259 chunk_id = bytestream2_get_byte(&gb);
1260 chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
1272 chunk.lfe.len = chunk_len;
1273 chunk.lfe.data = gb.
buffer;
1279 chunk.tonal.id = chunk_id;
1280 chunk.tonal.len = chunk_len;
1281 chunk.tonal.data = gb.
buffer;
1290 chunk.tonal_grp[i].id = i;
1291 chunk.tonal_grp[i].len = chunk_len;
1292 chunk.tonal_grp[i].data = gb.
buffer;
1301 chunk.tonal_grp[i].id = i;
1302 chunk.tonal_grp[i].len = chunk_len;
1303 chunk.tonal_grp[i].data = gb.
buffer;
1310 chunk.grid1[i].len = chunk_len;
1311 chunk.grid1[i].data = gb.
buffer;
1318 chunk.hr_grid[i].len = chunk_len;
1319 chunk.hr_grid[i].data = gb.
buffer;
1326 chunk.ts1[i].len = chunk_len;
1327 chunk.ts1[i].data = gb.
buffer;
1334 chunk.ts2[i].len = chunk_len;
1335 chunk.ts2[i].data = gb.
buffer;
1347 for (i = 0; i < 5; i++)
1350 for (i = 0; i < (s->
nchannels + 1) / 2; i++) {
1361 if (!chunk.grid1[i].len || !chunk.hr_grid[i].len || !chunk.ts1[i].len)
1384 for (ch = ch1; ch <= ch2; ch++) {
1397 for (i = 0; i < 8; i++) {
1398 int scf = w1 * g1_scf_a[i] + w2 * g1_scf_b[i];
1399 hr_scf[i] = scf >> 7;
1405 for (i = 0; i < 8; i++) {
1406 int scf = w1 * g1_scf_a[i] + w2 * g1_scf_b[i];
1407 hr_scf[i] = (scf >> 7) - g3_avg - g3_scf[i];
1419 int i, j, k,
ch, sb;
1421 for (ch = ch1; ch <= ch2; ch++) {
1431 }
else if (sb < 10) {
1436 float accum[8] = { 0 };
1439 for (k = 2; k < 6; k++) {
1441 for (j = 0; j < 8; j++)
1442 accum[j] += fabs(other[j]);
1445 for (j = 0; j < 8; j++)
1446 samples[j] = (accum[j] * 0.25f + 0.5f) *
lbr_rand(s, sb);
1457 for (i = 0; i < nsamples; i++) {
1459 for (j = 0; j < 8; j++)
1460 res += coeff[j] * samples[i - j - 1];
1470 for (ch = ch1; ch <= ch2; ch++) {
1473 if (!(s->
ch_pres[ch] & (1
U << sb)))
1493 for (ch = ch1; ch <= ch2; ch++) {
1498 unsigned int scf = hr_scf[i];
1501 for (j = 0; j < 16; j++)
1507 unsigned int scf = hr_scf[i / 8] - g2_scf[i];
1520 int ch2_pres = s->
ch_pres[ch2] & (1
U << sb);
1523 int sbms = (s->
sec_ch_sbms[ch1 / 2][sb] >> i) & 1;
1524 int lrms = (s->
sec_ch_lrms[ch1 / 2][sb] >> i) & 1;
1527 if (lrms && ch2_pres) {
1529 for (j = 0; j < 16; j++) {
1530 float tmp = samples_l[j];
1531 samples_l[j] = samples_r[j];
1532 samples_r[j] = -
tmp;
1535 for (j = 0; j < 16; j++) {
1536 float tmp = samples_l[j];
1537 samples_l[j] = samples_r[j];
1541 }
else if (!ch2_pres) {
1543 for (j = 0; j < 16; j++)
1544 samples_r[j] = -samples_l[j];
1546 for (j = 0; j < 16; j++)
1547 samples_r[j] = samples_l[j];
1550 }
else if (sbms && ch2_pres) {
1551 for (j = 0; j < 16; j++) {
1552 float tmp = samples_l[j];
1553 samples_l[j] = (tmp + samples_r[j]) * 0.5f;
1554 samples_r[j] = (tmp - samples_r[j]) * 0.5f;
1576 for (ch = ch1; ch <= ch2; ch++) {
1584 for (sf = 1; sf <= 4; sf++, samples += 32) {
1588 for (i = 0; i < 32; i++)
1589 samples[i] *= (32 - i) * prev + i * next;
1599 int group,
int group_sf,
int synth_idx)
1609 for (i = 0; i <
count; i++) {
1623 values[3] += cf[0] * -
s;
1624 values[2] += cf[1] *
c;
1625 values[1] += cf[2] *
s;
1626 values[0] += cf[3] * -
c;
1629 values[2] += cf[0] * -
s;
1630 values[1] += cf[1] *
c;
1631 values[0] += cf[2] *
s;
1634 values[1] += cf[0] * -
s;
1635 values[0] += cf[1] *
c;
1638 values[0] += cf[0] * -
s;
1642 values[x_freq - 5] += cf[ 0] * -
s;
1643 p4: values[x_freq - 4] += cf[ 1] *
c;
1644 p3: values[x_freq - 3] += cf[ 2] *
s;
1645 p2: values[x_freq - 2] += cf[ 3] * -
c;
1646 p1: values[x_freq - 1] += cf[ 4] * -
s;
1647 p0: values[x_freq ] += cf[ 5] *
c;
1648 values[x_freq + 1] += cf[ 6] *
s;
1649 values[x_freq + 2] += cf[ 7] * -
c;
1650 values[x_freq + 3] += cf[ 8] * -
s;
1651 values[x_freq + 4] += cf[ 9] *
c;
1652 values[x_freq + 5] += cf[10] *
s;
1667 for (group = 0; group < 5; group++) {
1668 int group_sf = (s->
framenum << group) + ((sf - 22) >> (5 - group));
1669 int synth_idx = ((((sf - 22) & 31) << group) & 31) + (1 << group) - 1;
1671 synth_tones(s, ch, values, group, (group_sf - 1) & 31, 30 - synth_idx);
1672 synth_tones(s, ch, values, group, (group_sf ) & 31, synth_idx);
1683 if (nsubbands < noutsubbands)
1684 memset(values[nsubbands], 0, (noutsubbands - nsubbands) *
sizeof(values[0]));
1697 s->
history[ch], noutsubbands * 4);
1699 s->
window, noutsubbands * 4);
1700 output += noutsubbands * 4;
1704 for (sb = 0; sb < nsubbands; sb++) {
1713 int i, ret, nchannels, ch_conf = (s->
ch_mask & 0x7) - 1;
1714 const int8_t *reorder;
1737 for (i = 0; i < (s->
nchannels + 1) / 2; i++) {
1750 if (ch1 < nchannels)
1753 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]
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.
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]
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...
static int parse_lfe_16(DCALbrDecoder *s)
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.
uint8_t part_stereo_pres
Partial stereo coefficients presence flags.
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 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 av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
void(* lfe_iir)(float *output, const float *input, const float iir[5][4], float hist[5][2], ptrdiff_t factor)
uint8_t ph_rot
Phase rotation.
int warned
Flags for warning suppression.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
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.
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.
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
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]
const uint16_t ff_dca_avg_g3_freqs[3]
GLsizei GLboolean const GLfloat * value
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)
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)
#define FF_ARRAY_ELEMS(a)
static int parse_high_res_grid(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
void(* lbr_bank)(float output[32][4], float **input, const float *coeff, ptrdiff_t ofs, ptrdiff_t len)
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.
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...
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...
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.
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
#define LOCAL_ALIGNED_32(t, v,...)
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]
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.
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.
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
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.
static void decode_grid(DCALbrDecoder *s, int ch1, int ch2)
Reconstruct high-frequency resolution grid from first and third grids.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_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),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){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) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;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)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) 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);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
const uint8_t ff_dca_grid_1_weights[12][32]