@@ -58,12 +58,17 @@ static opus_int silk_QueryEncoder( /* O Returns error co
5858/****************************************/
5959
6060opus_int silk_Get_Encoder_Size ( /* O Returns error code */
61- opus_int * encSizeBytes /* O Number of bytes in SILK encoder state */
61+ opus_int * encSizeBytes , /* O Number of bytes in SILK encoder state */
62+ opus_int channels /* I Number of channels */
6263)
6364{
6465 opus_int ret = SILK_NO_ERROR ;
6566
6667 * encSizeBytes = sizeof ( silk_encoder );
68+ /* Skip second encoder state for mono. */
69+ if ( channels == 1 ) {
70+ * encSizeBytes -= sizeof ( silk_encoder_state_Fxx );
71+ }
6772
6873 return ret ;
6974}
@@ -73,6 +78,7 @@ opus_int silk_Get_Encoder_Size( /* O Returns error co
7378/*************************/
7479opus_int silk_InitEncoder ( /* O Returns error code */
7580 void * encState , /* I/O State */
81+ int channels , /* I Number of channels */
7682 int arch , /* I Run-time architecture */
7783 silk_EncControlStruct * encStatus /* O Encoder Status */
7884)
@@ -82,9 +88,9 @@ opus_int silk_InitEncoder( /* O Returns error co
8288
8389 psEnc = (silk_encoder * )encState ;
8490
85- /* Reset encoder */
86- silk_memset ( psEnc , 0 , sizeof ( silk_encoder ) );
87- for ( n = 0 ; n < ENCODER_NUM_CHANNELS ; n ++ ) {
91+ /* Reset encoder. Skip second encoder state for mono. */
92+ silk_memset ( psEnc , 0 , sizeof ( silk_encoder ) - ( channels == 1 ) * sizeof ( silk_encoder_state_Fxx ) );
93+ for ( n = 0 ; n < channels ; n ++ ) {
8894 if ( ret += silk_init_encoder ( & psEnc -> state_Fxx [ n ], arch ) ) {
8995 celt_assert ( 0 );
9096 }
@@ -162,13 +168,16 @@ opus_int silk_Encode( /* O Returns error co
162168 opus_int transition , curr_block , tot_blocks ;
163169 SAVE_STACK ;
164170
171+ celt_assert ( encControl -> nChannelsAPI >= encControl -> nChannelsInternal && encControl -> nChannelsAPI >= psEnc -> nChannelsInternal );
165172 if (encControl -> reducedDependency )
166173 {
167- psEnc -> state_Fxx [0 ].sCmn .first_frame_after_reset = 1 ;
168- psEnc -> state_Fxx [1 ].sCmn .first_frame_after_reset = 1 ;
174+ for ( n = 0 ; n < encControl -> nChannelsAPI ; n ++ ) {
175+ psEnc -> state_Fxx [ n ].sCmn .first_frame_after_reset = 1 ;
176+ }
177+ }
178+ for ( n = 0 ; n < encControl -> nChannelsAPI ; n ++ ) {
179+ psEnc -> state_Fxx [ n ].sCmn .nFramesEncoded = 0 ;
169180 }
170- psEnc -> state_Fxx [ 0 ].sCmn .nFramesEncoded = psEnc -> state_Fxx [ 1 ].sCmn .nFramesEncoded = 0 ;
171-
172181 /* Check values in encoder control structure */
173182 if ( ( ret = check_control_input ( encControl ) ) != 0 ) {
174183 celt_assert ( 0 );
0 commit comments