michael@0: /* Copyright (c) 2011 Xiph.Org Foundation michael@0: Written by Jean-Marc Valin */ michael@0: /* michael@0: Redistribution and use in source and binary forms, with or without michael@0: modification, are permitted provided that the following conditions michael@0: are met: michael@0: michael@0: - Redistributions of source code must retain the above copyright michael@0: notice, this list of conditions and the following disclaimer. michael@0: michael@0: - Redistributions in binary form must reproduce the above copyright michael@0: notice, this list of conditions and the following disclaimer in the michael@0: documentation and/or other materials provided with the distribution. michael@0: michael@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR michael@0: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF michael@0: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING michael@0: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS michael@0: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifndef ANALYSIS_H michael@0: #define ANALYSIS_H michael@0: michael@0: #include "celt.h" michael@0: #include "opus_private.h" michael@0: michael@0: #define NB_FRAMES 8 michael@0: #define NB_TBANDS 18 michael@0: #define NB_TOT_BANDS 21 michael@0: #define ANALYSIS_BUF_SIZE 720 /* 15 ms at 48 kHz */ michael@0: michael@0: #define DETECT_SIZE 200 michael@0: michael@0: typedef struct { michael@0: float angle[240]; michael@0: float d_angle[240]; michael@0: float d2_angle[240]; michael@0: opus_val32 inmem[ANALYSIS_BUF_SIZE]; michael@0: int mem_fill; /* number of usable samples in the buffer */ michael@0: float prev_band_tonality[NB_TBANDS]; michael@0: float prev_tonality; michael@0: float E[NB_FRAMES][NB_TBANDS]; michael@0: float lowE[NB_TBANDS]; michael@0: float highE[NB_TBANDS]; michael@0: float meanE[NB_TOT_BANDS]; michael@0: float mem[32]; michael@0: float cmean[8]; michael@0: float std[9]; michael@0: float music_prob; michael@0: float Etracker; michael@0: float lowECount; michael@0: int E_count; michael@0: int last_music; michael@0: int last_transition; michael@0: int count; michael@0: float subframe_mem[3]; michael@0: int analysis_offset; michael@0: /** Probability of having speech for time i to DETECT_SIZE-1 (and music before). michael@0: pspeech[0] is the probability that all frames in the window are speech. */ michael@0: float pspeech[DETECT_SIZE]; michael@0: /** Probability of having music for time i to DETECT_SIZE-1 (and speech before). michael@0: pmusic[0] is the probability that all frames in the window are music. */ michael@0: float pmusic[DETECT_SIZE]; michael@0: float speech_confidence; michael@0: float music_confidence; michael@0: int speech_confidence_count; michael@0: int music_confidence_count; michael@0: int write_pos; michael@0: int read_pos; michael@0: int read_subframe; michael@0: AnalysisInfo info[DETECT_SIZE]; michael@0: } TonalityAnalysisState; michael@0: michael@0: void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, michael@0: const CELTMode *celt_mode, const void *x, int len, int offset, int c1, int c2, int C, int lsb_depth, downmix_func downmix); michael@0: michael@0: void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len); michael@0: michael@0: void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, const void *analysis_pcm, michael@0: int analysis_frame_size, int frame_size, int c1, int c2, int C, opus_int32 Fs, michael@0: int lsb_depth, downmix_func downmix, AnalysisInfo *analysis_info); michael@0: michael@0: #endif