shithub: opus

Download patch

ref: 9e3872a8161d657407c55b6a29882664d1a6320c
parent: d43445f350ff4e4f36442590697f9ce9a366848a
author: Ralph Giles <[email protected]>
date: Wed Dec 30 10:27:02 EST 2015

Add tonality_analysis_reset().

Add a reset function for the TonalityAnalysisState struct
and call it on encoder reset.

Move the state struct above the clear line in OpusEncoder
so reset doesn't clobber reusable fields. Currently this
is only the arch field, which is moved to to top of the
struct so we can use the same memset-to-the-end pattern
as OpusEncoder.

Signed-off-by: Jean-Marc Valin <[email protected]>

--- a/src/analysis.c
+++ b/src/analysis.c
@@ -142,7 +142,15 @@
 {
   /* Initialize reusable fields. */
   tonal->arch = opus_select_arch();
-  /* Other fields will be overwritten in use. */
+  /* Clear remaining fields. */
+  tonality_analysis_reset(tonal);
+}
+
+void tonality_analysis_reset(TonalityAnalysisState *tonal)
+{
+  /* Clear non-reusable fields. */
+  char *start = (char*)&tonal->TONALITY_ANALYSIS_RESET_START;
+  OPUS_CLEAR(start, sizeof(TonalityAnalysisState) - (start - (char*)tonal));
 }
 
 void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len)
--- a/src/analysis.h
+++ b/src/analysis.h
@@ -39,6 +39,8 @@
 #define DETECT_SIZE 200
 
 typedef struct {
+   int arch;
+#define TONALITY_ANALYSIS_RESET_START angle
    float angle[240];
    float d_angle[240];
    float d2_angle[240];
@@ -76,7 +78,6 @@
    int read_pos;
    int read_subframe;
    AnalysisInfo info[DETECT_SIZE];
-   int arch;
 } TonalityAnalysisState;
 
 /** Initialize a TonalityAnalysisState struct.
@@ -86,6 +87,12 @@
  * by the state struct, so no cleanup call is required.
  */
 void tonality_analysis_init(TonalityAnalysisState *analysis);
+
+/** Reset a TonalityAnalysisState stuct.
+ *
+ * Call this when there's a discontinuity in the data.
+ */
+void tonality_analysis_reset(TonalityAnalysisState *analysis);
 
 void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len);
 
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -82,6 +82,9 @@
     int          encoder_buffer;
     int          lfe;
     int          arch;
+#ifndef DISABLE_FLOAT_API
+    TonalityAnalysisState analysis;
+#endif
 
 #define OPUS_ENCODER_RESET_START stream_channels
     int          stream_channels;
@@ -101,7 +104,6 @@
     StereoWidthState width_mem;
     opus_val16   delay_buffer[MAX_ENCODER_BUFFER*2];
 #ifndef DISABLE_FLOAT_API
-    TonalityAnalysisState analysis;
     int          detected_bandwidth;
 #endif
     opus_uint32  rangeFinal;
@@ -2453,10 +2455,12 @@
            void *silk_enc;
            silk_EncControlStruct dummy;
            silk_enc = (char*)st+st->silk_enc_offset;
+#ifndef DISABLE_FLOAT_API
+           tonality_analysis_reset(&st->analysis);
+#endif
 
-           OPUS_CLEAR((char*)&st->OPUS_ENCODER_RESET_START,
-                 sizeof(OpusEncoder)-
-                 ((char*)&st->OPUS_ENCODER_RESET_START - (char*)st));
+           char *start = (char*)&st->OPUS_ENCODER_RESET_START;
+           OPUS_CLEAR(start, sizeof(OpusEncoder) - (start - (char*)st));
 
            celt_encoder_ctl(celt_enc, OPUS_RESET_STATE);
            silk_InitEncoder( silk_enc, st->arch, &dummy );
@@ -2467,9 +2471,6 @@
            st->mode = MODE_HYBRID;
            st->bandwidth = OPUS_BANDWIDTH_FULLBAND;
            st->variable_HP_smth2_Q15 = silk_LSHIFT( silk_lin2log( VARIABLE_HP_MIN_CUTOFF_HZ ), 8 );
-#ifndef DISABLE_FLOAT_API
-           tonality_analysis_init(&st->analysis);
-#endif
         }
         break;
         case OPUS_SET_FORCE_MODE_REQUEST: