niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | /* |
| 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 39 | int16_t WebRtcNetEQ_Correlator(DSPInst_t *inst, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | #ifdef SCRATCH |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 41 | int16_t *pw16_scratchPtr, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | #endif |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 43 | int16_t *pw16_data, int16_t w16_dataLen, |
| 44 | int16_t *pw16_corrOut, |
| 45 | int16_t *pw16_corrScale); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 65 | int16_t WebRtcNetEQ_PeakDetection(int16_t *pw16_data, int16_t w16_dataLen, |
| 66 | int16_t w16_nmbPeaks, int16_t fs_mult, |
| 67 | int16_t *pw16_corrIndex, |
| 68 | int16_t *pw16_winners); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 86 | int16_t WebRtcNetEQ_PrblFit(int16_t *pw16_3pts, int16_t *pw16_Ind, |
| 87 | int16_t *pw16_outVal, int16_t fs_mult); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 107 | int16_t WebRtcNetEQ_MinDistortion(const int16_t *pw16_data, |
| 108 | int16_t w16_minLag, int16_t w16_maxLag, |
| 109 | int16_t len, int32_t *pw16_dist); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 125 | void WebRtcNetEQ_RandomVec(uint32_t *w32_seed, int16_t *pw16_randVec, |
| 126 | int16_t w16_len, int16_t w16_incval); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 144 | void WebRtcNetEQ_MixVoiceUnvoice(int16_t *pw16_outData, int16_t *pw16_voicedVec, |
| 145 | int16_t *pw16_unvoicedVec, |
| 146 | int16_t *w16_current_vfraction, |
| 147 | int16_t w16_vfraction_change, int16_t N); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 164 | void WebRtcNetEQ_UnmuteSignal(int16_t *pw16_inVec, int16_t *startMuteFact, |
| 165 | int16_t *pw16_outVec, int16_t unmuteFact, |
| 166 | int16_t N); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 179 | void WebRtcNetEQ_MuteSignal(int16_t *pw16_inout, int16_t muteSlope, |
| 180 | int16_t N); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 193 | int16_t WebRtcNetEQ_CalcFsMult(uint16_t fsHz); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 216 | int WebRtcNetEQ_DownSampleTo4kHz(const int16_t *in, int inLen, uint16_t inFsHz, |
| 217 | int16_t *out, int outLen, int compensateDelay); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 218 | |
| 219 | #endif |
| 220 | |