diff --git a/dnn/lpcnet.h b/dnn/lpcnet.h index 836b168b9bad94130b80ffc9e31ec5c1fa867d98..34a2c63e9ade80c25b14164895b52b88cfa169f3 100644 --- a/dnn/lpcnet.h +++ b/dnn/lpcnet.h @@ -163,19 +163,10 @@ void lpcnet_destroy(LPCNetState *st); void lpcnet_synthesize(LPCNetState *st, const float *features, opus_int16 *output, int N); -#define LPCNET_PLC_CAUSAL 0 -#define LPCNET_PLC_CODEC 2 - -int lpcnet_plc_get_size(void); - -int lpcnet_plc_init(LPCNetPLCState *st, int options); +int lpcnet_plc_init(LPCNetPLCState *st); void lpcnet_plc_reset(LPCNetPLCState *st); -LPCNetPLCState *lpcnet_plc_create(int options); - -void lpcnet_plc_destroy(LPCNetPLCState *st); - int lpcnet_plc_update(LPCNetPLCState *st, opus_int16 *pcm); int lpcnet_plc_conceal(LPCNetPLCState *st, opus_int16 *pcm); diff --git a/dnn/lpcnet_demo.c b/dnn/lpcnet_demo.c index 67df63bc1989c063947ff6b27104f2b9c119f568..304ab25d15e2dc0f74285a8c343ac417cb16cb98 100644 --- a/dnn/lpcnet_demo.c +++ b/dnn/lpcnet_demo.c @@ -83,7 +83,6 @@ void free_blob(unsigned char *blob, int len) { #define MODE_FEATURES 2 /*#define MODE_SYNTHESIS 3*/ -#define MODE_PLC 4 #define MODE_ADDLPC 5 #define MODE_FWGAN_SYNTHESIS 6 #define MODE_FARGAN_SYNTHESIS 7 @@ -91,8 +90,6 @@ void free_blob(unsigned char *blob, int len) { void usage(void) { fprintf(stderr, "usage: lpcnet_demo -features <input.pcm> <features.f32>\n"); fprintf(stderr, " lpcnet_demo -fargan_synthesis <features.f32> <output.pcm>\n"); - fprintf(stderr, " lpcnet_demo -plc <plc_options> <percent> <input.pcm> <output.pcm>\n"); - fprintf(stderr, " lpcnet_demo -plc_file <plc_options> <percent> <input.pcm> <output.pcm>\n"); fprintf(stderr, " lpcnet_demo -addlpc <features_without_lpc.f32> <features_with_lpc.lpc>\n\n"); fprintf(stderr, " plc_options:\n"); fprintf(stderr, " causal: normal (causal) PLC\n"); @@ -102,11 +99,7 @@ void usage(void) { int main(int argc, char **argv) { int mode=0; - int plc_percent=0; FILE *fin, *fout; - FILE *plc_file = NULL; - const char *plc_options; - int plc_flags=-1; #ifdef USE_WEIGHTS_FILE int len; unsigned char *data; @@ -115,32 +108,11 @@ int main(int argc, char **argv) { if (argc < 4) usage(); if (strcmp(argv[1], "-features") == 0) mode=MODE_FEATURES; else if (strcmp(argv[1], "-fargan-synthesis") == 0) mode=MODE_FARGAN_SYNTHESIS; - else if (strcmp(argv[1], "-plc") == 0) { - mode=MODE_PLC; - plc_options = argv[2]; - plc_percent = atoi(argv[3]); - argv+=2; - argc-=2; - } else if (strcmp(argv[1], "-plc_file") == 0) { - mode=MODE_PLC; - plc_options = argv[2]; - plc_file = fopen(argv[3], "r"); - if (!plc_file) { - fprintf(stderr, "Can't open %s\n", argv[3]); - exit(1); - } - argv+=2; - argc-=2; - } else if (strcmp(argv[1], "-addlpc") == 0){ + else if (strcmp(argv[1], "-addlpc") == 0){ mode=MODE_ADDLPC; } else { usage(); } - if (mode == MODE_PLC) { - if (strcmp(plc_options, "causal")==0) plc_flags = LPCNET_PLC_CAUSAL; - else if (strcmp(plc_options, "codec")==0) plc_flags = LPCNET_PLC_CODEC; - else usage(); - } if (argc != 4) usage(); fin = fopen(argv[2], "rb"); if (fin == NULL) { @@ -195,35 +167,6 @@ int main(int argc, char **argv) { for (i=0;i<LPCNET_FRAME_SIZE;i++) pcm[i] = (int)floor(.5 + MIN32(32767, MAX32(-32767, 32768.f*fpcm[i]))); fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout); } - } else if (mode == MODE_PLC) { - opus_int16 pcm[FRAME_SIZE]; - int count=0; - int loss=0; - int skip=0, extra=0; - LPCNetPLCState *net; - net = lpcnet_plc_create(plc_flags); -#ifdef USE_WEIGHTS_FILE - lpcnet_plc_load_model(net, data, len); -#endif - while (1) { - size_t ret; - ret = fread(pcm, sizeof(pcm[0]), FRAME_SIZE, fin); - if (feof(fin) || ret != FRAME_SIZE) break; - if (count % 2 == 0) { - if (plc_file != NULL) ret = fscanf(plc_file, "%d", &loss); - else loss = rand() < (float)RAND_MAX*(float)plc_percent/100.f; - } - if (loss) lpcnet_plc_conceal(net, pcm); - else lpcnet_plc_update(net, pcm); - fwrite(&pcm[skip], sizeof(pcm[0]), FRAME_SIZE-skip, fout); - skip = 0; - count++; - } - if (extra) { - lpcnet_plc_conceal(net, pcm); - fwrite(pcm, sizeof(pcm[0]), extra, fout); - } - lpcnet_plc_destroy(net); } else if (mode == MODE_ADDLPC) { float features[36]; size_t ret; @@ -240,7 +183,6 @@ int main(int argc, char **argv) { } fclose(fin); fclose(fout); - if (plc_file) fclose(plc_file); #ifdef USE_WEIGHTS_FILE free_blob(data, len); #endif diff --git a/dnn/lpcnet_plc.c b/dnn/lpcnet_plc.c index 910fe935142ba23b8793726da2b3a892726b1689..c02f290978d0567f3154a3d67083f0d4699178e5 100644 --- a/dnn/lpcnet_plc.c +++ b/dnn/lpcnet_plc.c @@ -41,10 +41,6 @@ /* Comment this out to have LPCNet update its state on every good packet (slow). */ #define PLC_SKIP_UPDATES -int lpcnet_plc_get_size() { - return sizeof(LPCNetPLCState); -} - void lpcnet_plc_reset(LPCNetPLCState *st) { OPUS_CLEAR((char*)&st->LPCNET_PLC_RESET_START, sizeof(LPCNetPLCState)- @@ -55,18 +51,11 @@ void lpcnet_plc_reset(LPCNetPLCState *st) { st->loss_count = 0; } -int lpcnet_plc_init(LPCNetPLCState *st, int options) { +int lpcnet_plc_init(LPCNetPLCState *st) { 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) { - st->enable_blending = 0; - } else { - return -1; - } #ifndef USE_WEIGHTS_FILE ret = init_plc_model(&st->model, lpcnet_plc_arrays); #else @@ -89,38 +78,22 @@ int lpcnet_plc_load_model(LPCNetPLCState *st, const unsigned char *data, int len else return -1; } -LPCNetPLCState *lpcnet_plc_create(int options) { - LPCNetPLCState *st; - st = calloc(sizeof(*st), 1); - lpcnet_plc_init(st, options); - return st; -} - -void lpcnet_plc_destroy(LPCNetPLCState *st) { - free(st); -} - void lpcnet_plc_fec_add(LPCNetPLCState *st, const float *features) { if (features == NULL) { st->fec_skip++; return; } if (st->fec_fill_pos == PLC_MAX_FEC) { - if (st->fec_keep_pos == 0) { - fprintf(stderr, "FEC buffer full\n"); - return; - } - OPUS_MOVE(&st->fec[0][0], &st->fec[st->fec_keep_pos][0], (st->fec_fill_pos-st->fec_keep_pos)*NB_FEATURES); - st->fec_fill_pos = st->fec_fill_pos-st->fec_keep_pos; - st->fec_read_pos -= st->fec_keep_pos; - st->fec_keep_pos = 0; + OPUS_MOVE(&st->fec[0][0], &st->fec[st->fec_read_pos][0], (st->fec_fill_pos-st->fec_read_pos)*NB_FEATURES); + st->fec_fill_pos = st->fec_fill_pos-st->fec_read_pos; + st->fec_read_pos -= st->fec_read_pos; } OPUS_COPY(&st->fec[st->fec_fill_pos][0], features, NB_FEATURES); st->fec_fill_pos++; } void lpcnet_plc_fec_clear(LPCNetPLCState *st) { - st->fec_keep_pos = st->fec_read_pos = st->fec_fill_pos = st-> fec_skip = 0; + st->fec_read_pos = st->fec_fill_pos = st->fec_skip = 0; } @@ -140,8 +113,6 @@ static int get_fec_or_pred(LPCNetPLCState *st, float *out) { float discard[NB_FEATURES]; OPUS_COPY(out, &st->fec[st->fec_read_pos][0], NB_FEATURES); st->fec_read_pos++; - /* Make sure we can rewind a few frames back at resync time. */ - st->fec_keep_pos = IMAX(0, IMAX(st->fec_keep_pos, st->fec_read_pos-FEATURES_DELAY-1)); /* Update PLC state using FEC, so without Burg features. */ OPUS_COPY(&plc_features[2*NB_BANDS], out, NB_FEATURES); plc_features[2*NB_BANDS+NB_FEATURES] = -1; @@ -207,8 +178,6 @@ int lpcnet_plc_conceal(LPCNetPLCState *st, opus_int16 *pcm) { queue_features(st, st->features); fargan_cont(&st->fargan, &st->pcm[PLC_BUF_SIZE-FARGAN_CONT_SAMPLES], st->cont_features); } - OPUS_MOVE(&st->plc_copy[1], &st->plc_copy[0], FEATURES_DELAY); - st->plc_copy[0] = st->plc_net; 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)); diff --git a/dnn/lpcnet_private.h b/dnn/lpcnet_private.h index 20747fb44382ae214dab673a876e6d8483ef2fc8..ee269e4456186fce4ef4361de397de831f9187db 100644 --- a/dnn/lpcnet_private.h +++ b/dnn/lpcnet_private.h @@ -52,11 +52,9 @@ struct LPCNetPLCState { FARGANState fargan; LPCNetEncState enc; int arch; - int enable_blending; #define LPCNET_PLC_RESET_START fec float fec[PLC_MAX_FEC][NB_FEATURES]; - int fec_keep_pos; int fec_read_pos; int fec_fill_pos; int fec_skip; @@ -67,7 +65,6 @@ struct LPCNetPLCState { float cont_features[CONT_VECTORS*NB_FEATURES]; int loss_count; PLCNetState plc_net; - PLCNetState plc_copy[FEATURES_DELAY+1]; }; void preemphasis(float *y, float *mem, const float *x, float coef, int N); diff --git a/src/opus_decoder.c b/src/opus_decoder.c index 6f8e517a0be670353e70a752bb65851dff304f3a..67b1cfd39a50d88d0896064747d581bba979b04a 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -162,7 +162,7 @@ int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels) st->prev_mode = 0; st->frame_size = Fs/400; #ifdef ENABLE_DEEP_PLC - lpcnet_plc_init( &st->lpcnet, LPCNET_PLC_CODEC ); + lpcnet_plc_init( &st->lpcnet); #endif st->arch = opus_select_arch(); return OPUS_OK;