int has_band_ext;
int has_band_ext_data;
int band_ext_q_unit;
- int band_ext_mode;
/* Gradient */
int grad_mode;
if (grad_range[0] >= grad_range[1] || grad_range[1] > 47)
return AVERROR_INVALIDDATA;
- if (grad_value[0] >= grad_value[1] || grad_value[1] >= 32)
+ if (grad_value[0] > 31 || grad_value[1] > 31)
return AVERROR_INVALIDDATA;
if (b->grad_boundary > b->q_unit_cnt)
return 0;
if (!b->has_band_ext) {
- b->band_ext_mode = get_bits(gb, 2);
+ skip_bits(gb, 2);
skip_bits_long(gb, get_bits(gb, 5));
return 0;
}
av_bmg_get(&s->lfg, tmp);
c->coeffs[start + i + 0] = tmp[0];
c->coeffs[start + i + 1] = tmp[1];
- maxval = FFMAX(FFABS(tmp[0]), FFMAX(FFABS(tmp[1]), maxval));
+ maxval = FFMAX(FFMAX(FFABS(tmp[0]), FFABS(tmp[1])), maxval);
}
/* Normalize */
for (int i = 0; i < count; i++)
static inline void apply_band_extension(ATRAC9Context *s, ATRAC9BlockData *b,
const int stereo)
{
- const int bc = at9_tab_band_ext_group[b->q_unit_cnt - 13][2];
const int g_units[4] = { /* A, B, C, total units */
b->q_unit_cnt,
at9_tab_band_ext_group[b->q_unit_cnt - 13][0],
switch (c->band_ext) {
case 0: {
- int l;
float sf[6] = { 0.0f };
+ const int l = g_units[3] - g_units[0] - 1;
const int n_start = at9_q_unit_to_coeff_idx[g_units[3] - 1];
const int n_cnt = at9_q_unit_to_coeff_cnt[g_units[3] - 1];
- switch (bc) {
+ switch (at9_tab_band_ext_group[b->q_unit_cnt - 13][2]) {
case 3:
sf[0] = at9_band_ext_scales_m0[0][0][c->band_ext_data[0]];
sf[1] = at9_band_ext_scales_m0[0][1][c->band_ext_data[0]];
break;
}
- l = g_units[3] - g_units[0] - 1;
sf[l] = at9_scalefactor_c[c->scalefactors[g_units[0]]];
fill_with_noise(s, c, n_start, n_cnt);
const int reuse_params = get_bits1(gb);
const int stereo = s->block_config->type[block_idx] == ATRAC9_BLOCK_TYPE_CPE;
+ if (s->block_config->type[block_idx] == ATRAC9_BLOCK_TYPE_LFE) {
+ ATRAC9ChannelData *c = &b->channel[0];
+ const int precision = reuse_params ? 8 : 4;
+ c->q_unit_cnt = b->q_unit_cnt = 2;
+
+ memset(c->scalefactors, 0, sizeof(c->scalefactors));
+ memset(c->q_coeffs_fine, 0, sizeof(c->q_coeffs_fine));
+ memset(c->q_coeffs_coarse, 0, sizeof(c->q_coeffs_coarse));
+
+ for (int i = 0; i < b->q_unit_cnt; i++) {
+ c->scalefactors[i] = get_bits(gb, 5);
+ c->precision_coarse[i] = precision;
+ c->precision_fine[i] = 0;
+ }
+
+ for (int i = 0; i < c->q_unit_cnt; i++) {
+ const int start = at9_q_unit_to_coeff_idx[i + 0];
+ const int end = at9_q_unit_to_coeff_idx[i + 1];
+ for (int j = start; j < end; j++)
+ c->q_coeffs_coarse[j] = get_bits(gb, c->precision_coarse[i] + 1);
+ }
+
+ dequantize (s, b, c);
+ apply_scalefactors(s, b, 0);
+
+ goto imdct;
+ }
+
if (first_in_pkt && reuse_params) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid block flags!\n");
return AVERROR_INVALIDDATA;
apply_scalefactors (s, b, stereo);
apply_band_extension (s, b, stereo);
- /* iMDCT */
+imdct:
for (int i = 0; i <= stereo; i++) {
ATRAC9ChannelData *c = &b->channel[i];
const int dst_idx = s->block_config->plane_map[block_idx][i];