Vignesh Venkatasubramanian | 2bd8b54 | 2014-02-20 10:50:35 -0800 | [diff] [blame] | 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 | |
| 34 | #define NB_FRAMES 8 |
| 35 | #define NB_TBANDS 18 |
| 36 | #define NB_TOT_BANDS 21 |
| 37 | #define ANALYSIS_BUF_SIZE 720 /* 15 ms at 48 kHz */ |
| 38 | |
| 39 | #define DETECT_SIZE 200 |
| 40 | |
| 41 | typedef struct { |
flim | c91ee5b | 2016-01-26 14:33:44 +0100 | [diff] [blame] | 42 | int arch; |
| 43 | #define TONALITY_ANALYSIS_RESET_START angle |
Vignesh Venkatasubramanian | 2bd8b54 | 2014-02-20 10:50:35 -0800 | [diff] [blame] | 44 | float angle[240]; |
| 45 | float d_angle[240]; |
| 46 | float d2_angle[240]; |
| 47 | opus_val32 inmem[ANALYSIS_BUF_SIZE]; |
| 48 | int mem_fill; /* number of usable samples in the buffer */ |
| 49 | float prev_band_tonality[NB_TBANDS]; |
| 50 | float prev_tonality; |
| 51 | float E[NB_FRAMES][NB_TBANDS]; |
| 52 | float lowE[NB_TBANDS]; |
| 53 | float highE[NB_TBANDS]; |
| 54 | float meanE[NB_TOT_BANDS]; |
| 55 | float mem[32]; |
| 56 | float cmean[8]; |
| 57 | float std[9]; |
| 58 | float music_prob; |
| 59 | float Etracker; |
| 60 | float lowECount; |
| 61 | int E_count; |
| 62 | int last_music; |
| 63 | int last_transition; |
| 64 | int count; |
| 65 | float subframe_mem[3]; |
| 66 | int analysis_offset; |
| 67 | /** Probability of having speech for time i to DETECT_SIZE-1 (and music before). |
| 68 | pspeech[0] is the probability that all frames in the window are speech. */ |
| 69 | float pspeech[DETECT_SIZE]; |
| 70 | /** Probability of having music for time i to DETECT_SIZE-1 (and speech before). |
| 71 | pmusic[0] is the probability that all frames in the window are music. */ |
| 72 | float pmusic[DETECT_SIZE]; |
| 73 | float speech_confidence; |
| 74 | float music_confidence; |
| 75 | int speech_confidence_count; |
| 76 | int music_confidence_count; |
| 77 | int write_pos; |
| 78 | int read_pos; |
| 79 | int read_subframe; |
| 80 | AnalysisInfo info[DETECT_SIZE]; |
| 81 | } TonalityAnalysisState; |
| 82 | |
flim | c91ee5b | 2016-01-26 14:33:44 +0100 | [diff] [blame] | 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); |
| 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); |
Vignesh Venkatasubramanian | 2bd8b54 | 2014-02-20 10:50:35 -0800 | [diff] [blame] | 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 |