diff mbox

[FFmpeg-devel,4/4] opus: Don't invert phase when downmixing to mono (per RFC8251)

Message ID 20171202173627.5292-4-modchipv12@gmail.com
State New
Headers show

Commit Message

Andrew D'Addesio Dec. 2, 2017, 5:36 p.m. UTC
When decoding to downmixed mono, don't put the channels out of phase,
as they will cancel out and create audible artifacts. (See
RFC 8251 sec. 10.)

Signed-off-by: Andrew D'Addesio <modchipv12@gmail.com>
---
 libavcodec/opus_pvq.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox

Patch

diff --git a/libavcodec/opus_pvq.c b/libavcodec/opus_pvq.c
index 2f7aa74..f18c010 100644
--- a/libavcodec/opus_pvq.c
+++ b/libavcodec/opus_pvq.c
@@ -643,7 +643,13 @@  static av_always_inline uint32_t quant_band_template(CeltPVQ *pvq, CeltFrame *f,
                 }
             } else {
                 inv = (b > 2 << 3 && f->remaining2 > 2 << 3) ? ff_opus_rc_dec_log(rc, 2) : 0;
+
+                /* Don't put the channels out of phase if we are decoding to downmixed
+                 * mono as this subjectively sounds bad (RFC 8251 section 10). */
+                if (f->channels == 1)
+                    inv = 0;
             }
+
             itheta = 0;
         }
         qalloc = opus_rc_tell_frac(rc) - tell;