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
This commit is contained in:
parent
bad313c6ba
commit
421a628f4d
2 changed files with 37 additions and 30 deletions
|
@ -197,7 +197,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
|
||||||
if (st->prev_mode == 0)
|
if (st->prev_mode == 0)
|
||||||
{
|
{
|
||||||
/* If we haven't got any packet yet, all we can do is return zeros */
|
/* 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;
|
pcm[i] = 0;
|
||||||
RESTORE_STACK;
|
RESTORE_STACK;
|
||||||
return audiosize;
|
return audiosize;
|
||||||
|
|
|
@ -162,6 +162,37 @@ failure:
|
||||||
return NULL;
|
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)
|
OpusEncoder *opus_encoder_create(int Fs, int channels, int mode)
|
||||||
{
|
{
|
||||||
char *raw_state = (char *)malloc(opus_encoder_get_size(channels));
|
char *raw_state = (char *)malloc(opus_encoder_get_size(channels));
|
||||||
|
@ -183,7 +214,6 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
|
||||||
int ret=0;
|
int ret=0;
|
||||||
int nBytes;
|
int nBytes;
|
||||||
ec_enc enc;
|
ec_enc enc;
|
||||||
int framerate, period;
|
|
||||||
int silk_internal_bandwidth=-1;
|
int silk_internal_bandwidth=-1;
|
||||||
int bytes_target;
|
int bytes_target;
|
||||||
int prefill=0;
|
int prefill=0;
|
||||||
|
@ -467,7 +497,10 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
|
||||||
/* Handle error */
|
/* Handle error */
|
||||||
}
|
}
|
||||||
if (nBytes==0)
|
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 */
|
/* Extract SILK internal bandwidth for signaling in first byte */
|
||||||
if( st->mode == MODE_SILK_ONLY ) {
|
if( st->mode == MODE_SILK_ONLY ) {
|
||||||
if( st->silk_mode.internalSampleRate == 8000 ) {
|
if( st->silk_mode.internalSampleRate == 8000 ) {
|
||||||
|
@ -661,33 +694,7 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
|
||||||
|
|
||||||
/* Signalling the mode in the first byte */
|
/* Signalling the mode in the first byte */
|
||||||
data--;
|
data--;
|
||||||
framerate = st->Fs/frame_size;
|
data[0] = gen_toc(st->mode, st->Fs/frame_size, st->bandwidth, st->stream_channels);
|
||||||
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]);*/
|
|
||||||
|
|
||||||
st->rangeFinal = enc.rng;
|
st->rangeFinal = enc.rng;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue