ref: 69bfc67109abcf6ed4550b965ec65454e5b312f5
parent: 0abd1b0dea2ed9c771597549caf7ad4482150a8c
author: Jean-Marc Valin <[email protected]>
date: Mon Aug 29 17:46:17 EDT 2011
Fixes a bug introduced in 8fe8b8e0b The SILK bandwidth was incorrectly encoded in the ToC when SILK wasn't using the "desired bandwidth"
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -198,7 +198,7 @@
return OPUS_INTERNAL_ERROR;
}
-static unsigned char gen_toc(int mode, int framerate, int bandwidth, int channels)
+static unsigned char gen_toc(int mode, int framerate, int bandwidth, int silk_bandwidth, int channels)
{
int period;
unsigned char toc;
@@ -210,7 +210,7 @@
}
if (mode == MODE_SILK_ONLY)
{
- toc = (bandwidth-OPUS_BANDWIDTH_NARROWBAND)<<5;
+ toc = (silk_bandwidth-OPUS_BANDWIDTH_NARROWBAND)<<5;
toc |= (period-2)<<3;
} else if (mode == MODE_CELT_ONLY)
{
@@ -263,6 +263,7 @@
int ret=0;
int nBytes;
ec_enc enc;
+ int silk_internal_bandwidth=-1;
int bytes_target;
int prefill=0;
int start_band = 0;
@@ -553,9 +554,21 @@
}
if (nBytes==0)
{
- data[-1] = gen_toc(st->mode, st->Fs/frame_size, st->bandwidth, st->stream_channels);
+ data[-1] = gen_toc(st->mode, st->Fs/frame_size, st->bandwidth, silk_internal_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 ) {
+ silk_internal_bandwidth = OPUS_BANDWIDTH_NARROWBAND;
+ } else if( st->silk_mode.internalSampleRate == 12000 ) {
+ silk_internal_bandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
+ } else if( st->silk_mode.internalSampleRate == 16000 ) {
+ silk_internal_bandwidth = OPUS_BANDWIDTH_WIDEBAND;
+ }
+ } else {
+ SKP_assert( st->silk_mode.internalSampleRate == 16000 );
+ }
}
/* CELT processing */
@@ -739,7 +752,7 @@
/* Signalling the mode in the first byte */
data--;
- data[0] = gen_toc(st->mode, st->Fs/frame_size, st->bandwidth, st->stream_channels);
+ data[0] = gen_toc(st->mode, st->Fs/frame_size, st->bandwidth, silk_internal_bandwidth, st->stream_channels);
st->rangeFinal = enc.rng ^ redundant_rng;