ref: 2329ed17948dad5e11b6d5af02120dda4e47c591
parent: 08f5ff06bb4c769e48802e87160dd3c1ca230b1e
author: Jean-Marc Valin <jeanmarcv@google.com>
date: Wed Jun 18 11:21:44 EDT 2025
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.
--- a/celt/bands.c
+++ b/celt/bands.c
@@ -1243,6 +1243,11 @@
return cm;
}
+#ifdef FIXED_POINT
+#define MIN_STEREO_ENERGY 2
+#else
+#define MIN_STEREO_ENERGY 1e-10f
+#endif
/* This function is responsible for encoding and decoding a band for the stereo case. */
static unsigned quant_band_stereo(struct band_ctx *ctx, celt_norm *X, celt_norm *Y,
@@ -1273,6 +1278,12 @@
orig_fill = fill;
+ if (encode) {
+ if (ctx->bandE[ctx->i] < MIN_STEREO_ENERGY || ctx->bandE[ctx->m->nbEBands+ctx->i] < MIN_STEREO_ENERGY) {
+ if (ctx->bandE[ctx->i] > ctx->bandE[ctx->m->nbEBands+ctx->i]) OPUS_COPY(Y, X, N);
+ else OPUS_COPY(X, Y, N);
+ }
+ }
compute_theta(ctx, &sctx, X, Y, N, &b, B, B, LM, 1, &fill);
inv = sctx.inv;
imid = sctx.imid;
--
⑨