ref: 1e0805d74f440adbf5829c8a8179fc30a24c5746
parent: 8a7543c49e6cb944258b4cbe5598091e93b290ad
author: Jean-Marc Valin <[email protected]>
date: Mon Oct 3 09:52:18 EDT 2011
Delaying SILK stereo->mono transitions by two frames Gets rid of some more glitches caused by the decoder resampler
--- a/silk/enc_API.c
+++ b/silk/enc_API.c
@@ -137,11 +137,14 @@
}
i=0;
- if ( id==0 ) {
- for ( ; i < len>>1; i++ ) {
- out[ i ] = silk_RSHIFT_ROUND( silk_SMLABB( silk_SMULBB( x1[ 2*i ], g1 ), x2[ 2*i ], g2 ), 14 );
- g1 += delta;
- g2 -= delta;
+ if (to_mono != 2)
+ {
+ if ( id==0 ) {
+ for ( ; i < len>>1; i++ ) {
+ out[ i ] = silk_RSHIFT_ROUND( silk_SMLABB( silk_SMULBB( x1[ 2*i ], g1 ), x2[ 2*i ], g2 ), 14 );
+ g1 += delta;
+ g2 -= delta;
+ }
}
}
if (to_mono) {
@@ -153,7 +156,6 @@
out[ i ] = x1[ 2*i ];
}
}
- /*fprintf(stderr, "%d %d %d\n", g1, g2, to_mono);*/
}
/**************************/
@@ -256,8 +258,8 @@
/* Resample and write to buffer */
if( encControl->nChannelsAPI == 2 && encControl->nChannelsInternal == 2 ) {
int id = psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded;
- if ( encControl->toMono ) {
- stereo_crossmix( samplesIn, buf, 0, nSamplesFromInput, 1, id );
+ if ( encControl->toMono > 0) {
+ stereo_crossmix( samplesIn, buf, 0, nSamplesFromInput, encControl->toMono, id );
} else if( psEnc->nPrevChannelsInternal == 1 || encControl->toMono == -1 ) {
stereo_crossmix( samplesIn, buf, 0, nSamplesFromInput, 0, id );
} else {
@@ -275,9 +277,9 @@
nSamplesToBuffer = psEnc->state_Fxx[ 1 ].sCmn.frame_length - psEnc->state_Fxx[ 1 ].sCmn.inputBufIx;
nSamplesToBuffer = silk_min( nSamplesToBuffer, 10 * nBlocksOf10ms * psEnc->state_Fxx[ 1 ].sCmn.fs_kHz );
- if ( encControl->toMono ) {
- stereo_crossmix( samplesIn, buf, 1, nSamplesFromInput, 1, id );
- } else if( psEnc->nPrevChannelsInternal == 1 ) {
+ if ( encControl->toMono > 0) {
+ stereo_crossmix( samplesIn, buf, 1, nSamplesFromInput, encControl->toMono, id );
+ } else if( psEnc->nPrevChannelsInternal == 1 || encControl->toMono == -1) {
stereo_crossmix( samplesIn, buf, 1, nSamplesFromInput, 0, id );
} else {
for( n = 0; n < nSamplesFromInput; n++ ) {
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -489,10 +489,14 @@
{
/* In case the encoder changes its mind on stereo->mono transition */
st->silk_mode.toMono = -1;
- } else if (st->stream_channels == 1 && st->prev_channels ==2 && !st->silk_mode.toMono)
+ } else if (st->stream_channels == 1 && st->prev_channels ==2 && st->silk_mode.toMono==0)
{
- /* Delay stereo->mono transition so that SILK can do a smooth downmix */
+ /* Delay stereo->mono transition by two frames so that SILK can do a smooth downmix */
st->silk_mode.toMono=1;
+ st->stream_channels = 2;
+ } else if (st->stream_channels == 1 && st->prev_channels ==2 && st->silk_mode.toMono==1)
+ {
+ st->silk_mode.toMono=2;
st->stream_channels = 2;
} else {
st->silk_mode.toMono=0;