]> git.sesse.net Git - ffmpeg/commitdiff
opusenc: add apply_phase_inv option
authorLynne <dev@lynne.ee>
Mon, 25 May 2020 13:41:33 +0000 (14:41 +0100)
committerLynne <dev@lynne.ee>
Tue, 26 May 2020 09:52:12 +0000 (10:52 +0100)
By popular request.
Does the same as in libopusenc.

libavcodec/opus_pvq.c
libavcodec/opusenc.c
libavcodec/opusenc.h

index 9c21d6729804b5c331263701540f7fb23d3a3a60..a4ab7c46ebb7382975081e9423cd81ee47bbf231 100644 (file)
@@ -627,7 +627,7 @@ static av_always_inline uint32_t quant_band_template(CeltPVQ *pvq, CeltFrame *f,
             }
         } else if (stereo) {
             if (quant) {
-                inv = itheta > 8192;
+                inv = f->apply_phase_inv ? itheta > 8192 : 0;
                  if (inv) {
                     for (i = 0; i < N; i++)
                        Y[i] *= -1;
index 3c08ebcf69584c68873d08181d1839f00b5a1f92..953749af3a539c9970990dfac469fb2b6d545920 100644 (file)
@@ -691,7 +691,7 @@ static av_cold int opus_encode_init(AVCodecContext *avctx)
         s->frame[i].avctx = s->avctx;
         s->frame[i].seed = 0;
         s->frame[i].pvq = s->pvq;
-        s->frame[i].apply_phase_inv = 1;
+        s->frame[i].apply_phase_inv = s->options.apply_phase_inv;
         s->frame[i].block[0].emph_coeff = s->frame[i].block[1].emph_coeff = 0.0f;
     }
 
@@ -701,6 +701,7 @@ static av_cold int opus_encode_init(AVCodecContext *avctx)
 #define OPUSENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
 static const AVOption opusenc_options[] = {
     { "opus_delay", "Maximum delay in milliseconds", offsetof(OpusEncContext, options.max_delay_ms), AV_OPT_TYPE_FLOAT, { .dbl = OPUS_MAX_LOOKAHEAD }, 2.5f, OPUS_MAX_LOOKAHEAD, OPUSENC_FLAGS, "max_delay_ms" },
+    { "apply_phase_inv", "Apply intensity stereo phase inversion", offsetof(OpusEncContext, options.apply_phase_inv), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, OPUSENC_FLAGS, "apply_phase_inv" },
     { NULL },
 };
 
index b9162ebec64ceb556ac9a9f8e34df54d86b0a44b..b623b3e948b0cfd1a6a2c7a3a4f7f24de0301569 100644 (file)
@@ -42,6 +42,7 @@
 
 typedef struct OpusEncOptions {
     float max_delay_ms;
+    int apply_phase_inv;
 } OpusEncOptions;
 
 typedef struct OpusPacketInfo {