diff options
author | Jean-Marc Valin <jmvalin@amazon.com> | 2022-11-24 17:23:41 -0500 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@amazon.com> | 2022-11-24 17:23:41 -0500 |
commit | bd9a560eedff186ebd0173a67d2fd1f5d033ddcd (patch) | |
tree | e9fdfe9bdcfe885864170570ac89c30ce45722b0 | |
parent | 0dec778663568e38b595c1cd2ee555784925b60d (diff) | |
download | opus-bd9a560eedff186ebd0173a67d2fd1f5d033ddcd.tar.gz |
Hooking up FEC for ICASSP results
-rw-r--r-- | silk/PLC.c | 29 | ||||
-rw-r--r-- | src/opus_demo.c | 27 | ||||
-rw-r--r-- | src/opus_encoder.c | 2 |
3 files changed, 54 insertions, 4 deletions
@@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef NEURAL_PLC #include "lpcnet.h" +#include <stdio.h> #endif #define NB_ATT 2 @@ -54,6 +55,7 @@ static OPUS_INLINE void silk_PLC_conceal( int arch /* I Run-time architecture */ ); +int plc_init = 0; void silk_PLC_Reset( silk_decoder_state *psDec /* I/O Decoder state */ @@ -71,6 +73,7 @@ void silk_PLC_Reset( /* FIXME: This is leaking memory. The right fix is for the LPCNet state to be part of the PLC struct itself. */ psDec->sPLC.lpcnet = lpcnet_plc_create(LPCNET_PLC_CODEC); } + celt_assert(plc_init==0); #endif } @@ -87,7 +90,31 @@ void silk_PLC( silk_PLC_Reset( psDec ); psDec->sPLC.fs_kHz = psDec->fs_kHz; } - +#ifdef NEURAL_PLC + if (!plc_init) + { + int i; + size_t ret; + float in_features[NB_TOTAL_FEATURES]; + for (i=0;i<4;i++) { + ret = fread(in_features, sizeof(in_features[0]), NB_TOTAL_FEATURES, stdin); + if (i==0) { + lpcnet_plc_fec_add(psDec->sPLC.lpcnet, in_features); + lpcnet_plc_fec_add(psDec->sPLC.lpcnet, in_features); + } + lpcnet_plc_fec_add(psDec->sPLC.lpcnet, in_features); + } + plc_init = 1; + } + { + size_t ret; + float in_features[NB_TOTAL_FEATURES]; + ret = fread(in_features, sizeof(in_features[0]), NB_TOTAL_FEATURES, stdin); + lpcnet_plc_fec_add(psDec->sPLC.lpcnet, in_features); + ret = fread(in_features, sizeof(in_features[0]), NB_TOTAL_FEATURES, stdin); + lpcnet_plc_fec_add(psDec->sPLC.lpcnet, in_features); + } +#endif if( lost ) { /****************************/ /* Generate Signal */ diff --git a/src/opus_demo.c b/src/opus_demo.c index 4cc26a6c..879f2567 100644 --- a/src/opus_demo.c +++ b/src/opus_demo.c @@ -264,6 +264,7 @@ int main(int argc, char *argv[]) int variable_duration=OPUS_FRAMESIZE_ARG; int delayed_decision=0; int ret = EXIT_FAILURE; + FILE *packet_loss_file=NULL; if (argc < 5 ) { @@ -420,7 +421,12 @@ int main(int argc, char *argv[]) use_dtx = 1; args++; } else if( strcmp( argv[ args ], "-loss" ) == 0 ) { - packet_loss_perc = atoi( argv[ args + 1 ] ); + packet_loss_perc = 20; + packet_loss_file = fopen(argv[ args + 1 ], "r"); + if (packet_loss_file == NULL) { + fprintf(stderr, "failed to open loss file\n"); + exit(1); + } args += 2; } else if( strcmp( argv[ args ], "-sweep" ) == 0 ) { check_encoder_option(decode_only, "-sweep"); @@ -614,6 +620,12 @@ int main(int argc, char *argv[]) opus_encoder_ctl(enc, OPUS_SET_EXPERT_FRAME_DURATION(variable_duration)); frame_size = 2*48000; } + if (1) { + int i; + for (i=0;i<max_frame_size;i++) in[i] = 0; + len[0] = opus_encode(enc, in, frame_size, data[0], max_payload_bytes); + opus_decode(dec, data[0], len[0], out, max_frame_size, 0); + } while (!stop) { if (delayed_celt) @@ -763,8 +775,12 @@ int main(int argc, char *argv[]) } else { opus_int32 output_samples; lost = len[toggle]==0 || (packet_loss_perc>0 && rand()%100 < packet_loss_perc); + //printf("%d\n", lost); + //scanf("%d", &lost); + fscanf(packet_loss_file, "%d", &lost); if (lost) - opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples)); + //opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples)); + output_samples=320; else output_samples = max_frame_size; if( count >= use_inbandfec ) { @@ -781,6 +797,13 @@ int main(int argc, char *argv[]) } } else { output_samples = opus_decode(dec, lost ? NULL : data[toggle], len[toggle], out, output_samples, 0); + if (output_samples<0) { + int i; + output_samples = 320; + for (i=0;i<output_samples;i++) { + out[i] = 0; + } + } } if (output_samples>0) { diff --git a/src/opus_encoder.c b/src/opus_encoder.c index 8c8db5a5..bbf7f003 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -1410,7 +1410,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ } else { st->mode = st->user_forced_mode; } - + st->mode = MODE_SILK_ONLY; /* Override the chosen mode to make sure we meet the requested frame size */ if (st->mode != MODE_CELT_ONLY && frame_size < st->Fs/100) st->mode = MODE_CELT_ONLY; |