ref: 000af0340a6483edc76028e7fcd889b1270f5f80
parent: d1309dd2b62973757c00f476d1cd623147f6e0f1
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Wed Oct 18 09:00:40 EDT 2023
Avoiding work on the PLC update side Shift computation to concealment
--- a/dnn/lpcnet_plc.c
+++ b/dnn/lpcnet_plc.c
@@ -59,6 +59,7 @@
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 @@
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 @@
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 @@
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;
--- a/dnn/lpcnet_private.h
+++ b/dnn/lpcnet_private.h
@@ -60,6 +60,7 @@
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];
--
⑨