diff --git a/silk/enc_API.c b/silk/enc_API.c index 29d75686b04f8fbbf6bc897445ca56dad79fcbb7..e8a6556353d704c41ab0eba2a31cbf5bc88bd23f 100644 --- a/silk/enc_API.c +++ b/silk/enc_API.c @@ -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; diff --git a/silk/fixed/structs_FIX.h b/silk/fixed/structs_FIX.h index da22203e3c968d4f566cf9c54cdc0232e99bcc38..352535210290b6e0351876cca6f65858a89141fe 100644 --- a/silk/fixed/structs_FIX.h +++ b/silk/fixed/structs_FIX.h @@ -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; diff --git a/silk/float/structs_FLP.h b/silk/float/structs_FLP.h index 4e729a63a8b7457a33693935a03900232bec1a55..eab77ec55b7fce737e585f5e8d6b04ca974b4cad 100644 --- a/silk/float/structs_FLP.h +++ b/silk/float/structs_FLP.h @@ -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;