• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2011 Xiph.Org Foundation
2    Written by Jean-Marc Valin */
3 /*
4    Redistribution and use in source and binary forms, with or without
5    modification, are permitted provided that the following conditions
6    are met:
7 
8    - Redistributions of source code must retain the above copyright
9    notice, this list of conditions and the following disclaimer.
10 
11    - Redistributions in binary form must reproduce the above copyright
12    notice, this list of conditions and the following disclaimer in the
13    documentation and/or other materials provided with the distribution.
14 
15    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
19    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef ANALYSIS_H
29 #define ANALYSIS_H
30 
31 #include "celt.h"
32 #include "opus_private.h"
33 #include "mlp.h"
34 
35 #define NB_FRAMES 8
36 #define NB_TBANDS 18
37 #define ANALYSIS_BUF_SIZE 720 /* 30 ms at 24 kHz */
38 
39 /* At that point we can stop counting frames because it no longer matters. */
40 #define ANALYSIS_COUNT_MAX 10000
41 
42 #define DETECT_SIZE 100
43 
44 /* Uncomment this to print the MLP features on stdout. */
45 /*#define MLP_TRAINING*/
46 
47 typedef struct {
48    int arch;
49    int application;
50    opus_int32 Fs;
51 #define TONALITY_ANALYSIS_RESET_START angle
52    float angle[240];
53    float d_angle[240];
54    float d2_angle[240];
55    opus_val32 inmem[ANALYSIS_BUF_SIZE];
56    int   mem_fill;                      /* number of usable samples in the buffer */
57    float prev_band_tonality[NB_TBANDS];
58    float prev_tonality;
59    int prev_bandwidth;
60    float E[NB_FRAMES][NB_TBANDS];
61    float logE[NB_FRAMES][NB_TBANDS];
62    float lowE[NB_TBANDS];
63    float highE[NB_TBANDS];
64    float meanE[NB_TBANDS+1];
65    float mem[32];
66    float cmean[8];
67    float std[9];
68    float Etracker;
69    float lowECount;
70    int E_count;
71    int count;
72    int analysis_offset;
73    int write_pos;
74    int read_pos;
75    int read_subframe;
76    float hp_ener_accum;
77    int initialized;
78    float rnn_state[MAX_NEURONS];
79    opus_val32 downmix_state[3];
80    AnalysisInfo info[DETECT_SIZE];
81 } TonalityAnalysisState;
82 
83 /** Initialize a TonalityAnalysisState struct.
84  *
85  * This performs some possibly slow initialization steps which should
86  * not be repeated every analysis step. No allocated memory is retained
87  * by the state struct, so no cleanup call is required.
88  */
89 void tonality_analysis_init(TonalityAnalysisState *analysis, opus_int32 Fs);
90 
91 /** Reset a TonalityAnalysisState stuct.
92  *
93  * Call this when there's a discontinuity in the data.
94  */
95 void tonality_analysis_reset(TonalityAnalysisState *analysis);
96 
97 void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len);
98 
99 void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, const void *analysis_pcm,
100                  int analysis_frame_size, int frame_size, int c1, int c2, int C, opus_int32 Fs,
101                  int lsb_depth, downmix_func downmix, AnalysisInfo *analysis_info);
102 
103 #endif
104