shithub: opus

Download patch

ref: db78df8c01d386ef1fff9c99d38f9f44f726cb9f
parent: c5117c5ccd5da2680b29dbdae5d648d750107003
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Tue Feb 6 17:11:49 EST 2024

Delaying new DRED data when just out of silence

We don't need redundancy for the first active frame
since we already have the main Opus payload.

--- a/silk/dred_encoder.c
+++ b/silk/dred_encoder.c
@@ -257,7 +257,7 @@
     return 0;
 }
 
-int dred_encode_silk_frame(const DREDEnc *enc, unsigned char *buf, int max_chunks, int max_bytes, int q0, int dQ, unsigned char *activity_mem, int arch) {
+int dred_encode_silk_frame(DREDEnc *enc, unsigned char *buf, int max_chunks, int max_bytes, int q0, int dQ, unsigned char *activity_mem, int arch) {
     ec_enc ec_encoder;
 
     int q_level;
@@ -270,13 +270,22 @@
     int latent_offset;
     int extra_dred_offset=0;
     int dred_encoded=0;
+    int delayed_dred=0;
     int total_offset;
 
     latent_offset = enc->latent_offset;
+    /* Delaying new DRED data when just out of silence because we already have the
+       main Opus payload for that frame. */
+    if (activity_mem[0] && enc->last_extra_dred_offset>0) {
+        latent_offset = enc->last_extra_dred_offset;
+        delayed_dred = 1;
+        enc->last_extra_dred_offset = 0;
+    }
     while (latent_offset < enc->latents_buffer_fill && !dred_voice_active(activity_mem, latent_offset)) {
        latent_offset++;
        extra_dred_offset++;
     }
+    if (!delayed_dred) enc->last_extra_dred_offset = extra_dred_offset;
 
     /* entropy coding of state and latents */
     ec_enc_init(&ec_encoder, buf, max_bytes);
--- a/silk/dred_encoder.h
+++ b/silk/dred_encoder.h
@@ -51,6 +51,7 @@
     int input_buffer_fill;
     int dred_offset;
     int latent_offset;
+    int last_extra_dred_offset;
     float latents_buffer[DRED_MAX_FRAMES * DRED_LATENT_DIM];
     int latents_buffer_fill;
     float state_buffer[DRED_MAX_FRAMES * DRED_STATE_DIM];
@@ -65,6 +66,6 @@
 
 void dred_compute_latents(DREDEnc *enc, const float *pcm, int frame_size, int extra_delay, int arch);
 
-int dred_encode_silk_frame(const DREDEnc *enc, unsigned char *buf, int max_chunks, int max_bytes, int q0, int dQ, unsigned char *activity_mem, int arch);
+int dred_encode_silk_frame(DREDEnc *enc, unsigned char *buf, int max_chunks, int max_bytes, int q0, int dQ, unsigned char *activity_mem, int arch);
 
 #endif
--