Skip to content

Commit

Permalink
Avoid OSCE crash if weights aren't loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvalin committed Mar 3, 2024
1 parent 32d4d87 commit 4eca11c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion dnn/osce.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ void osce_enhance_frame(
float numbits[2];
int periods[4];
int i;
int method;

/* enhancement only implemented for 20 ms frame at 16kHz */
if (psDec->fs_kHz != 16 || psDec->nb_subfr != 4)
Expand All @@ -943,7 +944,11 @@ void osce_enhance_frame(
in_buffer[i] = ((float) xq[i]) * (1.f/32768.f);
}

switch(psDec->osce.method)
if (model->loaded)
method = psDec->osce.method;
else
method = OSCE_METHOD_NONE;
switch(method)
{
case OSCE_METHOD_NONE:
OPUS_COPY(out_buffer, in_buffer, 320);
Expand Down
1 change: 1 addition & 0 deletions dnn/osce_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ typedef struct {

/* OSCEModel */
typedef struct {
int loaded;
#ifndef DISABLE_LACE
LACE lace;
#endif
Expand Down
6 changes: 4 additions & 2 deletions silk/dec_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ opus_int silk_LoadOSCEModels(void *decState, const unsigned char *data, int len)
opus_int ret = SILK_NO_ERROR;

ret = osce_load_models(&((silk_decoder *)decState)->osce_model, data, len);

((silk_decoder *)decState)->osce_model.loaded = (ret == 0);
return ret;
#else
(void) decState;
Expand Down Expand Up @@ -110,7 +110,9 @@ opus_int silk_InitDecoder( /* O Returns error co
{
opus_int n, ret = SILK_NO_ERROR;
silk_decoder_state *channel_state = ((silk_decoder *)decState)->channel_state;

#ifdef ENABLE_OSCE
((silk_decoder *)decState)->osce_model.loaded = 0;
#endif
#ifndef USE_WEIGHTS_FILE
/* load osce models */
silk_LoadOSCEModels(decState, NULL, 0);
Expand Down

0 comments on commit 4eca11c

Please sign in to comment.