GetBitContext *gb, SBRData *ch_data)
{
int i;
+ unsigned bs_pointer;
+ int abs_bord_lead = 0;
+ // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots
+ int abs_bord_trail = 16;
+ int num_rel_lead, num_rel_trail;
+ uint8_t bs_rel_bord[2][3];
ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env[1]];
ch_data->bs_num_env[0] = ch_data->bs_num_env[1];
switch (ch_data->bs_frame_class = get_bits(gb, 2)) {
case FIXFIX:
ch_data->bs_num_env[1] = 1 << get_bits(gb, 2);
+ num_rel_lead = ch_data->bs_num_env[1] - 1;
if (ch_data->bs_num_env[1] == 1)
ch_data->bs_amp_res = 0;
return -1;
}
- ch_data->bs_pointer = 0;
+ bs_pointer = 0;
ch_data->bs_freq_res[1] = get_bits1(gb);
for (i = 1; i < ch_data->bs_num_env[1]; i++)
ch_data->bs_freq_res[i + 1] = ch_data->bs_freq_res[1];
break;
case FIXVAR:
- ch_data->bs_var_bord[1] = get_bits(gb, 2);
- ch_data->bs_num_rel[1] = get_bits(gb, 2);
- ch_data->bs_num_env[1] = ch_data->bs_num_rel[1] + 1;
+ abs_bord_trail += get_bits(gb, 2);
+ num_rel_trail = get_bits(gb, 2);
+ num_rel_lead = 0;
+ ch_data->bs_num_env[1] = num_rel_trail + 1;
- for (i = 0; i < ch_data->bs_num_rel[1]; i++)
- ch_data->bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2;
+ for (i = 0; i < num_rel_trail; i++)
+ bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2;
- ch_data->bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]);
+ bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]);
for (i = 0; i < ch_data->bs_num_env[1]; i++)
ch_data->bs_freq_res[ch_data->bs_num_env[1] - i] = get_bits1(gb);
break;
case VARFIX:
- ch_data->bs_var_bord[0] = get_bits(gb, 2);
- ch_data->bs_num_rel[0] = get_bits(gb, 2);
- ch_data->bs_num_env[1] = ch_data->bs_num_rel[0] + 1;
+ abs_bord_lead = get_bits(gb, 2);
+ num_rel_lead = get_bits(gb, 2);
+ ch_data->bs_num_env[1] = num_rel_lead + 1;
- for (i = 0; i < ch_data->bs_num_rel[0]; i++)
- ch_data->bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2;
+ for (i = 0; i < num_rel_lead; i++)
+ bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2;
- ch_data->bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]);
+ bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]);
get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]);
break;
case VARVAR:
- ch_data->bs_var_bord[0] = get_bits(gb, 2);
- ch_data->bs_var_bord[1] = get_bits(gb, 2);
- ch_data->bs_num_rel[0] = get_bits(gb, 2);
- ch_data->bs_num_rel[1] = get_bits(gb, 2);
- ch_data->bs_num_env[1] = ch_data->bs_num_rel[0] + ch_data->bs_num_rel[1] + 1;
+ abs_bord_lead = get_bits(gb, 2);
+ abs_bord_trail += get_bits(gb, 2);
+ num_rel_lead = get_bits(gb, 2);
+ num_rel_trail = get_bits(gb, 2);
+ ch_data->bs_num_env[1] = num_rel_lead + num_rel_trail + 1;
if (ch_data->bs_num_env[1] > 5) {
av_log(ac->avccontext, AV_LOG_ERROR,
return -1;
}
- for (i = 0; i < ch_data->bs_num_rel[0]; i++)
- ch_data->bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2;
- for (i = 0; i < ch_data->bs_num_rel[1]; i++)
- ch_data->bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2;
+ for (i = 0; i < num_rel_lead; i++)
+ bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2;
+ for (i = 0; i < num_rel_trail; i++)
+ bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2;
- ch_data->bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]);
+ bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]);
get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]);
break;
}
- if (ch_data->bs_pointer > ch_data->bs_num_env[1] + 1) {
+ if (bs_pointer > ch_data->bs_num_env[1] + 1) {
av_log(ac->avccontext, AV_LOG_ERROR,
"Invalid bitstream, bs_pointer points to a middle noise border outside the time borders table: %d\n",
- ch_data->bs_pointer);
- return -1;
- }
-
- int abs_bord_lead = ch_data->bs_frame_class >= 2 ? ch_data->bs_var_bord[0] : 0;
- // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots
- int abs_bord_trail = (ch_data->bs_frame_class & 1 ? ch_data->bs_var_bord[1] : 0) + 16;
- int n_rel_lead;
-
- if (ch_data->bs_frame_class == FIXFIX) {
- n_rel_lead = ch_data->bs_num_env[1] - 1;
- } else if (ch_data->bs_frame_class == FIXVAR) {
- n_rel_lead = 0;
- } else if (ch_data->bs_frame_class < 4) { // VARFIX or VARVAR
- n_rel_lead = ch_data->bs_num_rel[0];
- } else {
- av_log(ac->avccontext, AV_LOG_ERROR,
- "Invalid bs_frame_class for SBR: %d\n", ch_data->bs_frame_class);
+ bs_pointer);
return -1;
}
if (ch_data->bs_frame_class == FIXFIX) {
int temp = (abs_bord_trail + (ch_data->bs_num_env[1] >> 1)) /
ch_data->bs_num_env[1];
- for (i = 0; i < n_rel_lead; i++)
+ for (i = 0; i < num_rel_lead; i++)
ch_data->t_env[i + 1] = ch_data->t_env[i] + temp;
} else if (ch_data->bs_frame_class > 1) { // VARFIX or VARVAR
- for (i = 0; i < n_rel_lead; i++)
- ch_data->t_env[i + 1] = ch_data->t_env[i] + ch_data->bs_rel_bord[0][i];
+ for (i = 0; i < num_rel_lead; i++)
+ ch_data->t_env[i + 1] = ch_data->t_env[i] + bs_rel_bord[0][i];
} else { // FIXVAR
- for (i = 0; i < n_rel_lead; i++)
+ for (i = 0; i < num_rel_lead; i++)
ch_data->t_env[i + 1] = abs_bord_lead;
}
if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
- for (i = ch_data->bs_num_env[1] - 1; i > n_rel_lead; i--)
+ for (i = ch_data->bs_num_env[1] - 1; i > num_rel_lead; i--)
ch_data->t_env[i] = ch_data->t_env[i + 1] -
- ch_data->bs_rel_bord[1][ch_data->bs_num_env[1] - 1 - i];
+ bs_rel_bord[1][ch_data->bs_num_env[1] - 1 - i];
} else { // FIXFIX or VARFIX
- for (i = n_rel_lead; i < ch_data->bs_num_env[1]; i++)
+ for (i = num_rel_lead; i < ch_data->bs_num_env[1]; i++)
ch_data->t_env[i + 1] = abs_bord_trail;
}
if (ch_data->bs_frame_class == FIXFIX) {
idx = ch_data->bs_num_env[1] >> 1;
} else if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
- idx = ch_data->bs_num_env[1] - FFMAX(ch_data->bs_pointer - 1, 1);
+ idx = ch_data->bs_num_env[1] - FFMAX(bs_pointer - 1, 1);
} else { // VARFIX
- if (!ch_data->bs_pointer)
+ if (!bs_pointer)
idx = 1;
- else if (ch_data->bs_pointer == 1)
+ else if (bs_pointer == 1)
idx = ch_data->bs_num_env[1] - 1;
else // bs_pointer > 1
- idx = ch_data->bs_pointer - 1;
+ idx = bs_pointer - 1;
}
ch_data->t_q[1] = ch_data->t_env[idx];
ch_data->t_q[2] = ch_data->t_env[ch_data->bs_num_env[1]];
ch_data->e_a[0] = -(ch_data->e_a[1] != ch_data->bs_num_env[0]); // l_APrev
ch_data->e_a[1] = -1;
- if ((ch_data->bs_frame_class & 1) && ch_data->bs_pointer) { // FIXVAR or VARVAR and bs_pointer != 0
- ch_data->e_a[1] = ch_data->bs_num_env[1] + 1 - ch_data->bs_pointer;
- } else if ((ch_data->bs_frame_class == 2) && (ch_data->bs_pointer > 1)) // VARFIX and bs_pointer > 1
- ch_data->e_a[1] = ch_data->bs_pointer - 1;
+ if ((ch_data->bs_frame_class & 1) && bs_pointer) { // FIXVAR or VARVAR and bs_pointer != 0
+ ch_data->e_a[1] = ch_data->bs_num_env[1] + 1 - bs_pointer;
+ } else if ((ch_data->bs_frame_class == 2) && (bs_pointer > 1)) // VARFIX and bs_pointer > 1
+ ch_data->e_a[1] = bs_pointer - 1;
return 0;
}
//These variables are read from the bitstream and therefore copied
memcpy(dst->bs_freq_res+1, src->bs_freq_res+1, sizeof(dst->bs_freq_res)-sizeof(*dst->bs_freq_res));
memcpy(dst->bs_num_env+1, src->bs_num_env+1, sizeof(dst->bs_num_env)- sizeof(*dst->bs_num_env));
- memcpy(dst->bs_var_bord, src->bs_var_bord, sizeof(dst->bs_var_bord));
- memcpy(dst->bs_rel_bord, src->bs_rel_bord, sizeof(dst->bs_rel_bord));
- memcpy(dst->bs_num_rel, src->bs_num_rel, sizeof(dst->bs_rel_bord));
memcpy(dst->t_env, src->t_env, sizeof(dst->t_env));
memcpy(dst->t_q, src->t_q, sizeof(dst->t_q));
dst->bs_amp_res = src->bs_amp_res;
dst->bs_num_noise = src->bs_num_noise;
- dst->bs_pointer = src->bs_pointer;
dst->bs_frame_class = src->bs_frame_class;
dst->e_a[1] = src->e_a[1];
}