diff options
author | Felicia Lim <flim@google.com> | 2016-05-16 15:11:10 +0200 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2016-07-17 15:05:54 -0400 |
commit | 425e8a9bdab4065e8176198738e9caf046a03240 (patch) | |
tree | 5c65f86e77ac6eda453541560fff324cf3161044 /src | |
parent | e437424c2398aeed9f035e8b381ebcf2c698c0fb (diff) | |
download | opus-425e8a9bdab4065e8176198738e9caf046a03240.tar.gz |
Skip analysis if the frame contains only digital silence
Signed-off-by: Jean-Marc Valin <jmvalin@jmvalin.ca>
Diffstat (limited to 'src')
-rw-r--r-- | src/opus_encoder.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/src/opus_encoder.c b/src/opus_encoder.c index 4a1bd47a..c2bbd9d1 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -1008,6 +1008,26 @@ static opus_int32 compute_equiv_rate(opus_int32 bitrate, int channels, return equiv; } +#ifndef DISABLE_FLOAT_API + +static int is_digital_silence(const opus_val16* pcm, int frame_size, int lsb_depth) +{ + int silence = 0; + opus_val32 sample_max = 0; + + sample_max = celt_maxabs16(pcm, frame_size); + +#ifdef FIXED_POINT + silence = (sample_max == 0); +#else + silence = (sample_max <= (opus_val16) 1 / (1 << lsb_depth)); +#endif + + return silence; +} + +#endif + opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size, unsigned char *data, opus_int32 out_data_bytes, int lsb_depth, const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, @@ -1045,6 +1065,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ AnalysisInfo analysis_info; int analysis_read_pos_bak=-1; int analysis_read_subframe_bak=-1; + int is_silence = 0; #endif VARDECL(opus_val16, tmp_prefill); @@ -1080,20 +1101,28 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ if (st->silk_mode.complexity >= 7 && st->Fs==48000) #endif { - analysis_read_pos_bak = st->analysis.read_pos; - analysis_read_subframe_bak = st->analysis.read_subframe; - run_analysis(&st->analysis, celt_mode, analysis_pcm, analysis_size, frame_size, - c1, c2, analysis_channels, st->Fs, - lsb_depth, downmix, &analysis_info); + if (is_digital_silence(pcm, frame_size, lsb_depth)) + { + is_silence = 1; + } else { + analysis_read_pos_bak = st->analysis.read_pos; + analysis_read_subframe_bak = st->analysis.read_subframe; + run_analysis(&st->analysis, celt_mode, analysis_pcm, analysis_size, frame_size, + c1, c2, analysis_channels, st->Fs, + lsb_depth, downmix, &analysis_info); + } } #else (void)analysis_pcm; (void)analysis_size; #endif - st->voice_ratio = -1; - #ifndef DISABLE_FLOAT_API + /* Reset voice_ratio if this frame is not silent or if analysis is disabled. + * Otherwise, preserve voice_ratio from the last non-silent frame */ + if (!is_silence) + st->voice_ratio = -1; + st->detected_bandwidth = 0; if (analysis_info.valid) { @@ -1113,6 +1142,8 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ else st->detected_bandwidth = OPUS_BANDWIDTH_FULLBAND; } +#else + st->voice_ratio = -1; #endif if (st->channels==2 && st->force_channels!=1) |