Tuning the dynalloc adjustments and checking for LF transients
This commit is contained in:
parent
fe4730c587
commit
4e8b990511
1 changed files with 42 additions and 49 deletions
91
celt/celt.c
91
celt/celt.c
|
@ -306,9 +306,11 @@ static int transient_analysis(const opus_val32 * restrict in, int len, int C,
|
||||||
VARDECL(opus_val16, bins);
|
VARDECL(opus_val16, bins);
|
||||||
opus_val16 T1, T2, T3, T4, T5;
|
opus_val16 T1, T2, T3, T4, T5;
|
||||||
opus_val16 follower;
|
opus_val16 follower;
|
||||||
|
opus_val16 coef[2][4] = {{-2.f, 1.f, -1.f, .5f}, {0.005f, -0.995f, -1.92, .95}};
|
||||||
|
int filterID;
|
||||||
int metric=0;
|
int metric=0;
|
||||||
int fmetric=0, bmetric=0;
|
int fmetric=0, bmetric=0;
|
||||||
int count1, count2, count3, count4, count5;;
|
int count1, count2, count3, count4, count5;
|
||||||
|
|
||||||
SAVE_STACK;
|
SAVE_STACK;
|
||||||
ALLOC(tmp, len, opus_val16);
|
ALLOC(tmp, len, opus_val16);
|
||||||
|
@ -319,6 +321,8 @@ static int transient_analysis(const opus_val32 * restrict in, int len, int C,
|
||||||
|
|
||||||
*tf_estimate = 0;
|
*tf_estimate = 0;
|
||||||
tf_max = 0;
|
tf_max = 0;
|
||||||
|
for (filterID=0;filterID<2;filterID++)
|
||||||
|
{
|
||||||
for (c=0;c<C;c++)
|
for (c=0;c<C;c++)
|
||||||
{
|
{
|
||||||
mem0=0;
|
mem0=0;
|
||||||
|
@ -336,8 +340,10 @@ static int transient_analysis(const opus_val32 * restrict in, int len, int C,
|
||||||
mem0 = mem1 + y - SHL32(x,1);
|
mem0 = mem1 + y - SHL32(x,1);
|
||||||
mem1 = x - SHR32(y,1);
|
mem1 = x - SHR32(y,1);
|
||||||
#else
|
#else
|
||||||
mem0 = mem1 + y - 2*x;
|
mem0 = mem1 + coef[filterID][0]*x - coef[filterID][2]*y;
|
||||||
mem1 = x - .5f*y;
|
mem1 = coef[filterID][1]*x - coef[filterID][3]*y;
|
||||||
|
/*mem0 = mem1 + y - 2*x;
|
||||||
|
mem1 = x - .5f*y;*/
|
||||||
#endif
|
#endif
|
||||||
tmp[i] = EXTRACT16(SHR(y,2));
|
tmp[i] = EXTRACT16(SHR(y,2));
|
||||||
}
|
}
|
||||||
|
@ -356,13 +362,20 @@ static int transient_analysis(const opus_val32 * restrict in, int len, int C,
|
||||||
bins[i] = max_abs;
|
bins[i] = max_abs;
|
||||||
maxbin = MAX16(maxbin, bins[i]);
|
maxbin = MAX16(maxbin, bins[i]);
|
||||||
}
|
}
|
||||||
|
if (filterID==0)
|
||||||
T1 = QCONST16(.09f, 15);
|
{
|
||||||
T2 = QCONST16(.12f, 15);
|
T1 = QCONST16(.09f, 15);
|
||||||
T3 = QCONST16(.18f, 15);
|
T2 = QCONST16(.12f, 15);
|
||||||
T4 = QCONST16(.28f, 15);
|
T3 = QCONST16(.18f, 15);
|
||||||
T5 = QCONST16(.4f, 15);
|
T4 = QCONST16(.28f, 15);
|
||||||
|
T5 = QCONST16(.4f, 15);
|
||||||
|
} else {
|
||||||
|
T1 = QCONST16(.12f, 15);
|
||||||
|
T2 = QCONST16(.18f, 15);
|
||||||
|
T3 = QCONST16(.28f, 15);
|
||||||
|
T4 = QCONST16(.4f, 15);
|
||||||
|
T5 = QCONST16(.5f, 15);
|
||||||
|
}
|
||||||
follower = 0;
|
follower = 0;
|
||||||
count1=count2=count3=count4=count5=0;
|
count1=count2=count3=count4=count5=0;
|
||||||
for (i=0;i<N;i++)
|
for (i=0;i<N;i++)
|
||||||
|
@ -400,7 +413,7 @@ static int transient_analysis(const opus_val32 * restrict in, int len, int C,
|
||||||
metric = fmetric+bmetric;
|
metric = fmetric+bmetric;
|
||||||
|
|
||||||
//if (metric>40)
|
//if (metric>40)
|
||||||
if (metric>20+50*MAX16(analysis->tonality, analysis->noisiness))
|
if (metric>30+20*MAX16(analysis->tonality, analysis->noisiness))
|
||||||
is_transient=1;
|
is_transient=1;
|
||||||
|
|
||||||
if (metric>tf_max)
|
if (metric>tf_max)
|
||||||
|
@ -409,6 +422,7 @@ static int transient_analysis(const opus_val32 * restrict in, int len, int C,
|
||||||
tf_max = metric;
|
tf_max = metric;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
*tf_estimate = 1 + MIN16(1, sqrt(MAX16(0, tf_max-30))/20);
|
*tf_estimate = 1 + MIN16(1, sqrt(MAX16(0, tf_max-30))/20);
|
||||||
RESTORE_STACK;
|
RESTORE_STACK;
|
||||||
#ifdef FUZZING
|
#ifdef FUZZING
|
||||||
|
@ -946,6 +960,7 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
|
||||||
VARDECL(celt_norm, X);
|
VARDECL(celt_norm, X);
|
||||||
VARDECL(celt_ener, bandE);
|
VARDECL(celt_ener, bandE);
|
||||||
VARDECL(opus_val16, bandLogE);
|
VARDECL(opus_val16, bandLogE);
|
||||||
|
VARDECL(opus_val16, bandLogE2);
|
||||||
VARDECL(int, fine_quant);
|
VARDECL(int, fine_quant);
|
||||||
VARDECL(opus_val16, error);
|
VARDECL(opus_val16, error);
|
||||||
VARDECL(int, pulses);
|
VARDECL(int, pulses);
|
||||||
|
@ -1319,8 +1334,6 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
|
||||||
freq[c*N+i] = 0;
|
freq[c*N+i] = 0;
|
||||||
} while (++c<C);
|
} while (++c<C);
|
||||||
}
|
}
|
||||||
ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */
|
|
||||||
|
|
||||||
compute_band_energies(st->mode, freq, bandE, effEnd, C, M);
|
compute_band_energies(st->mode, freq, bandE, effEnd, C, M);
|
||||||
|
|
||||||
amp2Log2(st->mode, effEnd, st->end, bandE, bandLogE, C);
|
amp2Log2(st->mode, effEnd, st->end, bandE, bandLogE, C);
|
||||||
|
@ -1331,6 +1344,7 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
|
||||||
ALLOC(bandLogE2, C*st->mode->nbEBands, opus_val16);
|
ALLOC(bandLogE2, C*st->mode->nbEBands, opus_val16);
|
||||||
if (shortBlocks)
|
if (shortBlocks)
|
||||||
{
|
{
|
||||||
|
VARDECL(celt_sig, freq2);
|
||||||
ALLOC(freq2, C*N, celt_sig);
|
ALLOC(freq2, C*N, celt_sig);
|
||||||
compute_mdcts(st->mode, 0, in, freq2, CC, LM);
|
compute_mdcts(st->mode, 0, in, freq2, CC, LM);
|
||||||
if (CC==2&&C==1)
|
if (CC==2&&C==1)
|
||||||
|
@ -1358,29 +1372,9 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
|
||||||
for (i=0;i<C*st->mode->nbEBands;i++)
|
for (i=0;i<C*st->mode->nbEBands;i++)
|
||||||
bandLogE2[i] = bandLogE[i];
|
bandLogE2[i] = bandLogE[i];
|
||||||
}
|
}
|
||||||
/*for (i=0;i<C*st->mode->nbEBands;i++)
|
|
||||||
printf("%f ", MAX16(0,bandLogE[i]-bandLogE2[i]-LM/2.));
|
|
||||||
printf("\n");*/
|
|
||||||
|
|
||||||
{
|
ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */
|
||||||
opus_val16 follower[42]={0};
|
|
||||||
c=0;do
|
|
||||||
{
|
|
||||||
follower[c*st->mode->nbEBands] = bandLogE[c*st->mode->nbEBands];
|
|
||||||
for (i=1;i<st->mode->nbEBands;i++)
|
|
||||||
follower[c*st->mode->nbEBands+i] = MIN16(follower[c*st->mode->nbEBands+i-1]+2, bandLogE[c*st->mode->nbEBands+i]);
|
|
||||||
for (i=st->mode->nbEBands-2;i>=0;i--)
|
|
||||||
follower[c*st->mode->nbEBands+i] = MIN16(follower[c*st->mode->nbEBands+i], MIN16(follower[c*st->mode->nbEBands+i+1]+2, bandLogE[c*st->mode->nbEBands+i]));
|
|
||||||
} while (++c<2);
|
|
||||||
for (i=st->start;i<st->end-1;i++)
|
|
||||||
{
|
|
||||||
follower[i] = MAX16(0, bandLogE[i]-follower[i]);
|
|
||||||
}
|
|
||||||
/*for (i=st->start;i<st->end-1;i++)
|
|
||||||
printf("%f ", follower[i]);
|
|
||||||
printf("\n");*/
|
|
||||||
|
|
||||||
}
|
|
||||||
/* Band normalisation */
|
/* Band normalisation */
|
||||||
normalise_bands(st->mode, freq, X, bandE, effEnd, C, M);
|
normalise_bands(st->mode, freq, X, bandE, effEnd, C, M);
|
||||||
|
|
||||||
|
@ -1431,15 +1425,15 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
|
||||||
offsets[i] = 0;
|
offsets[i] = 0;
|
||||||
/* Dynamic allocation code */
|
/* Dynamic allocation code */
|
||||||
/* Make sure that dynamic allocation can't make us bust the budget */
|
/* Make sure that dynamic allocation can't make us bust the budget */
|
||||||
|
opus_val32 tot_boost=0;
|
||||||
if (effectiveBytes > 50 && LM>=1)
|
if (effectiveBytes > 50 && LM>=1)
|
||||||
{
|
{
|
||||||
int t1, t2;
|
|
||||||
opus_val16 follower[42]={0};
|
opus_val16 follower[42]={0};
|
||||||
c=0;do
|
c=0;do
|
||||||
{
|
{
|
||||||
follower[c*st->mode->nbEBands] = bandLogE2[c*st->mode->nbEBands];
|
follower[c*st->mode->nbEBands] = bandLogE2[c*st->mode->nbEBands];
|
||||||
for (i=1;i<st->mode->nbEBands;i++)
|
for (i=1;i<st->mode->nbEBands;i++)
|
||||||
follower[c*st->mode->nbEBands+i] = MIN16(follower[c*st->mode->nbEBands+i-1]+2, bandLogE2[c*st->mode->nbEBands+i]);
|
follower[c*st->mode->nbEBands+i] = MIN16(follower[c*st->mode->nbEBands+i-1]+1.5, bandLogE2[c*st->mode->nbEBands+i]);
|
||||||
for (i=st->mode->nbEBands-2;i>=0;i--)
|
for (i=st->mode->nbEBands-2;i>=0;i--)
|
||||||
follower[c*st->mode->nbEBands+i] = MIN16(follower[c*st->mode->nbEBands+i], MIN16(follower[c*st->mode->nbEBands+i+1]+2, bandLogE2[c*st->mode->nbEBands+i]));
|
follower[c*st->mode->nbEBands+i] = MIN16(follower[c*st->mode->nbEBands+i], MIN16(follower[c*st->mode->nbEBands+i+1]+2, bandLogE2[c*st->mode->nbEBands+i]));
|
||||||
} while (++c<2);
|
} while (++c<2);
|
||||||
|
@ -1457,31 +1451,30 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
|
||||||
follower[i] = MAX16(0, bandLogE[i]-follower[i]);
|
follower[i] = MAX16(0, bandLogE[i]-follower[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opus_val32 tot_boost=(effectiveBytes*8-20-40*C)/5;
|
|
||||||
for (i=st->start;i<st->end-1;i++)
|
for (i=st->start;i<st->end-1;i++)
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
int boost;
|
int boost;
|
||||||
|
|
||||||
follower[i] = MIN16(2*follower[i], i<10 ? QCONST16(4, DB_SHIFT) : QCONST16(2, DB_SHIFT));
|
follower[i] = MIN16(follower[i], QCONST16(2, DB_SHIFT));
|
||||||
|
if (i<8)
|
||||||
|
follower[i] *= 2;
|
||||||
|
if (i>=12)
|
||||||
|
follower[i] *= .5;
|
||||||
width = C*(st->mode->eBands[i+1]-st->mode->eBands[i])<<LM;
|
width = C*(st->mode->eBands[i+1]-st->mode->eBands[i])<<LM;
|
||||||
if (width<6)
|
if (width<6)
|
||||||
{
|
{
|
||||||
boost = IMIN(tot_boost/width, EXTEND32(follower[i]));
|
boost = EXTEND32(follower[i]);
|
||||||
tot_boost -= boost*width;
|
tot_boost += boost*width;
|
||||||
} else if (width > 48) {
|
} else if (width > 48) {
|
||||||
boost = IMIN(8*tot_boost/width, EXTEND32(follower[i])*8);
|
boost = EXTEND32(follower[i])*8;
|
||||||
tot_boost -= boost*width/8;
|
tot_boost += boost*width/8;
|
||||||
} else {
|
} else {
|
||||||
boost = IMIN(tot_boost/6, EXTEND32(follower[i])*width/6);
|
boost = EXTEND32(follower[i])*width/6;
|
||||||
tot_boost -= boost*6;
|
tot_boost += boost*6;
|
||||||
}
|
}
|
||||||
//printf("%d ", boost);
|
|
||||||
offsets[i] = boost;
|
offsets[i] = boost;
|
||||||
}
|
}
|
||||||
/*for (i=st->start;i<st->end-1;i++)
|
|
||||||
printf("%f ", follower[i]);
|
|
||||||
printf("%f\n", tot_boost);*/
|
|
||||||
}
|
}
|
||||||
#ifndef FIXED_POINT
|
#ifndef FIXED_POINT
|
||||||
if (0 && st->analysis.valid)
|
if (0 && st->analysis.valid)
|
||||||
|
@ -1598,6 +1591,7 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
|
||||||
#endif
|
#endif
|
||||||
target += (coded_bins<<BITRES)*.05;
|
target += (coded_bins<<BITRES)*.05;
|
||||||
target -= (coded_bins<<BITRES)*.13;
|
target -= (coded_bins<<BITRES)*.13;
|
||||||
|
target += IMAX(0,((int)tot_boost<<BITRES)-100)/2;
|
||||||
target *= .96;
|
target *= .96;
|
||||||
|
|
||||||
#ifdef FIXED_POINT
|
#ifdef FIXED_POINT
|
||||||
|
@ -1616,7 +1610,6 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
|
||||||
tonal_target += (coded_bins<<BITRES)*.8;
|
tonal_target += (coded_bins<<BITRES)*.8;
|
||||||
/*printf("%f %d\n", tonal, tonal_target);*/
|
/*printf("%f %d\n", tonal, tonal_target);*/
|
||||||
new_target = IMAX(tonal_target,new_target);
|
new_target = IMAX(tonal_target,new_target);
|
||||||
//printf("%f %f ", tonal, (coded_bins<<BITRES)*1.6f*tonal);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue