ref: 2c8b29806b96058d756340d9664e14848edbcfb8
parent: e904758c5acfc3d77c89c727e818ae7c523123e6
author: Jean-Marc Valin <[email protected]>
date: Thu Feb 3 19:38:50 EST 2011
Better handling of the bandwidth
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -84,6 +84,10 @@
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 */
--- a/src/test_opus.c
+++ b/src/test_opus.c
@@ -94,6 +94,7 @@
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 @@
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,8 +244,12 @@
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));
@@ -233,8 +256,33 @@
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));