From 2c8b29806b96058d756340d9664e14848edbcfb8 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Fri, 4 Feb 2011 00:38:50 -0500 Subject: Better handling of the bandwidth --- src/opus_decoder.c | 4 ++++ src/test_opus.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/opus_decoder.c b/src/opus_decoder.c index a57e1a26..f2a6e7d4 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -84,6 +84,10 @@ int opus_decode(OpusDecoder *st, const unsigned char *data, short pcm_celt[960*2]; int audiosize; + /* Payloads of 1 (2 including ToC) or 0 trigger the PLC/DTX */ + if (len<=2) + data = NULL; + if (data != NULL) { /* Decoding mode/bandwidth/framesize from first byte */ diff --git a/src/test_opus.c b/src/test_opus.c index 0ce6ec5f..f60cec6d 100644 --- a/src/test_opus.c +++ b/src/test_opus.c @@ -94,6 +94,7 @@ int main(int argc, char *argv[]) int mode; double bits=0.0, bits_act=0.0, bits2=0.0, nrg; int bandwidth=-1; + const char *bandwidth_string; if (argc < 8 ) { @@ -117,6 +118,24 @@ int main(int argc, char *argv[]) use_dtx = 0; packet_loss_perc = 0; + switch(sampling_rate) + { + case 8000: + bandwidth = BANDWIDTH_NARROWBAND; + break; + case 1200: + bandwidth = BANDWIDTH_MEDIUMBAND; + break; + case 16000: + bandwidth = BANDWIDTH_WIDEBAND; + break; + case 24000: + bandwidth = BANDWIDTH_SUPERWIDEBAND; + break; + case 48000: + bandwidth = BANDWIDTH_FULLBAND; + break; + } args = 6; while( args < argc - 2 ) { /* process command line options */ @@ -225,16 +244,45 @@ int main(int argc, char *argv[]) opus_encoder_ctl(enc, OPUS_SET_MODE(mode)); opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate_bps)); - if (bandwidth != -1) - opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bandwidth)); + if (bandwidth == -1) + { + fprintf (stderr, "Please specify a bandwidth when the sampling rate does not match one exactly\n"); + return 1; + } + opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bandwidth)); opus_encoder_ctl(enc, OPUS_SET_VBR_FLAG(use_vbr)); opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)); opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC_FLAG(use_inbandfec)); opus_encoder_ctl(enc, OPUS_SET_DTX_FLAG(use_dtx)); - //skip = 5*sampling_rate/1000 + 18; // 18 is when SILK resamples skip = 5*sampling_rate/1000; + /* When SILK resamples, add 18 samples delay */ + if (mode != MODE_SILK_ONLY || sampling_rate > 16000) + skip += 18; + + switch(bandwidth) + { + case BANDWIDTH_NARROWBAND: + bandwidth_string = "narrowband"; + break; + case BANDWIDTH_MEDIUMBAND: + bandwidth_string = "mediumband"; + break; + case BANDWIDTH_WIDEBAND: + bandwidth_string = "wideband"; + break; + case BANDWIDTH_SUPERWIDEBAND: + bandwidth_string = "superwideband"; + break; + case BANDWIDTH_FULLBAND: + bandwidth_string = "fullband"; + break; + default: + bandwidth_string = "unknown"; + } + + printf("Encoding %d Hz input at %.3f kb/s in %s mode.\n", sampling_rate, bitrate_bps*0.001, bandwidth_string); in = (short*)malloc(frame_size*channels*sizeof(short)); out = (short*)malloc(frame_size*channels*sizeof(short)); -- cgit v1.2.3