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
41typedef struct {
42   float angle[240];
43   float d_angle[240];
44   float d2_angle[240];
45   opus_val32 inmem[ANALYSIS_BUF_SIZE];
46   int   mem_fill;                      /* number of usable samples in the buffer */
47   float prev_band_tonality[NB_TBANDS];
48   float prev_tonality;
49   float E[NB_FRAMES][NB_TBANDS];
50   float lowE[NB_TBANDS];
51   float highE[NB_TBANDS];
52   float meanE[NB_TOT_BANDS];
53   float mem[32];
54   float cmean[8];
55   float std[9];
56   float music_prob;
57   float Etracker;
58   float lowECount;
59   int E_count;
60   int last_music;
61   int last_transition;
62   int count;
63   float subframe_mem[3];
64   int analysis_offset;
65   /** Probability of having speech for time i to DETECT_SIZE-1 (and music before).
66       pspeech[0] is the probability that all frames in the window are speech. */
67   float pspeech[DETECT_SIZE];
68   /** Probability of having music for time i to DETECT_SIZE-1 (and speech before).
69       pmusic[0] is the probability that all frames in the window are music. */
70   float pmusic[DETECT_SIZE];
71   float speech_confidence;
72   float music_confidence;
73   int speech_confidence_count;
74   int music_confidence_count;
75   int write_pos;
76   int read_pos;
77   int read_subframe;
78   AnalysisInfo info[DETECT_SIZE];
79} TonalityAnalysisState;
80
81void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info,
82     const CELTMode *celt_mode, const void *x, int len, int offset, int c1, int c2, int C, int lsb_depth, downmix_func downmix);
83
84void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len);
85
86void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, const void *analysis_pcm,
87                 int analysis_frame_size, int frame_size, int c1, int c2, int C, opus_int32 Fs,
88                 int lsb_depth, downmix_func downmix, AnalysisInfo *analysis_info);
89
90#endif
91