blob: f728c0979ad88fa5582092db633a2df80d012831 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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/*
12 * Various help functions used by the DSP functions.
13 */
14
15#ifndef DSP_HELPFUNCTIONS_H
16#define DSP_HELPFUNCTIONS_H
17
18#include "typedefs.h"
19
20#include "dsp.h"
21
22/****************************************************************************
23 * WebRtcNetEQ_Correlator(...)
24 *
25 * Calculate signal correlation.
26 *
27 * Input:
28 * - inst : DSP instance
29 * - data : Speech history to do expand from (older history in data[-4..-1])
30 * - dataLen : Length of data
31 *
32 * Output:
33 * - corrOut : CC of downsampled signal
34 * - corrScale : Scale factor for correlation (-Qdomain)
35 *
36 * Return value : Length of correlated data
37 */
38
39WebRtc_Word16 WebRtcNetEQ_Correlator(DSPInst_t *inst,
40#ifdef SCRATCH
41 WebRtc_Word16 *pw16_scratchPtr,
42#endif
43 WebRtc_Word16 *pw16_data, WebRtc_Word16 w16_dataLen,
44 WebRtc_Word16 *pw16_corrOut,
45 WebRtc_Word16 *pw16_corrScale);
46
47/****************************************************************************
48 * WebRtcNetEQ_PeakDetection(...)
49 *
50 * Peak detection with parabolic fit.
51 *
52 * Input:
53 * - data : Data sequence for peak detection
54 * - dataLen : Length of data
55 * - nmbPeaks : Number of peaks to detect
56 * - fs_mult : Sample rate multiplier
57 *
58 * Output:
59 * - corrIndex : Index of the peak
60 * - winner : Value of the peak
61 *
62 * Return value : 0 for ok
63 */
64
65WebRtc_Word16 WebRtcNetEQ_PeakDetection(WebRtc_Word16 *pw16_data, WebRtc_Word16 w16_dataLen,
66 WebRtc_Word16 w16_nmbPeaks, WebRtc_Word16 fs_mult,
67 WebRtc_Word16 *pw16_corrIndex,
68 WebRtc_Word16 *pw16_winners);
69
70/****************************************************************************
71 * WebRtcNetEQ_PrblFit(...)
72 *
73 * Three-point parbola fit.
74 *
75 * Input:
76 * - 3pts : Three input samples
77 * - fs_mult : Sample rate multiplier
78 *
79 * Output:
80 * - Ind : Index of the peak
81 * - outVal : Value of the peak
82 *
83 * Return value : 0 for ok
84 */
85
86WebRtc_Word16 WebRtcNetEQ_PrblFit(WebRtc_Word16 *pw16_3pts, WebRtc_Word16 *pw16_Ind,
87 WebRtc_Word16 *pw16_outVal, WebRtc_Word16 fs_mult);
88
89/****************************************************************************
90 * WebRtcNetEQ_MinDistortion(...)
91 *
92 * Find the lag that results in minimum distortion.
93 *
94 * Input:
95 * - data : Start of speech to perform distortion on, second vector is assumed
96 * to be data[-Lag]
97 * - minLag : Start lag
98 * - maxLag : End lag
99 * - len : Length to correlate
100 *
101 * Output:
102 * - dist : Distorion value
103 *
104 * Return value : Lag for minimum distortion
105 */
106
107WebRtc_Word16 WebRtcNetEQ_MinDistortion(const WebRtc_Word16 *pw16_data,
108 WebRtc_Word16 w16_minLag, WebRtc_Word16 w16_maxLag,
109 WebRtc_Word16 len, WebRtc_Word32 *pw16_dist);
110
111/****************************************************************************
112 * WebRtcNetEQ_RandomVec(...)
113 *
114 * Generate random vector.
115 *
116 * Input:
117 * - seed : Current seed (input/output)
118 * - len : Number of samples to generate
119 * - incVal : Jump step
120 *
121 * Output:
122 * - randVec : Generated random vector
123 */
124
125void WebRtcNetEQ_RandomVec(WebRtc_UWord32 *w32_seed, WebRtc_Word16 *pw16_randVec,
126 WebRtc_Word16 w16_len, WebRtc_Word16 w16_incval);
127
128/****************************************************************************
129 * WebRtcNetEQ_MixVoiceUnvoice(...)
130 *
131 * Mix voiced and unvoiced signal.
132 *
133 * Input:
134 * - voicedVec : Voiced input signal
135 * - unvoicedVec : Unvoiced input signal
136 * - current_vfraction : Current mixing factor
137 * - vfraction_change : Mixing factor change per sample
138 * - N : Number of samples
139 *
140 * Output:
141 * - outData : Mixed signal
142 */
143
144void WebRtcNetEQ_MixVoiceUnvoice(WebRtc_Word16 *pw16_outData, WebRtc_Word16 *pw16_voicedVec,
145 WebRtc_Word16 *pw16_unvoicedVec,
146 WebRtc_Word16 *w16_current_vfraction,
147 WebRtc_Word16 w16_vfraction_change, WebRtc_Word16 N);
148
149/****************************************************************************
150 * WebRtcNetEQ_UnmuteSignal(...)
151 *
152 * Gradually reduce attenuation.
153 *
154 * Input:
155 * - inVec : Input signal
156 * - startMuteFact : Starting attenuation
157 * - unmuteFact : Factor to "unmute" with (Q20)
158 * - N : Number of samples
159 *
160 * Output:
161 * - outVec : Output signal
162 */
163
164void WebRtcNetEQ_UnmuteSignal(WebRtc_Word16 *pw16_inVec, WebRtc_Word16 *startMuteFact,
165 WebRtc_Word16 *pw16_outVec, WebRtc_Word16 unmuteFact,
166 WebRtc_Word16 N);
167
168/****************************************************************************
169 * WebRtcNetEQ_MuteSignal(...)
170 *
171 * Gradually increase attenuation.
172 *
173 * Input:
174 * - inout : Input/output signal
175 * - muteSlope : Slope of muting
176 * - N : Number of samples
177 */
178
179void WebRtcNetEQ_MuteSignal(WebRtc_Word16 *pw16_inout, WebRtc_Word16 muteSlope,
180 WebRtc_Word16 N);
181
182/****************************************************************************
183 * WebRtcNetEQ_CalcFsMult(...)
184 *
185 * Calculate the sample rate divided by 8000.
186 *
187 * Input:
188 * - fsHz : Sample rate in Hz in {8000, 16000, 32000, 48000}.
189 *
190 * Return value : fsHz/8000 for the valid values, 1 for other inputs
191 */
192
193WebRtc_Word16 WebRtcNetEQ_CalcFsMult(WebRtc_UWord16 fsHz);
194
195/****************************************************************************
196 * WebRtcNetEQ_DownSampleTo4kHz(...)
197 *
198 * Lowpass filter and downsample a signal to 4 kHz sample rate.
199 *
200 * Input:
201 * - in : Input signal samples.
202 * - inLen : Number of input samples.
203 * - inFsHz : Input sample rate in Hz.
204 * - outLen : Desired number of samples in decimated signal.
205 * - compensateDelay : If non-zero, compensate for the phase delay of
206 * of the anti-alias filter.
207 *
208 * Output:
209 * - out : Output signal samples.
210 *
211 * Return value : 0 - Ok
212 * -1 - Error
213 *
214 */
215
216int WebRtcNetEQ_DownSampleTo4kHz(const WebRtc_Word16 *in, int inLen, WebRtc_UWord16 inFsHz,
217 WebRtc_Word16 *out, int outLen, int compensateDelay);
218
219#endif
220