shithub: opus

Download patch

ref: 292544453fc89a9a2d14781328f8b1a517e756bc
parent: a4c2512aa4fbd49142e2026ab5cdeacaa1e1e394
author: Jean-Marc Valin <[email protected]>
date: Sat Sep 28 15:29:23 EDT 2013

Makes analysis work when encoding more than 20 ms at a time

--- a/src/analysis.c
+++ b/src/analysis.c
@@ -625,22 +625,23 @@
    int offset;
    int pcm_len;
 
-   /* Avoid overflow/wrap-around of the analysis buffer */
-   analysis_frame_size = IMIN((DETECT_SIZE-5)*Fs/100, analysis_frame_size);
+   if (analysis_pcm != NULL)
+   {
+      /* Avoid overflow/wrap-around of the analysis buffer */
+      analysis_frame_size = IMIN((DETECT_SIZE-5)*Fs/100, analysis_frame_size);
 
-   pcm_len = analysis_frame_size - analysis->analysis_offset;
-   offset = analysis->analysis_offset;
-   do {
-      tonality_analysis(analysis, NULL, celt_mode, analysis_pcm, IMIN(480, pcm_len), offset, c1, c2, C, lsb_depth, downmix);
-      offset += 480;
-      pcm_len -= 480;
-   } while (pcm_len>0);
-   analysis->analysis_offset = analysis_frame_size;
+      pcm_len = analysis_frame_size - analysis->analysis_offset;
+      offset = analysis->analysis_offset;
+      do {
+         tonality_analysis(analysis, NULL, celt_mode, analysis_pcm, IMIN(480, pcm_len), offset, c1, c2, C, lsb_depth, downmix);
+         offset += 480;
+         pcm_len -= 480;
+      } while (pcm_len>0);
+      analysis->analysis_offset = analysis_frame_size;
 
-   analysis->analysis_offset -= frame_size;
+      analysis->analysis_offset -= frame_size;
+   }
 
-   /* Only perform analysis up to 20-ms frames. Longer ones will be split if
-      they're in CELT-only mode. */
    analysis_info->valid = 0;
    tonality_get_info(analysis, analysis_info, frame_size);
 }
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -982,6 +982,8 @@
     opus_val16 stereo_width;
     const CELTMode *celt_mode;
     AnalysisInfo analysis_info;
+    int analysis_read_pos_bak=-1;
+    int analysis_read_subframe_bak=-1;
     VARDECL(opus_val16, tmp_prefill);
 
     ALLOC_STACK;
@@ -1011,11 +1013,13 @@
     celt_encoder_ctl(celt_enc, CELT_GET_MODE(&celt_mode));
 #ifndef DISABLE_FLOAT_API
 #ifdef FIXED_POINT
-    if (analysis_pcm != NULL && st->silk_mode.complexity >= 10 && st->Fs==48000)
+    if (st->silk_mode.complexity >= 10 && st->Fs==48000)
 #else
-    if (analysis_pcm != NULL && st->silk_mode.complexity >= 7 && st->Fs==48000)
+    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);
@@ -1362,6 +1366,11 @@
        VARDECL(OpusRepacketizer, rp);
        opus_int32 bytes_per_frame;
 
+       if (analysis_read_pos_bak!= -1)
+       {
+          st->analysis.read_pos = analysis_read_pos_bak;
+          st->analysis.read_subframe = analysis_read_subframe_bak;
+       }
 
        nb_frames = frame_size > st->Fs/25 ? 3 : 2;
        bytes_per_frame = IMIN(1276,(out_data_bytes-3)/nb_frames);