aacenc_is: add a flag to use pure coefficients instead

This commit adds a flag to use the pure coefficients instead
of the processed ones (sce->coeffs). This is needed because
IS will apply the changes to the coefficients immediately
before the adjust_common_prediction function and it doesn't
make sense to measure stereo channel coefficient difference
when one of the channels coefficients are all zero.

Therefore add a flag to use pure coefficients in that case.
TNS is the only thing touching the coefficients before IS
so common window prediction will not take that into account
but the effect of the TNS filter per coefficient can be small
(a few percent) so to some approximation it's fine to just
ignore that.

Also fixed a small error which doesn't alter the results
that much. pow(sqrt(number), 3.0/4.0) == pow(number, 3.0/8.0) !=
pow(number, 3.0/4.0).

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
This commit is contained in:
Rostislav Pehlivanov 2015-09-05 08:32:09 +01:00
parent a87ada53c3
commit 4565611b04
3 changed files with 24 additions and 23 deletions

View File

@ -32,39 +32,39 @@
struct AACISError ff_aac_is_encoding_err(AACEncContext *s, ChannelElement *cpe, struct AACISError ff_aac_is_encoding_err(AACEncContext *s, ChannelElement *cpe,
int start, int w, int g, float ener0, int start, int w, int g, float ener0,
float ener1, float ener01, int phase) float ener1, float ener01,
int use_pcoeffs, int phase)
{ {
int i, w2; int i, w2;
SingleChannelElement *sce0 = &cpe->ch[0];
SingleChannelElement *sce1 = &cpe->ch[1];
float *L = use_pcoeffs ? sce0->pcoeffs : sce0->coeffs;
float *R = use_pcoeffs ? sce1->pcoeffs : sce1->coeffs;
float *L34 = &s->scoefs[256*0], *R34 = &s->scoefs[256*1]; float *L34 = &s->scoefs[256*0], *R34 = &s->scoefs[256*1];
float *IS = &s->scoefs[256*2], *I34 = &s->scoefs[256*3]; float *IS = &s->scoefs[256*2], *I34 = &s->scoefs[256*3];
float dist1 = 0.0f, dist2 = 0.0f; float dist1 = 0.0f, dist2 = 0.0f;
struct AACISError is_error = {0}; struct AACISError is_error = {0};
SingleChannelElement *sce0 = &cpe->ch[0];
SingleChannelElement *sce1 = &cpe->ch[1];
for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) { for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {
FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g]; FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];
FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g]; FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g];
int is_band_type, is_sf_idx = FFMAX(1, sce0->sf_idx[(w+w2)*16+g]-4); int is_band_type, is_sf_idx = FFMAX(1, sce0->sf_idx[(w+w2)*16+g]-4);
float e01_34 = phase*pow(sqrt(ener1/ener0), 3.0/4.0); float e01_34 = phase*pow(ener1/ener0, 3.0/4.0);
float maxval, dist_spec_err = 0.0f; float maxval, dist_spec_err = 0.0f;
float minthr = FFMIN(band0->threshold, band1->threshold); float minthr = FFMIN(band0->threshold, band1->threshold);
for (i = 0; i < sce0->ics.swb_sizes[g]; i++) { for (i = 0; i < sce0->ics.swb_sizes[g]; i++)
IS[i] = (sce0->pcoeffs[start+(w+w2)*128+i]+ IS[i] = (L[start+(w+w2)*128+i] + phase*R[start+(w+w2)*128+i])*sqrt(ener0/ener01);
phase*sce1->pcoeffs[start+(w+w2)*128+i])* abs_pow34_v(L34, &L[start+(w+w2)*128], sce0->ics.swb_sizes[g]);
sqrt(ener0/ener01); abs_pow34_v(R34, &R[start+(w+w2)*128], sce0->ics.swb_sizes[g]);
}
abs_pow34_v(L34, &sce0->coeffs[start+(w+w2)*128], sce0->ics.swb_sizes[g]);
abs_pow34_v(R34, &sce1->coeffs[start+(w+w2)*128], sce0->ics.swb_sizes[g]);
abs_pow34_v(I34, IS, sce0->ics.swb_sizes[g]); abs_pow34_v(I34, IS, sce0->ics.swb_sizes[g]);
maxval = find_max_val(1, sce0->ics.swb_sizes[g], I34); maxval = find_max_val(1, sce0->ics.swb_sizes[g], I34);
is_band_type = find_min_book(maxval, is_sf_idx); is_band_type = find_min_book(maxval, is_sf_idx);
dist1 += quantize_band_cost(s, &sce0->coeffs[start + (w+w2)*128], L34, dist1 += quantize_band_cost(s, &L[start + (w+w2)*128], L34,
sce0->ics.swb_sizes[g], sce0->ics.swb_sizes[g],
sce0->sf_idx[(w+w2)*16+g], sce0->sf_idx[(w+w2)*16+g],
sce0->band_type[(w+w2)*16+g], sce0->band_type[(w+w2)*16+g],
s->lambda / band0->threshold, INFINITY, NULL, 0); s->lambda / band0->threshold, INFINITY, NULL, 0);
dist1 += quantize_band_cost(s, &sce1->coeffs[start + (w+w2)*128], R34, dist1 += quantize_band_cost(s, &R[start + (w+w2)*128], R34,
sce1->ics.swb_sizes[g], sce1->ics.swb_sizes[g],
sce1->sf_idx[(w+w2)*16+g], sce1->sf_idx[(w+w2)*16+g],
sce1->band_type[(w+w2)*16+g], sce1->band_type[(w+w2)*16+g],
@ -117,9 +117,9 @@ void ff_aac_search_for_is(AACEncContext *s, AVCodecContext *avctx, ChannelElemen
} }
} }
ph_err1 = ff_aac_is_encoding_err(s, cpe, start, w, g, ph_err1 = ff_aac_is_encoding_err(s, cpe, start, w, g,
ener0, ener1, ener01, -1); ener0, ener1, ener01, 0, -1);
ph_err2 = ff_aac_is_encoding_err(s, cpe, start, w, g, ph_err2 = ff_aac_is_encoding_err(s, cpe, start, w, g,
ener0, ener1, ener01, +1); ener0, ener1, ener01, 0, +1);
erf = ph_err1.error < ph_err2.error ? &ph_err1 : &ph_err2; erf = ph_err1.error < ph_err2.error ? &ph_err1 : &ph_err2;
if (erf->pass) { if (erf->pass) {
cpe->is_mask[w*16+g] = 1; cpe->is_mask[w*16+g] = 1;

View File

@ -43,7 +43,8 @@ struct AACISError {
struct AACISError ff_aac_is_encoding_err(AACEncContext *s, ChannelElement *cpe, struct AACISError ff_aac_is_encoding_err(AACEncContext *s, ChannelElement *cpe,
int start, int w, int g, float ener0, int start, int w, int g, float ener0,
float ener1, float ener01, int phase); float ener1, float ener01,
int use_pcoeffs, int phase);
void ff_aac_search_for_is(AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe); void ff_aac_search_for_is(AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe);
#endif /* AVCODEC_AACENC_IS_H */ #endif /* AVCODEC_AACENC_IS_H */

View File

@ -185,9 +185,9 @@ void ff_aac_adjust_common_prediction(AACEncContext *s, ChannelElement *cpe)
} }
} }
ph_err1 = ff_aac_is_encoding_err(s, cpe, start, w, g, ph_err1 = ff_aac_is_encoding_err(s, cpe, start, w, g,
ener0, ener1, ener01, -1); ener0, ener1, ener01, 1, -1);
ph_err2 = ff_aac_is_encoding_err(s, cpe, start, w, g, ph_err2 = ff_aac_is_encoding_err(s, cpe, start, w, g,
ener0, ener1, ener01, +1); ener0, ener1, ener01, 1, +1);
erf = ph_err1.error < ph_err2.error ? &ph_err1 : &ph_err2; erf = ph_err1.error < ph_err2.error ? &ph_err1 : &ph_err2;
if (erf->pass) { if (erf->pass) {
sce0->ics.prediction_used[sfb] = 1; sce0->ics.prediction_used[sfb] = 1;