shithub: opus

Download patch

ref: 2824bd1f666102cff9e904ea8c6496b261960c03
parent: f9f35904f4e6a263ee49b2dd73165e3ff5e9ba1d
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Wed Jun 28 13:01:17 EDT 2023

Adjusting offsets to synthesize 10 ms at a time

Should make synthesis easier in the future

--- a/dnn/lpcnet_plc.c
+++ b/dnn/lpcnet_plc.c
@@ -208,7 +208,7 @@
           pcm[i] = (int)floor(.5 + w*pcm[i] + (1-w)*(tmp[i]-delta));
         }
         st->lpcnet = copy;
-        lpcnet_synthesize_impl(&st->lpcnet, &st->features[0], pcm, FRAME_SIZE-TRAINING_OFFSET, FRAME_SIZE-TRAINING_OFFSET);
+        /*lpcnet_synthesize_impl(&st->lpcnet, &st->features[0], pcm, FRAME_SIZE-TRAINING_OFFSET, FRAME_SIZE-TRAINING_OFFSET);*/
       } else {
         if (FEATURES_DELAY > 0) st->plc_net = st->plc_copy[FEATURES_DELAY-1];
         fec_rewind(st, FEATURES_DELAY);
@@ -219,8 +219,8 @@
         lpcnet_synthesize_tail_impl(&st->lpcnet, tmp, FRAME_SIZE-TRAINING_OFFSET, FRAME_SIZE-TRAINING_OFFSET);
 #endif
       }
-      OPUS_COPY(st->pcm, &pcm[FRAME_SIZE-TRAINING_OFFSET], TRAINING_OFFSET);
-      st->pcm_fill = TRAINING_OFFSET;
+      OPUS_COPY(st->pcm, pcm, FRAME_SIZE);
+      st->pcm_fill = FRAME_SIZE;
     } else {
       OPUS_COPY(&st->pcm[st->pcm_fill], pcm, FRAME_SIZE);
       st->pcm_fill += FRAME_SIZE;
@@ -286,12 +286,12 @@
   }
   OPUS_MOVE(&st->plc_copy[1], &st->plc_copy[0], FEATURES_DELAY);
   st->plc_copy[0] = st->plc_net;
-  lpcnet_synthesize_tail_impl(&st->lpcnet, pcm, FRAME_SIZE-TRAINING_OFFSET, 0);
+  /*lpcnet_synthesize_tail_impl(&st->lpcnet, pcm, FRAME_SIZE-TRAINING_OFFSET, 0);*/
   if (get_fec_or_pred(st, st->features)) st->loss_count = 0;
   else st->loss_count++;
   if (st->loss_count >= 10) st->features[0] = MAX16(-10, st->features[0]+att_table[9] - 2*(st->loss_count-9));
   else st->features[0] = MAX16(-10, st->features[0]+att_table[st->loss_count]);
-  lpcnet_synthesize_impl(&st->lpcnet, &st->features[0], &pcm[FRAME_SIZE-TRAINING_OFFSET], TRAINING_OFFSET, 0);
+  lpcnet_synthesize_impl(&st->lpcnet, &st->features[0], pcm, FRAME_SIZE, 0);
   {
     float x[FRAME_SIZE];
     /* FIXME: Can we do better? */
--- a/dnn/lpcnet_private.h
+++ b/dnn/lpcnet_private.h
@@ -62,7 +62,7 @@
   float burg_cepstrum[2*NB_BANDS];
 };
 
-#define PLC_BUF_SIZE (FEATURES_DELAY*FRAME_SIZE + TRAINING_OFFSET)
+#define PLC_BUF_SIZE (FEATURES_DELAY*FRAME_SIZE + FRAME_SIZE)
 struct LPCNetPLCState {
   PLCModel model;
   LPCNetState lpcnet;
--- a/silk/dred_config.h
+++ b/silk/dred_config.h
@@ -35,13 +35,16 @@
 #define DRED_NUM_FEATURES 20
 #define DRED_LATENT_DIM 80
 #define DRED_STATE_DIM 24
-#define DRED_MAX_FRAMES 100
-#define DRED_SILK_ENCODER_DELAY (79+12)
+#define DRED_SILK_ENCODER_DELAY (79+12-80)
 #define DRED_FRAME_SIZE 160
 #define DRED_DFRAME_SIZE (2 * (DRED_FRAME_SIZE))
 #define DRED_MAX_DATA_SIZE 1000
 #define DRED_ENC_Q0 9
 #define DRED_ENC_Q1 15
-#define DRED_NUM_REDUNDANCY_FRAMES 50
+
+/* Covers 1.04 second so we can cover one second, after the lookahead. */
+#define DRED_MAX_LATENTS 26
+#define DRED_NUM_REDUNDANCY_FRAMES (2*DRED_MAX_LATENTS)
+#define DRED_MAX_FRAMES (4*DRED_MAX_LATENTS)
 
 #endif
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -673,7 +673,7 @@
       /* if blend==0, the last PLC call was "update" and we need to feed two extra 10-ms frames. */
       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));
+         int feature_offset = (needed_feature_frames-i-1 + (dred_offset/(st->Fs/100)-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 {
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -2205,7 +2205,7 @@
        unsigned char buf[DRED_MAX_DATA_SIZE];
        int dred_chunks;
        int dred_bytes_left;
-       dred_chunks = IMIN(st->dred_duration/4, DRED_NUM_REDUNDANCY_FRAMES/2);
+       dred_chunks = IMIN((st->dred_duration+5)/4, DRED_NUM_REDUNDANCY_FRAMES/2);
        dred_bytes_left = IMIN(DRED_MAX_DATA_SIZE, max_data_bytes-ret-2);
        /* Check whether we actually have something to encode. */
        if (dred_chunks >= 1 && dred_bytes_left >= DRED_MIN_BYTES+2) {
--