Better handling of the bandwidth

This commit is contained in:
Jean-Marc Valin 2011-02-04 00:38:50 -05:00
parent e904758c5a
commit 2c8b29806b
2 changed files with 55 additions and 3 deletions

View file

@ -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 */

View file

@ -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,7 +244,11 @@ 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)
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));
@ -233,8 +256,33 @@ int main(int argc, char *argv[])
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));