Skip to content

Commit

Permalink
Should handle mixes of PLC and DRED
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvalin committed Jun 16, 2023
1 parent 37a4e2e commit 2d98ced
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e
srcdir=`dirname $0`
test -n "$srcdir" && cd "$srcdir"

(cd lpcnet; ./download_model.sh plc_challenge)
(cd lpcnet; ./download_model.sh 5e88ebe)

echo "Updating build configuration files, please wait...."

Expand Down
2 changes: 1 addition & 1 deletion lpcnet
2 changes: 2 additions & 0 deletions silk/PLC.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void silk_PLC(
#ifdef NEURAL_PLC
if ( psDec->sPLC.fs_kHz == 16 ) {
int k;
psDec->sPLC.pre_filled = 0;
for( k = 0; k < psDec->nb_subfr; k += 2 ) {
lpcnet_plc_update( psDec->sPLC.lpcnet, frame + k * psDec->subfr_length );
}
Expand Down Expand Up @@ -393,6 +394,7 @@ static OPUS_INLINE void silk_PLC_conceal(
}
#ifdef NEURAL_PLC
if ( psDec->sPLC.fs_kHz == 16 ) {
psDec->sPLC.pre_filled = 1;
for( k = 0; k < psDec->nb_subfr; k += 2 ) {
lpcnet_plc_conceal(psDec->sPLC.lpcnet, frame + k * psDec->subfr_length );
}
Expand Down
2 changes: 1 addition & 1 deletion silk/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ typedef struct {
#ifdef NEURAL_PLC
/* FIXME: We should include the state struct directly to preserve the state shadow copy property. */
LPCNetPLCState *lpcnet;
int pre_filled;
#ifdef ENABLE_NEURAL_FEC
DREDDec dred_decoder;
float fec_features[2*DRED_NUM_REDUNDANCY_FRAMES*DRED_NUM_FEATURES];
int nb_fec_frames;
int pre_filled;
#endif
#endif
} silk_PLC_struct;
Expand Down
13 changes: 6 additions & 7 deletions src/opus_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,15 +659,15 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data,
features_per_frame = frame_size/(st->Fs/100);
needed_feature_frames = features_per_frame;
if (!silk_dec->sPLC.pre_filled) needed_feature_frames+=2;
silk_dec->sPLC.pre_filled = 1;
for (i=0;i<needed_feature_frames;i++) {
int feature_offset = (needed_feature_frames-i-1 + (decode_fec-1)*features_per_frame);
/* FIXME: Find something better than that (involving actual PLC) */
feature_offset = IMIN(feature_offset, silk_dec->sPLC.nb_fec_frames-1);
lpcnet_plc_fec_add(silk_dec->sPLC.lpcnet, silk_dec->sPLC.fec_features+feature_offset*DRED_NUM_FEATURES);
if (feature_offset <= silk_dec->sPLC.nb_fec_frames-1) {
lpcnet_plc_fec_add(silk_dec->sPLC.lpcnet, silk_dec->sPLC.fec_features+feature_offset*DRED_NUM_FEATURES);
} else {
lpcnet_plc_fec_add(silk_dec->sPLC.lpcnet, NULL);
}

}
} else {
silk_dec->sPLC.pre_filled = 0;
}
if (len==0 || data==NULL)
{
Expand Down Expand Up @@ -1114,7 +1114,6 @@ int opus_decoder_dred_input(OpusDecoder *st, const unsigned char *data,
/*printf("Found: %p of size %d\n", payload, payload_len);*/
min_feature_frames = IMIN(2 + offset, 2*DRED_NUM_REDUNDANCY_FRAMES);
silk_dec->sPLC.nb_fec_frames = dred_decode_redundancy_package(&silk_dec->sPLC.dred_decoder, silk_dec->sPLC.fec_features, payload, payload_len, min_feature_frames);
/*printf("%d\n", silk_dec->sPLC.nb_fec_frames);*/
return 1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/opus_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ int main(int argc, char *argv[])
if (run_decoder)
run_decoder += lost_count;
if (!lost && lost_count > 0) {
opus_decoder_dred_input(dec, data, len, 100);
opus_decoder_dred_input(dec, data, len, 2);
}
/* FIXME: Figure out how to trigger the decoder when the last packet of the file is lost. */
for (fr=0;fr<run_decoder;fr++) {
Expand Down

0 comments on commit 2d98ced

Please sign in to comment.