Commit 9e3872a8 authored by Ralph Giles's avatar Ralph Giles

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's avatarJean-Marc Valin <jmvalin@jmvalin.ca>
parent d43445f3
......@@ -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)
......
......@@ -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,
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment