From db78df8c01d386ef1fff9c99d38f9f44f726cb9f Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Tue, 6 Feb 2024 22:11:49 -0500 Subject: [PATCH] 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. --- silk/dred_encoder.c | 11 ++++++++++- silk/dred_encoder.h | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/silk/dred_encoder.c b/silk/dred_encoder.c index d0da8d8f..804a67ab 100644 --- a/silk/dred_encoder.c +++ b/silk/dred_encoder.c @@ -257,7 +257,7 @@ static int dred_voice_active(const unsigned char *activity_mem, int offset) { 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 dred_encode_silk_frame(const DREDEnc *enc, unsigned char *buf, int max_chunk 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); diff --git a/silk/dred_encoder.h b/silk/dred_encoder.h index 3831f355..137c963d 100644 --- a/silk/dred_encoder.h +++ b/silk/dred_encoder.h @@ -51,6 +51,7 @@ typedef struct { 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_deinit_encoder(DREDEnc *enc); 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