Skip to content

Commit

Permalink
Avoiding work on the PLC update side
Browse files Browse the repository at this point in the history
Shift computation to concealment
  • Loading branch information
jmvalin committed Oct 18, 2023
1 parent d1309dd commit 000af03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
36 changes: 21 additions & 15 deletions dnn/lpcnet_plc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions dnn/lpcnet_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 000af03

Please sign in to comment.