shithub: opus

Download patch

ref: 8b42b00647df1c0ef5dd81459e355f293a9a28b6
parent: 28503d92e8a44b4ad0313de8e3320a806e7683ce
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Mon Jun 5 15:22:27 EDT 2023

Fix DRED for 10-ms frames

--- a/silk/dred_coding.c
+++ b/silk/dred_coding.c
@@ -38,6 +38,7 @@
 #include "celt/laplace.h"
 #include "os_support.h"
 #include "dred_config.h"
+#include "dred_coding.h"
 
 #define LATENT_DIM 80
 #define PVQ_DIM 24
@@ -74,9 +75,12 @@
     }
 }
 
-void dred_encode_state(ec_enc *enc, float *x) {
+void dred_encode_state(ec_enc *enc, const float *x) {
     int iy[PVQ_DIM];
-    op_pvq_search_c(x, iy, PVQ_K, PVQ_DIM, 0);
+    float x0[PVQ_DIM];
+    /* Copy state because the PVQ search will trash it. */
+    OPUS_COPY(x0, x, PVQ_DIM);
+    op_pvq_search_c(x0, iy, PVQ_K, PVQ_DIM, 0);
     encode_pvq(iy, PVQ_DIM, PVQ_K, enc);
 }
 
--- a/silk/dred_coding.h
+++ b/silk/dred_coding.h
@@ -33,7 +33,7 @@
 
 int compute_quantizer(int q0, int dQ, int i);
 
-void dred_encode_state(ec_enc *enc, float *x);
+void dred_encode_state(ec_enc *enc, const float *x);
 
 void dred_encode_latents(ec_enc *enc, const float *x, const opus_uint16 *scale, const opus_uint16 *dzone, const opus_uint16 *r, const opus_uint16 *p0);
 
--- a/silk/dred_encoder.c
+++ b/silk/dred_encoder.c
@@ -107,7 +107,7 @@
     }
 }
 
-int dred_encode_silk_frame(DREDEnc *enc, unsigned char *buf, int max_chunks, int max_bytes) {
+int dred_encode_silk_frame(const DREDEnc *enc, unsigned char *buf, int max_chunks, int max_bytes) {
     const opus_uint16 *dead_zone       = DRED_rdovae_get_dead_zone_pointer();
     const opus_uint16 *p0              = DRED_rdovae_get_p0_pointer();
     const opus_uint16 *quant_scales    = DRED_rdovae_get_quant_scales_pointer();
--- a/silk/dred_encoder.h
+++ b/silk/dred_encoder.h
@@ -59,6 +59,6 @@
 
 void dred_compute_latents(DREDEnc *enc, const float *pcm, int frame_size);
 
-int dred_encode_silk_frame(DREDEnc *enc, unsigned char *buf, int max_chunks, int max_bytes);
+int dred_encode_silk_frame(const DREDEnc *enc, unsigned char *buf, int max_chunks, int max_bytes);
 
 #endif
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -670,7 +670,7 @@
       if (st->lpcnet.blend == 0) needed_feature_frames+=2;
       for (i=0;i<needed_feature_frames;i++) {
          int feature_offset = (needed_feature_frames-i-1 + (dred_offset/(st->Fs/100)-2));
-         if (feature_offset <= 4*dred->nb_latents-1) {
+         if (feature_offset <= 4*dred->nb_latents-1 && feature_offset >= 0) {
            lpcnet_plc_fec_add(&st->lpcnet, dred->fec_features+feature_offset*DRED_NUM_FEATURES);
          } else {
            lpcnet_plc_fec_add(&st->lpcnet, NULL);
--