diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2017-01-31 17:35:37 -0500 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2017-05-31 18:09:32 -0400 |
commit | 1396bdad835cecd006663917288a96549b92da60 (patch) | |
tree | dda276fb5e292aceeaf18e0192cd5373c0f5598f | |
parent | aef369f536ecb89ab94c2c6bc6b6e0a767fab39d (diff) | |
download | opus-exp_leakage4.tar.gz |
First attempt at modelling leakageexp_leakage4
-rw-r--r-- | celt/celt.h | 3 | ||||
-rw-r--r-- | celt/celt_encoder.c | 28 | ||||
-rw-r--r-- | src/analysis.c | 50 |
3 files changed, 72 insertions, 9 deletions
diff --git a/celt/celt.h b/celt/celt.h index d69cd44c..e93eb711 100644 --- a/celt/celt.h +++ b/celt/celt.h @@ -50,6 +50,8 @@ extern "C" { #define CELTDecoder OpusCustomDecoder #define CELTMode OpusCustomMode +#define LEAK_BANDS 19 + typedef struct { int valid; float tonality; @@ -60,6 +62,7 @@ typedef struct { float vad_prob; int bandwidth; float activity_probability; + float leak_boost[LEAK_BANDS]; } AnalysisInfo; typedef struct { diff --git a/celt/celt_encoder.c b/celt/celt_encoder.c index 72b6540a..7e7136fd 100644 --- a/celt/celt_encoder.c +++ b/celt/celt_encoder.c @@ -964,7 +964,7 @@ static opus_val16 median_of_3(const opus_val16 *x) static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 *bandLogE2, int nbEBands, int start, int end, int C, int *offsets, int lsb_depth, const opus_int16 *logN, int isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM, - int effectiveBytes, opus_int32 *tot_boost_, int lfe, opus_val16 *surround_dynalloc) + int effectiveBytes, opus_int32 *tot_boost_, int lfe, opus_val16 *surround_dynalloc, AnalysisInfo *analysis) { int i, c; opus_int32 tot_boost=0; @@ -1054,14 +1054,24 @@ static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 } for (i=start;i<end;i++) { - int width; - int boost; - int boost_bits; - if (i<8) follower[i] *= 2; if (i>=12) follower[i] = HALF16(follower[i]); + } +#ifndef DISABLE_FLOAT_API + if (analysis->valid) + { + for (i=start;i<IMIN(LEAK_BANDS, end);i++) + follower[i] = follower[i] + analysis->leak_boost[i]; + } +#endif + for (i=start;i<end;i++) + { + int width; + int boost; + int boost_bits; + follower[i] = MIN16(follower[i], QCONST16(4, DB_SHIFT)); width = C*(eBands[i+1]-eBands[i])<<LM; @@ -1076,11 +1086,11 @@ static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 boost = (int)SHR32(EXTEND32(follower[i])*width/6,DB_SHIFT); boost_bits = boost*6<<BITRES; } - /* For CBR and non-transient CVBR frames, limit dynalloc to 1/4 of the bits */ + /* For CBR and non-transient CVBR frames, limit dynalloc to 2/3 of the bits */ if ((!vbr || (constrained_vbr&&!isTransient)) - && (tot_boost+boost_bits)>>BITRES>>3 > effectiveBytes/4) + && (tot_boost+boost_bits)>>BITRES>>3 > 2*effectiveBytes/3) { - opus_int32 cap = ((effectiveBytes/4)<<BITRES<<3); + opus_int32 cap = ((2*effectiveBytes/3)<<BITRES<<3); offsets[i] = cap-tot_boost; tot_boost = cap; break; @@ -1893,7 +1903,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, maxDepth = dynalloc_analysis(bandLogE, bandLogE2, nbEBands, start, end, C, offsets, st->lsb_depth, mode->logN, isTransient, st->vbr, st->constrained_vbr, - eBands, LM, effectiveBytes, &tot_boost, st->lfe, surround_dynalloc); + eBands, LM, effectiveBytes, &tot_boost, st->lfe, surround_dynalloc, &st->analysis); /* For LFE, everything interesting is in the first band */ if (st->lfe) offsets[0] = IMIN(8, effectiveBytes/3); diff --git a/src/analysis.c b/src/analysis.c index 63d3b732..6672bc88 100644 --- a/src/analysis.c +++ b/src/analysis.c @@ -290,6 +290,9 @@ static const float std_feature_bias[9] = { 2.163313f, 1.260756f, 1.116868f, 1.918795f }; +#define LEAKAGE_OFFSET 2.5f +#define LEAKAGE_SLOPE 2.f + static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt_mode, const void *x, int len, int offset, int c1, int c2, int C, int lsb_depth, downmix_func downmix) { int i, b; @@ -327,6 +330,9 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt float tonality2[240]; float midE[8]; float spec_variability=0; + float band_log2[NB_TBANDS+1]; + float leakage_low[NB_TBANDS+1]; + float leakage_high[NB_TBANDS+1]; SAVE_STACK; alpha = 1.f/IMIN(10, 1+tonal->count); @@ -452,6 +458,21 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt } relativeE = 0; frame_loudness = 0; + /* The energy of the very first band is special because of DC. */ + { + float E = 0; + float X1r, X2r; + X1r = 2*(float)out[0].r; + X2r = 2*(float)out[0].i; + E = X1r*X1r + X2r*X2r; + for (i=1;i<4;i++) + { + float binE = out[i].r*(float)out[i].r + out[N-i].r*(float)out[N-i].r + + out[i].i*(float)out[i].i + out[N-i].i*(float)out[N-i].i; + E += binE; + } + band_log2[0] = (float).5*log2(E+1e-10f); + } for (b=0;b<NB_TBANDS;b++) { float E=0, tE=0, nE=0; @@ -484,6 +505,7 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt frame_loudness += (float)sqrt(E+1e-10f); logE[b] = (float)log(E+1e-10f); + band_log2[b+1] = (float).5*log2(E+1e-10f); tonal->logE[tonal->E_count][b] = logE[b]; if (tonal->count==0) tonal->highE[b] = tonal->lowE[b] = logE[b]; @@ -535,6 +557,34 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt tonal->prev_band_tonality[b] = band_tonality[b]; } + leakage_low[0] = band_log2[0]; + leakage_high[0] = band_log2[0] - LEAKAGE_OFFSET; + for (b=1;b<NB_TBANDS+1;b++) + { + float leak_slope = LEAKAGE_SLOPE*(tbands[b]-tbands[b-1])/4; + leakage_low[b] = MIN16(leakage_low[b-1]+leak_slope, band_log2[b]); + leakage_high[b] = MAX16(leakage_high[b-1]-leak_slope, band_log2[b]-LEAKAGE_OFFSET); + } + for (b=NB_TBANDS-2;b>=0;b--) + { + float leak_slope = LEAKAGE_SLOPE*(tbands[b+1]-tbands[b])/4; + leakage_low[b] = MIN16(leakage_low[b+1]+leak_slope, leakage_low[b]); + leakage_high[b] = MAX16(leakage_high[b+1]-leak_slope, leakage_high[b]); + } + celt_assert(NB_TBANDS+1 <= LEAK_BANDS); + for (b=0;b<NB_TBANDS+1;b++) + { + /* leak_boost[] is made up of two terms. The first, based on leakage_high[], + represents the boost needed to overcome the amount of analysis leakage + cause in a weaker band b by louder neighroubing bands. + The second, based on leakage_low[], applies to a loud band b for + which the quantization noise causes synthesis leakage to the weaker + neighbouring bands. */ + info->leak_boost[b] = MAX16(0, leakage_high[b] - band_log2[b]) + + MAX16(0, band_log2[b] - (leakage_low[b]+LEAKAGE_OFFSET)); + } + for (;b<LEAK_BANDS;b++) info->leak_boost[b] = 0; + for (i=0;i<NB_FRAMES;i++) { int j; |