Skip to content

Commit 0869829

Browse files
committed
Adds a 3 Hz high-pass filter and boost allocation on leakage
Fixes two leakage problems on the wood blocks sample - Removes DC which causes leakage with no masking - Detect leakage by comparing short-MDCT energy to long-MDCT energy and boost allocation for bands with leakage
1 parent 96d7a07 commit 0869829

File tree

3 files changed

+50
-45
lines changed

3 files changed

+50
-45
lines changed

celt/celt.c

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,9 +1325,44 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
13251325
compute_band_energies(st->mode, freq, bandE, effEnd, C, M);
13261326

13271327
amp2Log2(st->mode, effEnd, st->end, bandE, bandLogE, C);
1328-
/*for (i=0;i<17;i++)
1328+
/*for (i=0;i<21;i++)
13291329
printf("%f ", bandLogE[i]);
13301330
printf("\n");*/
1331+
1332+
ALLOC(bandLogE2, C*st->mode->nbEBands, opus_val16);
1333+
if (shortBlocks)
1334+
{
1335+
ALLOC(freq2, C*N, celt_sig);
1336+
compute_mdcts(st->mode, 0, in, freq2, CC, LM);
1337+
if (CC==2&&C==1)
1338+
{
1339+
for (i=0;i<N;i++)
1340+
freq2[i] = ADD32(HALF32(freq2[i]), HALF32(freq2[N+i]));
1341+
}
1342+
if (st->upsample != 1)
1343+
{
1344+
c=0; do
1345+
{
1346+
int bound = N/st->upsample;
1347+
for (i=0;i<bound;i++)
1348+
freq2[c*N+i] *= st->upsample;
1349+
for (;i<N;i++)
1350+
freq2[c*N+i] = 0;
1351+
} while (++c<C);
1352+
}
1353+
ALLOC(bandE2, C*st->mode->nbEBands, opus_val32);
1354+
compute_band_energies(st->mode, freq2, bandE2, effEnd, C, M);
1355+
amp2Log2(st->mode, effEnd, st->end, bandE2, bandLogE2, C);
1356+
for (i=0;i<C*st->mode->nbEBands;i++)
1357+
bandLogE2[i] += LM/2.;
1358+
} else {
1359+
for (i=0;i<C*st->mode->nbEBands;i++)
1360+
bandLogE2[i] = bandLogE[i];
1361+
}
1362+
/*for (i=0;i<C*st->mode->nbEBands;i++)
1363+
printf("%f ", MAX16(0,bandLogE[i]-bandLogE2[i]-LM/2.));
1364+
printf("\n");*/
1365+
13311366
{
13321367
opus_val16 follower[42]={0};
13331368
c=0;do
@@ -1403,11 +1438,11 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
14031438
opus_val16 follower[42]={0};
14041439
c=0;do
14051440
{
1406-
follower[c*st->mode->nbEBands] = bandLogE[c*st->mode->nbEBands];
1441+
follower[c*st->mode->nbEBands] = bandLogE2[c*st->mode->nbEBands];
14071442
for (i=1;i<st->mode->nbEBands;i++)
1408-
follower[c*st->mode->nbEBands+i] = MIN16(follower[c*st->mode->nbEBands+i-1]+2, bandLogE[c*st->mode->nbEBands+i]);
1443+
follower[c*st->mode->nbEBands+i] = MIN16(follower[c*st->mode->nbEBands+i-1]+2, bandLogE2[c*st->mode->nbEBands+i]);
14091444
for (i=st->mode->nbEBands-2;i>=0;i--)
1410-
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]));
1445+
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]));
14111446
} while (++c<2);
14121447
if (C==2)
14131448
{
@@ -1423,13 +1458,13 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
14231458
follower[i] = MAX16(0, bandLogE[i]-follower[i]);
14241459
}
14251460
}
1426-
opus_val32 tot_boost=effectiveBytes*8/6;
1461+
opus_val32 tot_boost=(effectiveBytes*8-20-40*C)/5;
14271462
for (i=st->start;i<st->end-1;i++)
14281463
{
14291464
int width;
14301465
int boost;
14311466

1432-
follower[i] = MIN16(follower[i], QCONST16(2, DB_SHIFT));
1467+
follower[i] = MIN16(2*follower[i], i<10 ? QCONST16(4, DB_SHIFT) : QCONST16(2, DB_SHIFT));
14331468
width = C*(st->mode->eBands[i+1]-st->mode->eBands[i])<<LM;
14341469
if (width<6)
14351470
{
@@ -1446,43 +1481,10 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
14461481
offsets[i] = boost;
14471482
}
14481483
/*for (i=st->start;i<st->end-1;i++)
1449-
printf("%f ", follower[i]);*/
1450-
//printf("%f\n", tot_boost);
1451-
#if 0
1452-
if (LM <= 1)
1453-
{
1454-
t1 = 3;
1455-
t2 = 5;
1456-
} else {
1457-
t1 = 2;
1458-
t2 = 4;
1459-
}
1460-
for (i=st->start+1;i<st->end-1;i++)
1461-
{
1462-
opus_val32 d2;
1463-
d2 = 2*bandLogE[i]-bandLogE[i-1]-bandLogE[i+1];
1464-
if (C==2)
1465-
d2 = HALF32(d2 + 2*bandLogE[i+st->mode->nbEBands]-
1466-
bandLogE[i-1+st->mode->nbEBands]-bandLogE[i+1+st->mode->nbEBands]);
1467-
#ifdef FUZZING
1468-
if((rand()&0xF)==0)
1469-
{
1470-
offsets[i] += 1;
1471-
if((rand()&0x3)==0)
1472-
offsets[i] += 1+(rand()&0x3);
1473-
}
1474-
#else
1475-
if (d2 > SHL16(t1,DB_SHIFT))
1476-
offsets[i] += 1;
1477-
if (d2 > SHL16(t2,DB_SHIFT))
1478-
offsets[i] += 1;
1479-
#endif
1480-
}
1481-
#endif
1484+
printf("%f ", follower[i]);
1485+
printf("%f\n", tot_boost);*/
14821486
}
14831487
#ifndef FIXED_POINT
1484-
//offsets[4] += 12;
1485-
//offsets[10] += 12;
14861488
if (0 && st->analysis.valid)
14871489
{
14881490
if (st->analysis.boost_amount[0]>.2)

celt/mdct.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar
109109
int N, N2, N4;
110110
kiss_twiddle_scalar sine;
111111
VARDECL(kiss_fft_scalar, f);
112+
VARDECL(kiss_fft_scalar, f2);
112113
SAVE_STACK;
113114
N = l->n;
114115
N >>= shift;
115116
N2 = N>>1;
116117
N4 = N>>2;
117118
ALLOC(f, N2, kiss_fft_scalar);
119+
ALLOC(f2, N2, kiss_fft_scalar);
118120
/* sin(x) ~= x here */
119121
#ifdef FIXED_POINT
120122
sine = TRIG_UPSCALE*(QCONST16(0.7853981f, 15)+N2)/N;
@@ -180,12 +182,12 @@ void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar
180182
}
181183

