ref: 421a628f4da8dc700682ea0b0993853bbe6fcf98
parent: bad313c6ba835a3d9bdf729dd54353590a2c0ffd
author: Jean-Marc Valin <[email protected]>
date: Thu Aug 18 10:32:16 EDT 2011
Changing the encoder to output the ToC in DTX mode Also fixes the "output all zeros" case for DTX/PLC at the beginning of a stream
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -197,7 +197,7 @@
if (st->prev_mode == 0)
{
/* If we haven't got any packet yet, all we can do is return zeros */
- for (i=0;i<audiosize;i++)
+ for (i=0;i<audiosize*st->channels;i++)
pcm[i] = 0;
RESTORE_STACK;
return audiosize;
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -162,6 +162,37 @@
return NULL;
}
+static unsigned char gen_toc(int mode, int framerate, int bandwidth, int channels)
+{
+ int period;
+ unsigned char toc;
+ period = 0;
+ while (framerate < 400)
+ {
+ framerate <<= 1;
+ period++;
+ }
+ if (mode == MODE_SILK_ONLY)
+ {
+ toc = (bandwidth-OPUS_BANDWIDTH_NARROWBAND)<<5;
+ toc |= (period-2)<<3;
+ } else if (mode == MODE_CELT_ONLY)
+ {
+ int tmp = bandwidth-OPUS_BANDWIDTH_MEDIUMBAND;
+ if (tmp < 0)
+ tmp = 0;
+ toc = 0x80;
+ toc |= tmp << 5;
+ toc |= period<<3;
+ } else /* Hybrid */
+ {
+ toc = 0x60;
+ toc |= (bandwidth-OPUS_BANDWIDTH_SUPERWIDEBAND)<<4;
+ toc |= (period-2)<<3;
+ }
+ toc |= (channels==2)<<2;
+ return toc;
+}
OpusEncoder *opus_encoder_create(int Fs, int channels, int mode)
{
char *raw_state = (char *)malloc(opus_encoder_get_size(channels));
@@ -183,7 +214,6 @@
int ret=0;
int nBytes;
ec_enc enc;
- int framerate, period;
int silk_internal_bandwidth=-1;
int bytes_target;
int prefill=0;
@@ -467,7 +497,10 @@
/* Handle error */
}
if (nBytes==0)
- return 0;
+ {
+ data[-1] = gen_toc(st->mode, st->Fs/frame_size, st->bandwidth, st->stream_channels);
+ return 1;
+ }
/* Extract SILK internal bandwidth for signaling in first byte */
if( st->mode == MODE_SILK_ONLY ) {
if( st->silk_mode.internalSampleRate == 8000 ) {
@@ -661,33 +694,7 @@
/* Signalling the mode in the first byte */
data--;
- framerate = st->Fs/frame_size;
- period = 0;
- while (framerate < 400)
- {
- framerate <<= 1;
- period++;
- }
- if (st->mode == MODE_SILK_ONLY)
- {
- data[0] = (silk_internal_bandwidth-OPUS_BANDWIDTH_NARROWBAND)<<5;
- data[0] |= (period-2)<<3;
- } else if (st->mode == MODE_CELT_ONLY)
- {
- int tmp = st->bandwidth-OPUS_BANDWIDTH_MEDIUMBAND;
- if (tmp < 0)
- tmp = 0;
- data[0] = 0x80;
- data[0] |= tmp << 5;
- data[0] |= period<<3;
- } else /* Hybrid */
- {
- data[0] = 0x60;
- data[0] |= (st->bandwidth-OPUS_BANDWIDTH_SUPERWIDEBAND)<<4;
- data[0] |= (period-2)<<3;
- }
- data[0] |= (st->stream_channels==2)<<2;
- /*printf ("%x\n", (int)data[0]);*/
+ data[0] = gen_toc(st->mode, st->Fs/frame_size, st->bandwidth, st->stream_channels);
st->rangeFinal = enc.rng;