summaryrefslogtreecommitdiff
path: root/silk/enc_API.c
diff options
context:
space:
mode:
authorTimothy B. Terriberry <tterribe@xiph.org>2011-10-14 13:38:24 -0700
committerJean-Marc Valin <jmvalin@jmvalin.ca>2011-10-17 16:03:41 -0400
commit53cc1a033a3183c9d137b03446db58d2e58c0e0a (patch)
tree24476c962dbb081126c89d6f26dd9d02f7bf88e7 /silk/enc_API.c
parent7ef6c7c1b465df4ef3b4ece2ecbf9d35c625beb4 (diff)
downloadopus-53cc1a033a3183c9d137b03446db58d2e58c0e0a.tar.gz
Fix the side frame conditional coding rules.
b24e5746 introduced changes to LastGainIndex which broke conditional coding for side frames after a mid-only frame (i.e., in a 60 ms frame where the side is coded, not coded, then coded again). These rules were a mess in general, however, because the side channel state kept a different nFramesDecoded count from the mid channel state, and had no way to tell if the prior side frame was coded. This patch attempts to rationalize them by moving the conditional coding decision up to the top level, where all this information is available. The first coded side frame after an uncoded side frame now always uses independent coding. If such a frame is also not the first side frame in an Opus frame, then it doesn't include an LTP scaling parameter (because the LTP state is well-defined).
Diffstat (limited to 'silk/enc_API.c')
-rw-r--r--silk/enc_API.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/silk/enc_API.c b/silk/enc_API.c
index 339dafc4..7177d4d5 100644
--- a/silk/enc_API.c
+++ b/silk/enc_API.c
@@ -330,6 +330,8 @@ opus_int silk_Encode(
for( i = 0; i < psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket; i++ ) {
for( n = 0; n < encControl->nChannelsInternal; n++ ) {
if( psEnc->state_Fxx[ n ].sCmn.LBRR_flags[ i ] ) {
+ opus_int condCoding;
+
if( encControl->nChannelsInternal == 2 && n == 0 ) {
silk_stereo_encode_pred( psRangeEnc, psEnc->sStereo.predIx[ i ] );
/* For LBRR data there's no need to code the mid-only flag if the side-channel LBRR flag is set */
@@ -337,7 +339,13 @@ opus_int silk_Encode(
silk_stereo_encode_mid_only( psRangeEnc, psEnc->sStereo.mid_only_flags[ i ] );
}
}
- silk_encode_indices( &psEnc->state_Fxx[ n ].sCmn, psRangeEnc, i, 1 );
+ /* Use conditional coding if previous frame available */
+ if( i > 0 && psEnc->state_Fxx[ n ].sCmn.LBRR_flags[ i - 1 ] ) {
+ condCoding = CODE_CONDITIONALLY;
+ } else {
+ condCoding = CODE_INDEPENDENTLY;
+ }
+ silk_encode_indices( &psEnc->state_Fxx[ n ].sCmn, psRangeEnc, i, 1, condCoding );
silk_encode_pulses( psRangeEnc, psEnc->state_Fxx[ n ].sCmn.indices_LBRR[i].signalType, psEnc->state_Fxx[ n ].sCmn.indices_LBRR[i].quantOffsetType,
psEnc->state_Fxx[ n ].sCmn.pulses_LBRR[ i ], psEnc->state_Fxx[ n ].sCmn.frame_length );
}
@@ -400,7 +408,6 @@ opus_int silk_Encode(
psEnc->state_Fxx[ 1 ].sCmn.prevSignalType = TYPE_NO_VOICE_ACTIVITY;
psEnc->state_Fxx[ 1 ].sCmn.sNSQ.prev_inv_gain_Q16 = 65536;
}
- psEnc->prev_decode_only_middle = psEnc->sStereo.mid_only_flags[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ];
/* Encode */
for( n = 0; n < encControl->nChannelsInternal; n++ ) {
@@ -411,9 +418,21 @@ opus_int silk_Encode(
}
if( channelRate_bps > 0 ) {
+ opus_int condCoding;
+
silk_control_SNR( &psEnc->state_Fxx[ n ].sCmn, channelRate_bps );
- if( ( ret = silk_encode_frame_Fxx( &psEnc->state_Fxx[ n ], nBytesOut, psRangeEnc ) ) != 0 ) {
+ /* Use independent coding if no previous frame available */
+ if( psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded - n <= 0 ) {
+ condCoding = CODE_INDEPENDENTLY;
+ } else if( n > 0 && psEnc->prev_decode_only_middle ) {
+ /* If we skipped a side frame in this packet, we don't
+ need LTP scaling; the LTP state is well-defined. */
+ condCoding = CODE_INDEPENDENTLY_NO_LTP_SCALING;
+ } else {
+ condCoding = CODE_CONDITIONALLY;
+ }
+ if( ( ret = silk_encode_frame_Fxx( &psEnc->state_Fxx[ n ], nBytesOut, psRangeEnc, condCoding ) ) != 0 ) {
silk_assert( 0 );
}
psEnc->state_Fxx[ n ].sCmn.nFramesEncoded++;
@@ -421,6 +440,7 @@ opus_int silk_Encode(
psEnc->state_Fxx[ n ].sCmn.controlled_since_last_payload = 0;
psEnc->state_Fxx[ n ].sCmn.inputBufIx = 0;
}
+ psEnc->prev_decode_only_middle = psEnc->sStereo.mid_only_flags[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded - 1 ];
/* Insert VAD and FEC flags at beginning of bitstream */
if( *nBytesOut > 0 && psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded == psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket) {