Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jean-marc.valin@usherbrooke.ca>2011-02-04 08:38:50 +0300
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>2011-02-04 08:38:50 +0300
commit2c8b29806b96058d756340d9664e14848edbcfb8 (patch)
tree9e2339ae02ba07683fb48ca3c1ea87daca37097c
parente904758c5acfc3d77c89c727e818ae7c523123e6 (diff)
Better handling of the bandwidth
-rw-r--r--src/opus_decoder.c4
-rw-r--r--src/test_opus.c54
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));