182184
/* N/4 complex FFT, down-scales by 4/N */
183-
opus_fft(l->kfft[shift], (kiss_fft_cpx *)f, (kiss_fft_cpx *)in);
185+
opus_fft(l->kfft[shift], (kiss_fft_cpx *)f, (kiss_fft_cpx *)f2);
184186

185187
/* Post-rotate */
186188
{
187189
/* Temp pointers to make it really clear to the compiler what we're doing */
188-
const kiss_fft_scalar * restrict fp = in;
190+
const kiss_fft_scalar * restrict fp = f2;
189191
kiss_fft_scalar * restrict yp1 = out;
190192
kiss_fft_scalar * restrict yp2 = out+stride*(N2-1);
191193
const kiss_twiddle_scalar *t = &l->trig[0];

src/opus_encoder.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,9 @@ opus_int32 opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_s
859859
{
860860
hp_cutoff(pcm, cutoff_Hz, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs);
861861
} else {
862-
for (i=0;i<frame_size*st->channels;i++)
863-
pcm_buf[total_buffer*st->channels + i] = pcm[i];
862+
hp_cutoff(pcm, 3, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs);
863+
/*for (i=0;i<frame_size*st->channels;i++)
864+
pcm_buf[total_buffer*st->channels + i] = pcm[i];*/
864865
}
865866

866867
#ifndef FIXED_POINT

0 commit comments

Comments
 (0)