diff options
author | Jean-Marc Valin <jmvalin@amazon.com> | 2023-10-19 00:40:54 +0300 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@amazon.com> | 2023-10-19 00:44:00 +0300 |
commit | 8d43b185b2bb44841cb9b13e6dc1f4f30da0db87 (patch) | |
tree | 15c3a6801df6d2f36d8eb9a10c62bcd500ba6abd /src | |
parent | 000af0340a6483edc76028e7fcd889b1270f5f80 (diff) |
Support OPUS_SET_COMPLEXITY() on decoder side
Controls whether deep PLC is enabled
Diffstat (limited to 'src')
-rw-r--r-- | src/opus_decoder.c | 26 | ||||
-rw-r--r-- | src/opus_demo.c | 8 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/opus_decoder.c b/src/opus_decoder.c index 1bdb6ad4..6f8e517a 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -63,6 +63,7 @@ struct OpusDecoder { opus_int32 Fs; /** Sampling rate (at the API level) */ silk_DecControlStruct DecControl; int decode_gain; + int complexity; int arch; #ifdef ENABLE_DEEP_PLC LPCNetPLCState lpcnet; @@ -142,6 +143,7 @@ int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels) silk_dec = (char*)st+st->silk_dec_offset; celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset); st->stream_channels = st->channels = channels; + st->complexity = 0; st->Fs = Fs; st->DecControl.API_sampleRate = st->Fs; @@ -404,6 +406,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data, st->DecControl.internalSampleRate = 16000; } } + st->DecControl.enable_deep_plc = st->complexity >= 5; lost_flag = data == NULL ? 1 : 2 * !!decode_fec; decoded_samples = 0; @@ -537,7 +540,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data, /* Decode CELT */ celt_ret = celt_decode_with_ec_dred(celt_dec, decode_fec ? NULL : data, len, pcm, celt_frame_size, &dec, celt_accum -#ifdef ENABLE_DRED +#ifdef ENABLE_DEEP_PLC , &st->lpcnet #endif ); @@ -911,6 +914,27 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...) *value = st->bandwidth; } break; + case OPUS_SET_COMPLEXITY_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + if(value<0 || value>10) + { + goto bad_arg; + } + st->complexity = value; + celt_decoder_ctl(celt_dec, OPUS_SET_COMPLEXITY(value)); + } + break; + case OPUS_GET_COMPLEXITY_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + *value = st->complexity; + } + break; case OPUS_GET_FINAL_RANGE_REQUEST: { opus_uint32 *value = va_arg(ap, opus_uint32*); diff --git a/src/opus_demo.c b/src/opus_demo.c index 66c7492a..c5f6250f 100644 --- a/src/opus_demo.c +++ b/src/opus_demo.c @@ -126,6 +126,7 @@ static opus_uint32 char_to_int(unsigned char ch[4]) } #define check_encoder_option(decode_only, opt) do {if (decode_only) {fprintf(stderr, "option %s is only for encoding\n", opt); goto failure;}} while(0) +#define check_decoder_option(encode_only, opt) do {if (encode_only) {fprintf(stderr, "option %s is only for decoding\n", opt); goto failure;}} while(0) static const int silk8_test[][4] = { {MODE_SILK_ONLY, OPUS_BANDWIDTH_NARROWBAND, 960*3, 1}, @@ -273,6 +274,7 @@ int main(int argc, char *argv[]) int use_vbr; int max_payload_bytes; int complexity; + int dec_complexity; int use_inbandfec; int use_dtx; int forcechannels; @@ -391,6 +393,7 @@ int main(int argc, char *argv[]) use_vbr = 1; max_payload_bytes = MAX_PACKET; complexity = 10; + dec_complexity = 0; use_inbandfec = 0; forcechannels = OPUS_AUTO; use_dtx = 0; @@ -456,6 +459,10 @@ int main(int argc, char *argv[]) check_encoder_option(decode_only, "-complexity"); complexity = atoi( argv[ args + 1 ] ); args += 2; + } else if( strcmp( argv[ args ], "-dec_complexity" ) == 0 ) { + check_decoder_option(encode_only, "-dec_complexity"); + dec_complexity = atoi( argv[ args + 1 ] ); + args += 2; } else if( strcmp( argv[ args ], "-inbandfec" ) == 0 ) { use_inbandfec = 1; args++; @@ -616,6 +623,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot create decoder: %s\n", opus_strerror(err)); goto failure; } + opus_decoder_ctl(dec, OPUS_SET_COMPLEXITY(dec_complexity)); } switch(bandwidth) { |