Fixes a glitch in SILK mono->stereo switching
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 27 Sep 2011 18:10:23 +0000 (14:10 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 27 Sep 2011 18:10:23 +0000 (14:10 -0400)
For these transitions, we now start the left and right resamplers
from the same state.

silk/enc_API.c
silk/fixed/structs_FIX.h
silk/float/structs_FLP.h

index 29d7568..e8a6556 100644 (file)
@@ -219,6 +219,10 @@ opus_int silk_Encode(
             for( n = 0; n < nSamplesFromInput; n++ ) {
                 buf[ n ] = samplesIn[ 2 * n ];
             }
+            /* Making sure to start both resamplers from the same state when switching from mono to stereo */
+            if(psEnc->nPrevChannelsInternal == 1)
+               silk_memcpy(&psEnc->state_Fxx[ 1 ].sCmn.resampler_state, &psEnc->state_Fxx[ 0 ].sCmn.resampler_state, sizeof(psEnc->state_Fxx[ 1 ].sCmn.resampler_state));
+
             ret += silk_resampler( &psEnc->state_Fxx[ 0 ].sCmn.resampler_state,
                 &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.inputBufIx + 2 ], buf, nSamplesFromInput );
             psEnc->state_Fxx[ 0 ].sCmn.inputBufIx += nSamplesToBuffer;
@@ -245,6 +249,8 @@ opus_int silk_Encode(
                 &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.inputBufIx + 2 ], samplesIn, nSamplesFromInput );
             psEnc->state_Fxx[ 0 ].sCmn.inputBufIx += nSamplesToBuffer;
         }
+        psEnc->nPrevChannelsInternal = encControl->nChannelsInternal;
+
         samplesIn  += nSamplesFromInput * encControl->nChannelsAPI;
         nSamplesIn -= nSamplesFromInput;
 
index da22203..3525352 100644 (file)
@@ -120,6 +120,7 @@ typedef struct {
     opus_int32               nBitsExceeded;
     opus_int                 nChannelsAPI;
     opus_int                 nChannelsInternal;
+    opus_int                 nPrevChannelsInternal;
     opus_int                 timeSinceSwitchAllowed_ms;
     opus_int                 allowBandwidthSwitch;
 } silk_encoder;
index 4e729a6..eab77ec 100644 (file)
@@ -118,6 +118,7 @@ typedef struct {
     opus_int32                   nBitsExceeded;
     opus_int                     nChannelsAPI;
     opus_int                     nChannelsInternal;
+    opus_int                     nPrevChannelsInternal;
     opus_int                     timeSinceSwitchAllowed_ms;
     opus_int                     allowBandwidthSwitch;
 } silk_encoder;