@@ -1151,9 +1151,9 @@ static opus_int32 opus_encode_frame_native(OpusEncoder *st, const opus_res *pcm,
11511151 opus_int32 dred_bitrate_bps ,
11521152#endif
11531153#ifndef DISABLE_FLOAT_API
1154- AnalysisInfo * analysis_info , int is_silence ,
1154+ AnalysisInfo * analysis_info ,
11551155#endif
1156- int redundancy , int celt_to_silk , int prefill ,
1156+ int is_silence , int redundancy , int celt_to_silk , int prefill ,
11571157 opus_int32 equiv_rate , int to_celt );
11581158
11591159opus_int32 opus_encode_native (OpusEncoder * st , const opus_res * pcm , int frame_size ,
@@ -1183,8 +1183,8 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_res *pcm, int frame_si
11831183 AnalysisInfo analysis_info ;
11841184 int analysis_read_pos_bak = -1 ;
11851185 int analysis_read_subframe_bak = -1 ;
1186- int is_silence = 0 ;
11871186#endif
1187+ int is_silence = 0 ;
11881188#ifdef ENABLE_DRED
11891189 opus_int32 dred_bitrate_bps ;
11901190#endif
@@ -1220,6 +1220,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_res *pcm, int frame_si
12201220
12211221 if (st -> application != OPUS_APPLICATION_RESTRICTED_SILK )
12221222 celt_encoder_ctl (celt_enc , CELT_GET_MODE (& celt_mode ));
1223+ is_silence = is_digital_silence (pcm , frame_size , st -> channels , lsb_depth );
12231224#ifndef DISABLE_FLOAT_API
12241225 analysis_info .valid = 0 ;
12251226#ifdef FIXED_POINT
@@ -1228,7 +1229,6 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_res *pcm, int frame_si
12281229 if (st -> silk_mode .complexity >= 7 && st -> Fs >=16000 && st -> Fs <=48000 && st -> application != OPUS_APPLICATION_RESTRICTED_SILK )
12291230#endif
12301231 {
1231- is_silence = is_digital_silence (pcm , frame_size , st -> channels , lsb_depth );
12321232 analysis_read_pos_bak = st -> analysis .read_pos ;
12331233 analysis_read_subframe_bak = st -> analysis .read_subframe ;
12341234 run_analysis (& st -> analysis , celt_mode , analysis_pcm , analysis_size , frame_size ,
@@ -1247,12 +1247,11 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_res *pcm, int frame_si
12471247 (void )downmix ;
12481248#endif
12491249
1250- #ifndef DISABLE_FLOAT_API
12511250 /* Reset voice_ratio if this frame is not silent or if analysis is disabled.
12521251 * Otherwise, preserve voice_ratio from the last non-silent frame */
12531252 if (!is_silence )
12541253 st -> voice_ratio = -1 ;
1255-
1254+ #ifndef DISABLE_FLOAT_API
12561255 st -> detected_bandwidth = 0 ;
12571256 if (analysis_info .valid )
12581257 {
@@ -1287,11 +1286,14 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_res *pcm, int frame_si
12871286
12881287 /* Track the peak signal energy */
12891288#ifndef DISABLE_FLOAT_API
1290- if (!is_silence && (! analysis_info .valid || analysis_info .activity_probability > DTX_ACTIVITY_THRESHOLD ) )
1289+ if (!analysis_info .valid || analysis_info .activity_probability > DTX_ACTIVITY_THRESHOLD )
12911290#endif
12921291 {
1293- st -> peak_signal_energy = MAX32 (MULT16_32_Q15 (QCONST16 (0.999f , 15 ), st -> peak_signal_energy ),
1294- compute_frame_energy (pcm , frame_size , st -> channels , st -> arch ));
1292+ if (!is_silence )
1293+ {
1294+ st -> peak_signal_energy = MAX32 (MULT16_32_Q15 (QCONST16 (0.999f , 15 ), st -> peak_signal_energy ),
1295+ compute_frame_energy (pcm , frame_size , st -> channels , st -> arch ));
1296+ }
12951297 }
12961298 if (st -> channels == 2 && st -> force_channels != 1 )
12971299 stereo_width = compute_stereo_width (pcm , frame_size , st -> Fs , & st -> width_mem );
@@ -1438,7 +1440,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_res *pcm, int frame_si
14381440#ifndef DISABLE_FLOAT_API
14391441 st -> silk_mode .useDTX = st -> use_dtx && !(analysis_info .valid || is_silence );
14401442#else
1441- st -> silk_mode .useDTX = st -> use_dtx ;
1443+ st -> silk_mode .useDTX = st -> use_dtx && ! is_silence ;
14421444#endif
14431445
14441446 /* Mode selection depending on application and signal type */
@@ -1768,21 +1770,20 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_res *pcm, int frame_si
17681770 curr_max = IMIN (max_len_sum - tot_size , curr_max );
17691771#ifndef DISABLE_FLOAT_API
17701772 if (analysis_read_pos_bak != -1 ) {
1771- is_silence = is_digital_silence (pcm , frame_size , st -> channels , lsb_depth );
17721773 /* Get analysis for current frame. */
17731774 tonality_get_info (& st -> analysis , & analysis_info , enc_frame_size );
17741775 }
17751776#endif
1777+ is_silence = is_digital_silence (pcm , frame_size , st -> channels , lsb_depth );
17761778
17771779 tmp_len = opus_encode_frame_native (st , pcm + i * (st -> channels * enc_frame_size ), enc_frame_size , curr_data , curr_max , float_api , first_frame ,
17781780#ifdef ENABLE_DRED
1779- dred_bitrate_bps ,
1781+ dred_bitrate_bps ,
17801782#endif
17811783#ifndef DISABLE_FLOAT_API
1782- & analysis_info ,
1783- is_silence ,
1784+ & analysis_info ,
17841785#endif
1785- frame_redundancy , celt_to_silk , prefill ,
1786+ is_silence , frame_redundancy , celt_to_silk , prefill ,
17861787 equiv_rate , frame_to_celt
17871788 );
17881789 if (tmp_len < 0 )
@@ -1817,9 +1818,8 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_res *pcm, int frame_si
18171818#endif
18181819#ifndef DISABLE_FLOAT_API
18191820 & analysis_info ,
1820- is_silence ,
18211821#endif
1822- redundancy , celt_to_silk , prefill ,
1822+ is_silence , redundancy , celt_to_silk , prefill ,
18231823 equiv_rate , to_celt
18241824 );
18251825 RESTORE_STACK ;
@@ -1834,9 +1834,9 @@ static opus_int32 opus_encode_frame_native(OpusEncoder *st, const opus_res *pcm,
18341834 opus_int32 dred_bitrate_bps ,
18351835#endif
18361836#ifndef DISABLE_FLOAT_API
1837- AnalysisInfo * analysis_info , int is_silence ,
1837+ AnalysisInfo * analysis_info ,
18381838#endif
1839- int redundancy , int celt_to_silk , int prefill ,
1839+ int is_silence , int redundancy , int celt_to_silk , int prefill ,
18401840 opus_int32 equiv_rate , int to_celt )
18411841{
18421842 void * silk_enc = NULL ;
@@ -1883,22 +1883,22 @@ static opus_int32 opus_encode_frame_native(OpusEncoder *st, const opus_res *pcm,
18831883
18841884 frame_rate = st -> Fs /frame_size ;
18851885
1886- #ifndef DISABLE_FLOAT_API
18871886 if (is_silence )
18881887 {
18891888 activity = !is_silence ;
1890- } else if (analysis_info -> valid )
1891- {
1889+ }
1890+ #ifndef DISABLE_FLOAT_API
1891+ else if (analysis_info -> valid ) {
18921892 activity = analysis_info -> activity_probability >= DTX_ACTIVITY_THRESHOLD ;
18931893 if (!activity )
18941894 {
18951895 /* Mark as active if this noise frame is sufficiently loud */
18961896 opus_val32 noise_energy = compute_frame_energy (pcm , frame_size , st -> channels , st -> arch );
18971897 activity = st -> peak_signal_energy < (PSEUDO_SNR_THRESHOLD * noise_energy );
18981898 }
1899- } else
1899+ }
19001900#endif
1901- if (st -> mode == MODE_CELT_ONLY ) {
1901+ else if (st -> mode == MODE_CELT_ONLY ) {
19021902 opus_val32 noise_energy = compute_frame_energy (pcm , frame_size , st -> channels , st -> arch );
19031903 /* Boosting peak energy a bit because we didn't just average the active frames. */
19041904 activity = 2 * st -> peak_signal_energy < (QCONST16 (PSEUDO_SNR_THRESHOLD , 0 ) * (opus_val64 )noise_energy );
0 commit comments