Fixes a crash in silk prefill (used for mode switching)
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Fri, 27 May 2011 14:03:58 +0000 (10:03 -0400)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Fri, 27 May 2011 14:03:58 +0000 (10:03 -0400)
Also fixes two stereo mode switching issues.

silk/silk_enc_API.c
src/opus_decoder.c

index b665c5b..9824e8f 100644 (file)
@@ -304,7 +304,8 @@ SKP_int silk_Encode(
             /* Total target bits for packet */\r
             nBits = SKP_DIV32_16( SKP_MUL( encControl->bitRate, encControl->payloadSize_ms ), 1000 );\r
             /* Subtract half of the bits already used */\r
-            nBits -= ec_tell( psRangeEnc ) >> 1;\r
+            if (!prefillFlag)\r
+                nBits -= ec_tell( psRangeEnc ) >> 1;\r
             /* Divide by number of uncoded frames left in packet */\r
             nBits = SKP_DIV32_16( nBits, psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket - psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded );\r
             /* Convert to bits/second */\r
@@ -323,7 +324,8 @@ SKP_int silk_Encode(
                 silk_stereo_LR_to_MS( &psEnc->sStereo, psEnc->state_Fxx[ 0 ].sCmn.inputBuf, psEnc->state_Fxx[ 1 ].sCmn.inputBuf, \r
                     psEnc->sStereo.ix[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ], MStargetRates_bps, TargetRate_bps, \r
                     psEnc->state_Fxx[ 0 ].sCmn.speech_activity_Q8, psEnc->state_Fxx[ 0 ].sCmn.fs_kHz, psEnc->state_Fxx[ 0 ].sCmn.frame_length );\r
-                silk_stereo_encode_pred( psRangeEnc, psEnc->sStereo.ix[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ] );\r
+                if (!prefillFlag)\r
+                    silk_stereo_encode_pred( psRangeEnc, psEnc->sStereo.ix[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ] );\r
             } else {\r
                 /* Buffering */\r
                 SKP_memcpy( &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ -2 ], psEnc->sStereo.sMid, 2 * sizeof( SKP_int16 ) );\r
@@ -361,7 +363,8 @@ SKP_int silk_Encode(
                     flags  = SKP_LSHIFT( flags, 1 );\r
                     flags |= psEnc->state_Fxx[ n ].sCmn.LBRR_flag;\r
                 }\r
-                ec_enc_patch_initial_bits( psRangeEnc, flags, ( psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket + 1 ) * encControl->nChannelsInternal );\r
+                if (!prefillFlag)\r
+                    ec_enc_patch_initial_bits( psRangeEnc, flags, ( psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket + 1 ) * encControl->nChannelsInternal );\r
 \r
                 /* Return zero bytes if all channels DTXed */\r
                 if( psEnc->state_Fxx[ 0 ].sCmn.inDTX && ( encControl->nChannelsInternal == 1 || psEnc->state_Fxx[ 1 ].sCmn.inDTX ) ) {\r
index 26e1770..88e87d5 100644 (file)
@@ -347,17 +347,18 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
         for (c=0;c<st->channels;c++)
         {
             for (i=0;i<F2_5;i++)
-                pcm[st->channels*i+c] = redundant_audio[st->channels*i];
+                pcm[st->channels*i+c] = redundant_audio[st->channels*i+c];
         }
         smooth_fade(redundant_audio+st->channels*F2_5, pcm+st->channels*F2_5,
                 pcm+st->channels*F2_5, F2_5, st->channels, window, st->Fs);
     }
     if (transition)
     {
-       for (i=0;i<F2_5;i++)
+       for (i=0;i<st->channels*F2_5;i++)
                pcm[i] = pcm_transition[i];
        if (audiosize >= F5)
-           smooth_fade(pcm_transition+F2_5, pcm+F2_5, pcm+F2_5, F2_5,
+           smooth_fade(pcm_transition+st->channels*F2_5, pcm+st->channels*F2_5,
+                   pcm+st->channels*F2_5, F2_5,
                    st->channels, window, st->Fs);
     }
 #if OPUS_TEST_RANGE_CODER_STATE