summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalph Giles <giles@mozilla.com>2015-12-30 15:27:02 -0800
committerRalph Giles <giles@mozilla.com>2015-12-31 00:43:27 -0800
commit9e3872a8161d657407c55b6a29882664d1a6320c (patch)
tree6117661754b737a69e83346355a07ed80c570b53
parentd43445f350ff4e4f36442590697f9ce9a366848a (diff)
downloadopus-9e3872a8161d657407c55b6a29882664d1a6320c.tar.gz
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 <jmvalin@jmvalin.ca>
-rw-r--r--src/analysis.c10
-rw-r--r--src/analysis.h9
-rw-r--r--src/opus_encoder.c15
3 files changed, 25 insertions, 9 deletions
diff --git a/src/analysis.c b/src/analysis.c
index f8187d03..360ebcc8 100644
--- a/src/analysis.c
+++ b/src/analysis.c
@@ -142,7 +142,15 @@ void tonality_analysis_init(TonalityAnalysisState *tonal)
{
/* 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)
diff --git a/src/analysis.h b/src/analysis.h
index 9c2b978a..9eae56a5 100644
--- 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 @@ typedef struct {
int read_pos;
int read_subframe;
AnalysisInfo info[DETECT_SIZE];
- int arch;
} TonalityAnalysisState;
/** Initialize a TonalityAnalysisState struct.
@@ -87,6 +88,12 @@ typedef struct {
*/
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);
void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, const void *analysis_pcm,
diff --git a/src/opus_encoder.c b/src/opus_encoder.c
index e1ca868b..4340de40 100644
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -82,6 +82,9 @@ struct OpusEncoder {
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 @@ struct OpusEncoder {
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 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
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 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
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: