| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 {-367, 1090, -2706, 9945, 10596, -3318, 1626, -781, 287}, | 27 {-367, 1090, -2706, 9945, 10596, -3318, 1626, -781, 287}, |
| 28 {-325, 953, -2292, 7301, 12963, -3320, 1570, -743, 271}, | 28 {-325, 953, -2292, 7301, 12963, -3320, 1570, -743, 271}, |
| 29 {-240, 693, -1622, 4634, 14809, -2782, 1262, -587, 212}, | 29 {-240, 693, -1622, 4634, 14809, -2782, 1262, -587, 212}, |
| 30 {-125, 358, -817, 2144, 15982, -1668, 721, -329, 118}, | 30 {-125, 358, -817, 2144, 15982, -1668, 721, -329, 118}, |
| 31 { 0, 0, -1, 1, 16380, 1, -1, 0, 0}, | 31 { 0, 0, -1, 1, 16380, 1, -1, 0, 0}, |
| 32 { 118, -329, 721, -1668, 15982, 2144, -817, 358, -125}, | 32 { 118, -329, 721, -1668, 15982, 2144, -817, 358, -125}, |
| 33 { 212, -587, 1262, -2782, 14809, 4634, -1622, 693, -240}, | 33 { 212, -587, 1262, -2782, 14809, 4634, -1622, 693, -240}, |
| 34 { 271, -743, 1570, -3320, 12963, 7301, -2292, 953, -325} | 34 { 271, -743, 1570, -3320, 12963, 7301, -2292, 953, -325} |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 static __inline int32_t CalcLrIntQ(int32_t fixVal, | 37 static __inline size_t CalcLrIntQ(int16_t fixVal, |
| 38 int16_t qDomain) { | 38 int16_t qDomain) { |
| 39 int32_t roundVal = 1 << (qDomain - 1); | 39 int32_t roundVal = 1 << (qDomain - 1); |
| 40 | 40 |
| 41 return (fixVal + roundVal) >> qDomain; | 41 return (fixVal + roundVal) >> qDomain; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void WebRtcIsacfix_PitchFilter(int16_t* indatQQ, // Q10 if type is 1 or 4, | 44 void WebRtcIsacfix_PitchFilter(int16_t* indatQQ, // Q10 if type is 1 or 4, |
| 45 // Q0 if type is 2. | 45 // Q0 if type is 2. |
| 46 int16_t* outdatQQ, | 46 int16_t* outdatQQ, |
| 47 PitchFiltstr* pfp, | 47 PitchFiltstr* pfp, |
| 48 int16_t* lagsQ7, | 48 int16_t* lagsQ7, |
| 49 int16_t* gainsQ12, | 49 int16_t* gainsQ12, |
| 50 int16_t type) { | 50 int16_t type) { |
| 51 int k, ind, cnt; | 51 int k, ind, cnt; |
| 52 int16_t sign = 1; | 52 int16_t sign = 1; |
| 53 int16_t inystateQQ[PITCH_DAMPORDER]; | 53 int16_t inystateQQ[PITCH_DAMPORDER]; |
| 54 int16_t ubufQQ[PITCH_INTBUFFSIZE + QLOOKAHEAD]; | 54 int16_t ubufQQ[PITCH_INTBUFFSIZE + QLOOKAHEAD]; |
| 55 const int16_t Gain = 21299; // 1.3 in Q14 | 55 const int16_t Gain = 21299; // 1.3 in Q14 |
| 56 int16_t oldLagQ7; | 56 int16_t oldLagQ7; |
| 57 int16_t oldGainQ12, lagdeltaQ7, curLagQ7, gaindeltaQ12, curGainQ12; | 57 int16_t oldGainQ12, lagdeltaQ7, curLagQ7, gaindeltaQ12, curGainQ12; |
| 58 int indW32 = 0, frcQQ = 0; | 58 size_t indW32 = 0, frcQQ = 0; |
| 59 const int16_t* fracoeffQQ = NULL; | 59 const int16_t* fracoeffQQ = NULL; |
| 60 | 60 |
| 61 // Assumptions in ARM assembly for WebRtcIsacfix_PitchFilterCoreARM(). | 61 // Assumptions in ARM assembly for WebRtcIsacfix_PitchFilterCoreARM(). |
| 62 COMPILE_ASSERT(PITCH_FRACORDER == 9); | 62 COMPILE_ASSERT(PITCH_FRACORDER == 9); |
| 63 COMPILE_ASSERT(PITCH_DAMPORDER == 5); | 63 COMPILE_ASSERT(PITCH_DAMPORDER == 5); |
| 64 | 64 |
| 65 // Set up buffer and states. | 65 // Set up buffer and states. |
| 66 memcpy(ubufQQ, pfp->ubufQQ, sizeof(pfp->ubufQQ)); | 66 memcpy(ubufQQ, pfp->ubufQQ, sizeof(pfp->ubufQQ)); |
| 67 memcpy(inystateQQ, pfp->ystateQQ, sizeof(inystateQQ)); | 67 memcpy(inystateQQ, pfp->ystateQQ, sizeof(inystateQQ)); |
| 68 | 68 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 WebRtcIsacfix_PitchFilterCore(QLOOKAHEAD, curGainQ12, indW32, 1, inystateQQ, | 134 WebRtcIsacfix_PitchFilterCore(QLOOKAHEAD, curGainQ12, indW32, 1, inystateQQ, |
| 135 ubufQQ, fracoeffQQ, indatQQ, outdatQQ, &ind); | 135 ubufQQ, fracoeffQQ, indatQQ, outdatQQ, &ind); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 | 139 |
| 140 void WebRtcIsacfix_PitchFilterGains(const int16_t* indatQ0, | 140 void WebRtcIsacfix_PitchFilterGains(const int16_t* indatQ0, |
| 141 PitchFiltstr* pfp, | 141 PitchFiltstr* pfp, |
| 142 int16_t* lagsQ7, | 142 int16_t* lagsQ7, |
| 143 int16_t* gainsQ12) { | 143 int16_t* gainsQ12) { |
| 144 int k, n, m, ind, pos, pos3QQ; | 144 int k, n, m; |
| 145 size_t ind, pos, pos3QQ; |
| 145 | 146 |
| 146 int16_t ubufQQ[PITCH_INTBUFFSIZE]; | 147 int16_t ubufQQ[PITCH_INTBUFFSIZE]; |
| 147 int16_t oldLagQ7, lagdeltaQ7, curLagQ7; | 148 int16_t oldLagQ7, lagdeltaQ7, curLagQ7; |
| 148 const int16_t* fracoeffQQ = NULL; | 149 const int16_t* fracoeffQQ = NULL; |
| 149 int16_t scale; | 150 int16_t scale; |
| 150 int16_t cnt = 0, frcQQ, indW16 = 0, tmpW16; | 151 int16_t cnt = 0, tmpW16; |
| 152 size_t frcQQ, indW16 = 0; |
| 151 int32_t tmpW32, tmp2W32, csum1QQ, esumxQQ; | 153 int32_t tmpW32, tmp2W32, csum1QQ, esumxQQ; |
| 152 | 154 |
| 153 // Set up buffer and states. | 155 // Set up buffer and states. |
| 154 memcpy(ubufQQ, pfp->ubufQQ, sizeof(pfp->ubufQQ)); | 156 memcpy(ubufQQ, pfp->ubufQQ, sizeof(pfp->ubufQQ)); |
| 155 oldLagQ7 = pfp->oldlagQ7; | 157 oldLagQ7 = pfp->oldlagQ7; |
| 156 | 158 |
| 157 // No interpolation if pitch lag step is big. | 159 // No interpolation if pitch lag step is big. |
| 158 if (((lagsQ7[0] * 3 >> 1) < oldLagQ7) || (lagsQ7[0] > (oldLagQ7 * 3 >> 1))) { | 160 if (((lagsQ7[0] * 3 >> 1) < oldLagQ7) || (lagsQ7[0] > (oldLagQ7 * 3 >> 1))) { |
| 159 oldLagQ7 = lagsQ7[0]; | 161 oldLagQ7 = lagsQ7[0]; |
| 160 } | 162 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 172 oldLagQ7 = lagsQ7[k]; | 174 oldLagQ7 = lagsQ7[k]; |
| 173 | 175 |
| 174 csum1QQ = 1; | 176 csum1QQ = 1; |
| 175 esumxQQ = 1; | 177 esumxQQ = 1; |
| 176 | 178 |
| 177 // Same as function WebRtcIsacfix_PitchFilter(), we break the pitch | 179 // Same as function WebRtcIsacfix_PitchFilter(), we break the pitch |
| 178 // filtering into two for-loops (5 x 12) below. | 180 // filtering into two for-loops (5 x 12) below. |
| 179 for (cnt = 0; cnt < kSegments; cnt++) { | 181 for (cnt = 0; cnt < kSegments; cnt++) { |
| 180 // Update parameters for each segment. | 182 // Update parameters for each segment. |
| 181 curLagQ7 += lagdeltaQ7; | 183 curLagQ7 += lagdeltaQ7; |
| 182 indW16 = (int16_t)CalcLrIntQ(curLagQ7, 7); | 184 indW16 = CalcLrIntQ(curLagQ7, 7); |
| 183 frcQQ = ((indW16 << 7) + 64 - curLagQ7) >> 4; | 185 frcQQ = ((indW16 << 7) + 64 - curLagQ7) >> 4; |
| 184 | 186 |
| 185 if (frcQQ == PITCH_FRACS) { | 187 if (frcQQ == PITCH_FRACS) { |
| 186 frcQQ = 0; | 188 frcQQ = 0; |
| 187 } | 189 } |
| 188 fracoeffQQ = kIntrpCoef[frcQQ]; | 190 fracoeffQQ = kIntrpCoef[frcQQ]; |
| 189 | 191 |
| 190 pos3QQ = pos - (indW16 + 4); | 192 pos3QQ = pos - (indW16 + 4); |
| 191 | 193 |
| 192 for (n = 0; n < PITCH_SUBFRAME_LEN / kSegments; n++) { | 194 for (n = 0; n < PITCH_SUBFRAME_LEN / kSegments; n++) { |
| 193 // Filter to get fractional pitch. | 195 // Filter to get fractional pitch. |
| 194 | 196 |
| 195 tmpW32 = 0; | 197 tmpW32 = 0; |
| 196 for (m = 0; m < PITCH_FRACORDER; m++) { | 198 for (m = 0; m < PITCH_FRACORDER; m++) { |
| 197 tmpW32 += ubufQQ[pos3QQ + m] * fracoeffQQ[m]; | 199 tmpW32 += ubufQQ[pos3QQ + m] * fracoeffQQ[m]; |
| 198 } | 200 } |
| 199 | 201 |
| 200 // Subtract from input and update buffer. | 202 // Subtract from input and update buffer. |
| 201 ubufQQ[pos] = indatQ0[ind]; | 203 ubufQQ[pos] = indatQ0[ind]; |
| 202 | 204 |
| 203 tmp2W32 = WEBRTC_SPL_MUL_16_32_RSFT14(indatQ0[ind], tmpW32); | 205 tmp2W32 = WEBRTC_SPL_MUL_16_32_RSFT14(indatQ0[ind], tmpW32); |
| 204 tmpW32 += 8192; | 206 tmpW32 += 8192; |
| 205 tmpW16 = (int16_t)(tmpW32 >> 14); | 207 tmpW16 = tmpW32 >> 14; |
| 206 tmpW32 = tmpW16 * tmpW16; | 208 tmpW32 = tmpW16 * tmpW16; |
| 207 | 209 |
| 208 if ((tmp2W32 > 1073700000) || (csum1QQ > 1073700000) || | 210 if ((tmp2W32 > 1073700000) || (csum1QQ > 1073700000) || |
| 209 (tmpW32 > 1073700000) || (esumxQQ > 1073700000)) { // 2^30 | 211 (tmpW32 > 1073700000) || (esumxQQ > 1073700000)) { // 2^30 |
| 210 scale++; | 212 scale++; |
| 211 csum1QQ >>= 1; | 213 csum1QQ >>= 1; |
| 212 esumxQQ >>= 1; | 214 esumxQQ >>= 1; |
| 213 } | 215 } |
| 214 csum1QQ += tmp2W32 >> scale; | 216 csum1QQ += tmp2W32 >> scale; |
| 215 esumxQQ += tmpW32 >> scale; | 217 esumxQQ += tmpW32 >> scale; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 230 } | 232 } |
| 231 gainsQ12[k] = (int16_t)WEBRTC_SPL_SAT(PITCH_MAX_GAIN_Q12, tmpW32, 0); | 233 gainsQ12[k] = (int16_t)WEBRTC_SPL_SAT(PITCH_MAX_GAIN_Q12, tmpW32, 0); |
| 232 } | 234 } |
| 233 | 235 |
| 234 // Export buffer and states. | 236 // Export buffer and states. |
| 235 memcpy(pfp->ubufQQ, ubufQQ + PITCH_FRAME_LEN, sizeof(pfp->ubufQQ)); | 237 memcpy(pfp->ubufQQ, ubufQQ + PITCH_FRAME_LEN, sizeof(pfp->ubufQQ)); |
| 236 pfp->oldlagQ7 = lagsQ7[PITCH_SUBFRAMES - 1]; | 238 pfp->oldlagQ7 = lagsQ7[PITCH_SUBFRAMES - 1]; |
| 237 pfp->oldgainQ12 = gainsQ12[PITCH_SUBFRAMES - 1]; | 239 pfp->oldgainQ12 = gainsQ12[PITCH_SUBFRAMES - 1]; |
| 238 | 240 |
| 239 } | 241 } |
| OLD | NEW |