From 000af0340a6483edc76028e7fcd889b1270f5f80 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin <jmvalin@amazon.com> Date: Wed, 18 Oct 2023 13:00:40 -0400 Subject: [PATCH] Avoiding work on the PLC update side Shift computation to concealment --- dnn/lpcnet_plc.c | 36 +++++++++++++++++++++--------------- dnn/lpcnet_private.h | 1 + 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/dnn/lpcnet_plc.c b/dnn/lpcnet_plc.c index 0a1a95aaa..910fe9351 100644 --- a/dnn/lpcnet_plc.c +++ b/dnn/lpcnet_plc.c @@ -59,6 +59,7 @@ int lpcnet_plc_init(LPCNetPLCState *st, int options) { int ret; fargan_init(&st->fargan); lpcnet_encoder_init(&st->enc); + st->analysis_pos = PLC_BUF_SIZE; if ((options&0x3) == LPCNET_PLC_CAUSAL) { st->enable_blending = 1; } else if ((options&0x3) == LPCNET_PLC_CODEC) { @@ -168,20 +169,10 @@ static void replace_features(LPCNetPLCState *st, const float *features) { int lpcnet_plc_update(LPCNetPLCState *st, opus_int16 *pcm) { int i; - float x[FRAME_SIZE]; - float plc_features[2*NB_BANDS+NB_FEATURES+1]; - for (i=0;i<FRAME_SIZE;i++) x[i] = pcm[i]; - burg_cepstral_analysis(plc_features, x); - lpcnet_compute_single_frame_features_float(&st->enc, x, st->features); if (st->blend) { - replace_features(st, st->features); - if (FEATURES_DELAY > 0) st->plc_net = st->plc_copy[FEATURES_DELAY-1]; - } else { - queue_features(st, st->features); - OPUS_COPY(&plc_features[2*NB_BANDS], st->features, NB_FEATURES); - plc_features[2*NB_BANDS+NB_FEATURES] = 1; - compute_plc_pred(st, st->features, plc_features); + st->analysis_pos = PLC_BUF_SIZE-FRAME_SIZE; } + if (st->analysis_pos - FRAME_SIZE >= 0) st->analysis_pos -= FRAME_SIZE; OPUS_MOVE(st->pcm, &st->pcm[FRAME_SIZE], PLC_BUF_SIZE-FRAME_SIZE); for (i=0;i<FRAME_SIZE;i++) st->pcm[PLC_BUF_SIZE-FRAME_SIZE+i] = (1.f/32768.f)*pcm[i]; st->loss_count = 0; @@ -193,6 +184,23 @@ static const float att_table[10] = {0, 0, -.2, -.2, -.4, -.4, -.8, -.8, -1.6, int lpcnet_plc_conceal(LPCNetPLCState *st, opus_int16 *pcm) { int i; if (st->blend == 0) { + int count = 0; + while (st->analysis_pos + FRAME_SIZE <= PLC_BUF_SIZE) { + float x[FRAME_SIZE]; + float plc_features[2*NB_BANDS+NB_FEATURES+1]; + for (i=0;i<FRAME_SIZE;i++) x[i] = 32768.f*st->pcm[st->analysis_pos+i]; + burg_cepstral_analysis(plc_features, x); + lpcnet_compute_single_frame_features_float(&st->enc, x, st->features); + if (count > 0) { + if (count == 1) replace_features(st, st->features); + else queue_features(st, st->features); + OPUS_COPY(&plc_features[2*NB_BANDS], st->features, NB_FEATURES); + plc_features[2*NB_BANDS+NB_FEATURES] = 1; + compute_plc_pred(st, st->features, plc_features); + } + st->analysis_pos += FRAME_SIZE; + count++; + } get_fec_or_pred(st, st->features); queue_features(st, st->features); get_fec_or_pred(st, st->features); @@ -206,9 +214,7 @@ int lpcnet_plc_conceal(LPCNetPLCState *st, opus_int16 *pcm) { 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]); fargan_synthesize_int(&st->fargan, pcm, &st->features[0]); - lpcnet_compute_single_frame_features(&st->enc, pcm, st->features); - OPUS_MOVE(&st->cont_features[0], &st->cont_features[NB_FEATURES], (CONT_VECTORS-1)*NB_FEATURES); - OPUS_COPY(&st->cont_features[(CONT_VECTORS-1)*NB_FEATURES], st->features, NB_FEATURES); + queue_features(st, st->features); OPUS_MOVE(st->pcm, &st->pcm[FRAME_SIZE], PLC_BUF_SIZE-FRAME_SIZE); for (i=0;i<FRAME_SIZE;i++) st->pcm[PLC_BUF_SIZE-FRAME_SIZE+i] = (1.f/32768.f)*pcm[i]; st->blend = 1; diff --git a/dnn/lpcnet_private.h b/dnn/lpcnet_private.h index 6302cc640..20747fb44 100644 --- a/dnn/lpcnet_private.h +++ b/dnn/lpcnet_private.h @@ -60,6 +60,7 @@ struct LPCNetPLCState { int fec_read_pos; int fec_fill_pos; int fec_skip; + int analysis_pos; float pcm[PLC_BUF_SIZE]; int blend; float features[NB_TOTAL_FEATURES]; -- GitLab