ref: 7ebacf430a465d000d97d6d9015f8f6061af8804
parent: 6044907c820f40adc6be8c3d342d49c9956cf233
author: Jean-Marc Valin <[email protected]>
date: Mon Nov 12 21:24:07 EST 2012
Moves analysis to the beginning of opus_encode()
--- a/src/analysis.c
+++ b/src/analysis.c
@@ -185,19 +185,21 @@
for (i=0;i<N2;i++)
{
float w = analysis_window[i];
- in[i].r = MULT16_16(w, x[i]);
- in[i].i = MULT16_16(w, x[N-N2+i]);
- in[N-i-1].r = MULT16_16(w, x[N-i-1]);
- in[N-i-1].i = MULT16_16(w, x[2*N-N2-i-1]);
+ in[i].r = MULT16_16(w, tonal->inmem[i]);
+ in[i].i = MULT16_16(w, x[i]);
+ in[N-i-1].r = MULT16_16(w, x[N2-i-1]);
+ in[N-i-1].i = MULT16_16(w, x[N-i-1]);
+ tonal->inmem[i] = x[N2+i];
}
} else {
for (i=0;i<N2;i++)
{
float w = analysis_window[i];
- in[i].r = MULT16_16(w, x[2*i]+x[2*i+1]);
- in[i].i = MULT16_16(w, x[2*(N-N2+i)]+x[2*(N-N2+i)+1]);
- in[N-i-1].r = MULT16_16(w, x[2*(N-i-1)]+x[2*(N-i-1)+1]);
- in[N-i-1].i = MULT16_16(w, x[2*(2*N-N2-i-1)]+x[2*(2*N-N2-i-1)+1]);
+ in[i].r = MULT16_16(w, tonal->inmem[i]);
+ in[i].i = MULT16_16(w, x[2*i]+x[2*i+1]);
+ in[N-i-1].r = MULT16_16(w, x[2*(N2-i-1)]+x[2*(N2-i-1)+1]);
+ in[N-i-1].i = MULT16_16(w, x[2*(N-i-1)]+x[2*(N-i-1)+1]);
+ tonal->inmem[i] = x[2*(N2+i)]+x[2*(N2+i)+1];
}
}
opus_fft(kfft, in, out);
--- a/src/analysis.h
+++ b/src/analysis.h
@@ -36,6 +36,7 @@
float angle[240];
float d_angle[240];
float d2_angle[240];
+ float inmem[240];
float prev_band_tonality[NB_TBANDS];
float prev_tonality;
float E[NB_FRAMES][NB_TBANDS];
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -592,18 +592,32 @@
lsb_depth = IMIN(lsb_depth, st->lsb_depth);
#ifndef FIXED_POINT
- perform_analysis = st->silk_mode.complexity >= 7 && frame_size >= st->Fs/100 && st->Fs==48000;
+ /* Only perform analysis for 10- and 20-ms frames. We don't have enough buffering for shorter
+ ones and longer ones will be split if they're in CELT-only mode. */
+ perform_analysis = st->silk_mode.complexity >= 7
+ && (frame_size >= st->Fs/100 || frame_size >= st->Fs/50)
+ && st->Fs==48000;
+ if (perform_analysis)
+ {
+ int nb_analysis_frames;
+ nb_analysis_frames = frame_size/(st->Fs/100);
+ for (i=0;i<nb_analysis_frames;i++)
+ tonality_analysis(&st->analysis, &analysis_info, celt_enc, pcm+i*(st->Fs/100)*st->channels, st->channels, lsb_depth);
+ if (st->signal_type == OPUS_AUTO)
+ st->voice_ratio = (int)floor(.5+100*(1-analysis_info.music_prob));
+ st->detected_bandwidth = analysis_info.opus_bandwidth;
+ } else {
+ analysis_info.valid = 0;
+ st->voice_ratio = -1;
+ st->detected_bandwidth = 0;
+ }
#endif
+
if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY)
delay_compensation = 0;
else
delay_compensation = st->delay_compensation;
- if (perform_analysis)
- {
- total_buffer = IMAX(st->Fs/200, delay_compensation);
- } else {
- total_buffer = delay_compensation;
- }
+ total_buffer = delay_compensation;
extra_buffer = total_buffer-delay_compensation;
st->bitrate_bps = user_bitrate_to_bitrate(st, frame_size, max_data_bytes);
@@ -975,22 +989,7 @@
dc_reject(pcm, 3, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs);
}
-#ifndef FIXED_POINT
- if (perform_analysis)
- {
- int nb_analysis_frames;
- nb_analysis_frames = frame_size/(st->Fs/100);
- for (i=0;i<nb_analysis_frames;i++)
- tonality_analysis(&st->analysis, &analysis_info, celt_enc, pcm_buf+i*(st->Fs/100)*st->channels, st->channels, lsb_depth);
- if (st->signal_type == OPUS_AUTO)
- st->voice_ratio = (int)floor(.5+100*(1-analysis_info.music_prob));
- st->detected_bandwidth = analysis_info.opus_bandwidth;
- } else {
- analysis_info.valid = 0;
- st->voice_ratio = -1;
- st->detected_bandwidth = 0;
- }
-#endif
+
/* SILK processing */
HB_gain = Q15ONE;