1/*
2 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NS_CORE_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NS_CORE_H_
13
14#include "defines.h"
15
16typedef struct NSParaExtract_t_ {
17
18  //bin size of histogram
19  float binSizeLrt;
20  float binSizeSpecFlat;
21  float binSizeSpecDiff;
22  //range of histogram over which lrt threshold is computed
23  float rangeAvgHistLrt;
24  //scale parameters: multiply dominant peaks of the histograms by scale factor to obtain
25  //thresholds for prior model
26  float factor1ModelPars; //for lrt and spectral difference
27  float factor2ModelPars; //for spectral_flatness: used when noise is flatter than speech
28  //peak limit for spectral flatness (varies between 0 and 1)
29  float thresPosSpecFlat;
30  //limit on spacing of two highest peaks in histogram: spacing determined by bin size
31  float limitPeakSpacingSpecFlat;
32  float limitPeakSpacingSpecDiff;
33  //limit on relevance of second peak:
34  float limitPeakWeightsSpecFlat;
35  float limitPeakWeightsSpecDiff;
36  //limit on fluctuation of lrt feature
37  float thresFluctLrt;
38  //limit on the max and min values for the feature thresholds
39  float maxLrt;
40  float minLrt;
41  float maxSpecFlat;
42  float minSpecFlat;
43  float maxSpecDiff;
44  float minSpecDiff;
45  //criteria of weight of histogram peak  to accept/reject feature
46  int thresWeightSpecFlat;
47  int thresWeightSpecDiff;
48
49} NSParaExtract_t;
50
51typedef struct NSinst_t_ {
52
53  WebRtc_UWord32  fs;
54  int             blockLen;
55  int             blockLen10ms;
56  int             windShift;
57  int             outLen;
58  int             anaLen;
59  int             magnLen;
60  int             aggrMode;
61  const float*    window;
62  float           dataBuf[ANAL_BLOCKL_MAX];
63  float           syntBuf[ANAL_BLOCKL_MAX];
64  float           outBuf[3 * BLOCKL_MAX];
65
66  int             initFlag;
67  // parameters for quantile noise estimation
68  float           density[SIMULT* HALF_ANAL_BLOCKL];
69  float           lquantile[SIMULT* HALF_ANAL_BLOCKL];
70  float           quantile[HALF_ANAL_BLOCKL];
71  int             counter[SIMULT];
72  int             updates;
73  // parameters for Wiener filter
74  float           smooth[HALF_ANAL_BLOCKL];
75  float           overdrive;
76  float           denoiseBound;
77  int             gainmap;
78  // fft work arrays.
79  int             ip[IP_LENGTH];
80  float           wfft[W_LENGTH];
81
82  // parameters for new method: some not needed, will reduce/cleanup later
83  WebRtc_Word32   blockInd;                           //frame index counter
84  int             modelUpdatePars[4];                 //parameters for updating or estimating
85  // thresholds/weights for prior model
86  float           priorModelPars[7];                  //parameters for prior model
87  float           noisePrev[HALF_ANAL_BLOCKL];        //noise spectrum from previous frame
88  float           magnPrev[HALF_ANAL_BLOCKL];         //magnitude spectrum of previous frame
89  float           logLrtTimeAvg[HALF_ANAL_BLOCKL];    //log lrt factor with time-smoothing
90  float           priorSpeechProb;                    //prior speech/noise probability
91  float           featureData[7];                     //data for features
92  float           magnAvgPause[HALF_ANAL_BLOCKL];     //conservative noise spectrum estimate
93  float           signalEnergy;                       //energy of magn
94  float           sumMagn;                            //sum of magn
95  float           whiteNoiseLevel;                    //initial noise estimate
96  float           initMagnEst[HALF_ANAL_BLOCKL];      //initial magnitude spectrum estimate
97  float           pinkNoiseNumerator;                 //pink noise parameter: numerator
98  float           pinkNoiseExp;                       //pink noise parameter: power of freq
99  NSParaExtract_t featureExtractionParams;            //parameters for feature extraction
100  //histograms for parameter estimation
101  int             histLrt[HIST_PAR_EST];
102  int             histSpecFlat[HIST_PAR_EST];
103  int             histSpecDiff[HIST_PAR_EST];
104  //quantities for high band estimate
105  float           speechProbHB[HALF_ANAL_BLOCKL];     //final speech/noise prob: prior + LRT
106  float           dataBufHB[ANAL_BLOCKL_MAX];         //buffering data for HB
107
108} NSinst_t;
109
110
111#ifdef __cplusplus
112extern "C" {
113#endif
114
115/****************************************************************************
116 * WebRtcNs_InitCore(...)
117 *
118 * This function initializes a noise suppression instance
119 *
120 * Input:
121 *      - inst          : Instance that should be initialized
122 *      - fs            : Sampling frequency
123 *
124 * Output:
125 *      - inst          : Initialized instance
126 *
127 * Return value         :  0 - Ok
128 *                        -1 - Error
129 */
130int WebRtcNs_InitCore(NSinst_t* inst, WebRtc_UWord32 fs);
131
132/****************************************************************************
133 * WebRtcNs_set_policy_core(...)
134 *
135 * This changes the aggressiveness of the noise suppression method.
136 *
137 * Input:
138 *      - inst          : Instance that should be initialized
139 *      - mode          : 0: Mild (6 dB), 1: Medium (10 dB), 2: Aggressive (15 dB)
140 *
141 * Output:
142 *      - NS_inst      : Initialized instance
143 *
144 * Return value         :  0 - Ok
145 *                        -1 - Error
146 */
147int WebRtcNs_set_policy_core(NSinst_t* inst, int mode);
148
149/****************************************************************************
150 * WebRtcNs_ProcessCore
151 *
152 * Do noise suppression.
153 *
154 * Input:
155 *      - inst          : Instance that should be initialized
156 *      - inFrameLow    : Input speech frame for lower band
157 *      - inFrameHigh   : Input speech frame for higher band
158 *
159 * Output:
160 *      - inst          : Updated instance
161 *      - outFrameLow   : Output speech frame for lower band
162 *      - outFrameHigh  : Output speech frame for higher band
163 *
164 * Return value         :  0 - OK
165 *                        -1 - Error
166 */
167
168
169int WebRtcNs_ProcessCore(NSinst_t* inst,
170                         short* inFrameLow,
171                         short* inFrameHigh,
172                         short* outFrameLow,
173                         short* outFrameHigh);
174
175
176#ifdef __cplusplus
177}
178#endif
179#endif  // WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NS_CORE_H_
180