Skip to content

Commit 2329ed1

Browse files
committed
Avoid problems when only one channel is silent
When one channel is silent and the other isn't, then mid and side are not orthogonal, which can cause problems with the stereo code. Now the side will always be zero in those cases.
1 parent 08f5ff0 commit 2329ed1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

celt/bands.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,11 @@ static unsigned quant_band(struct band_ctx *ctx, celt_norm *X,
12431243
return cm;
12441244
}
12451245

1246+
#ifdef FIXED_POINT
1247+
#define MIN_STEREO_ENERGY 2
1248+
#else
1249+
#define MIN_STEREO_ENERGY 1e-10f
1250+
#endif
12461251

12471252
/* This function is responsible for encoding and decoding a band for the stereo case. */
12481253
static unsigned quant_band_stereo(struct band_ctx *ctx, celt_norm *X, celt_norm *Y,
@@ -1273,6 +1278,12 @@ static unsigned quant_band_stereo(struct band_ctx *ctx, celt_norm *X, celt_norm
12731278

12741279
orig_fill = fill;
12751280

1281+
if (encode) {
1282+
if (ctx->bandE[ctx->i] < MIN_STEREO_ENERGY || ctx->bandE[ctx->m->nbEBands+ctx->i] < MIN_STEREO_ENERGY) {
1283+
if (ctx->bandE[ctx->i] > ctx->bandE[ctx->m->nbEBands+ctx->i]) OPUS_COPY(Y, X, N);
1284+
else OPUS_COPY(X, Y, N);
1285+
}
1286+
}
12761287
compute_theta(ctx, &sctx, X, Y, N, &b, B, B, LM, 1, &fill);
12771288
inv = sctx.inv;
12781289
imid = sctx.imid;

0 commit comments

Comments
 (0)