ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 /* Copyright (C) 2005 Analog Devices */
TMBOY 47:9e361da97763 2 /**
TMBOY 47:9e361da97763 3 @file ltp_bfin.h
TMBOY 47:9e361da97763 4 @author Jean-Marc Valin
TMBOY 47:9e361da97763 5 @brief Long-Term Prediction functions (Blackfin version)
TMBOY 47:9e361da97763 6 */
TMBOY 47:9e361da97763 7 /*
TMBOY 47:9e361da97763 8 Redistribution and use in source and binary forms, with or without
TMBOY 47:9e361da97763 9 modification, are permitted provided that the following conditions
TMBOY 47:9e361da97763 10 are met:
TMBOY 47:9e361da97763 11
TMBOY 47:9e361da97763 12 - Redistributions of source code must retain the above copyright
TMBOY 47:9e361da97763 13 notice, this list of conditions and the following disclaimer.
TMBOY 47:9e361da97763 14
TMBOY 47:9e361da97763 15 - Redistributions in binary form must reproduce the above copyright
TMBOY 47:9e361da97763 16 notice, this list of conditions and the following disclaimer in the
TMBOY 47:9e361da97763 17 documentation and/or other materials provided with the distribution.
TMBOY 47:9e361da97763 18
TMBOY 47:9e361da97763 19 - Neither the name of the Xiph.org Foundation nor the names of its
TMBOY 47:9e361da97763 20 contributors may be used to endorse or promote products derived from
TMBOY 47:9e361da97763 21 this software without specific prior written permission.
TMBOY 47:9e361da97763 22
TMBOY 47:9e361da97763 23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
TMBOY 47:9e361da97763 24 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
TMBOY 47:9e361da97763 25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
TMBOY 47:9e361da97763 26 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
TMBOY 47:9e361da97763 27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
TMBOY 47:9e361da97763 28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
TMBOY 47:9e361da97763 29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
TMBOY 47:9e361da97763 30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
TMBOY 47:9e361da97763 31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
TMBOY 47:9e361da97763 32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
TMBOY 47:9e361da97763 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TMBOY 47:9e361da97763 34 */
TMBOY 47:9e361da97763 35
TMBOY 47:9e361da97763 36 #define OVERRIDE_INNER_PROD
TMBOY 47:9e361da97763 37 spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len)
TMBOY 47:9e361da97763 38 {
TMBOY 47:9e361da97763 39 spx_word32_t sum=0;
TMBOY 47:9e361da97763 40 __asm__ __volatile__ (
TMBOY 47:9e361da97763 41 "P0 = %3;\n\t"
TMBOY 47:9e361da97763 42 "P1 = %1;\n\t"
TMBOY 47:9e361da97763 43 "P2 = %2;\n\t"
TMBOY 47:9e361da97763 44 "I0 = P1;\n\t"
TMBOY 47:9e361da97763 45 "I1 = P2;\n\t"
TMBOY 47:9e361da97763 46 "L0 = 0;\n\t"
TMBOY 47:9e361da97763 47 "L1 = 0;\n\t"
TMBOY 47:9e361da97763 48 "A0 = 0;\n\t"
TMBOY 47:9e361da97763 49 "R0.L = W[I0++] || R1.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 50 "LOOP inner%= LC0 = P0;\n\t"
TMBOY 47:9e361da97763 51 "LOOP_BEGIN inner%=;\n\t"
TMBOY 47:9e361da97763 52 "A0 += R0.L*R1.L (IS) || R0.L = W[I0++] || R1.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 53 "LOOP_END inner%=;\n\t"
TMBOY 47:9e361da97763 54 "A0 += R0.L*R1.L (IS);\n\t"
TMBOY 47:9e361da97763 55 "A0 = A0 >>> 6;\n\t"
TMBOY 47:9e361da97763 56 "R0 = A0;\n\t"
TMBOY 47:9e361da97763 57 "%0 = R0;\n\t"
TMBOY 47:9e361da97763 58 : "=m" (sum)
TMBOY 47:9e361da97763 59 : "m" (x), "m" (y), "d" (len-1)
TMBOY 47:9e361da97763 60 : "P0", "P1", "P2", "R0", "R1", "A0", "I0", "I1", "L0", "L1", "R3"
TMBOY 47:9e361da97763 61 );
TMBOY 47:9e361da97763 62 return sum;
TMBOY 47:9e361da97763 63 }
TMBOY 47:9e361da97763 64
TMBOY 47:9e361da97763 65 #define OVERRIDE_PITCH_XCORR
TMBOY 47:9e361da97763 66 void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word32_t *corr, int len, int nb_pitch, char *stack)
TMBOY 47:9e361da97763 67 {
TMBOY 47:9e361da97763 68 corr += nb_pitch - 1;
TMBOY 47:9e361da97763 69 __asm__ __volatile__ (
TMBOY 47:9e361da97763 70 "P2 = %0;\n\t"
TMBOY 47:9e361da97763 71 "I0 = P2;\n\t" /* x in I0 */
TMBOY 47:9e361da97763 72 "B0 = P2;\n\t" /* x in B0 */
TMBOY 47:9e361da97763 73 "R0 = %3;\n\t" /* len in R0 */
TMBOY 47:9e361da97763 74 "P3 = %3;\n\t"
TMBOY 47:9e361da97763 75 "P3 += -2;\n\t" /* len in R0 */
TMBOY 47:9e361da97763 76 "P4 = %4;\n\t" /* nb_pitch in R0 */
TMBOY 47:9e361da97763 77 "R1 = R0 << 1;\n\t" /* number of bytes in x */
TMBOY 47:9e361da97763 78 "L0 = R1;\n\t"
TMBOY 47:9e361da97763 79 "P0 = %1;\n\t"
TMBOY 47:9e361da97763 80
TMBOY 47:9e361da97763 81 "P1 = %2;\n\t"
TMBOY 47:9e361da97763 82 "B1 = P1;\n\t"
TMBOY 47:9e361da97763 83 "L1 = 0;\n\t" /*Disable looping on I1*/
TMBOY 47:9e361da97763 84
TMBOY 47:9e361da97763 85 "r0 = [I0++];\n\t"
TMBOY 47:9e361da97763 86 "LOOP pitch%= LC0 = P4 >> 1;\n\t"
TMBOY 47:9e361da97763 87 "LOOP_BEGIN pitch%=;\n\t"
TMBOY 47:9e361da97763 88 "I1 = P0;\n\t"
TMBOY 47:9e361da97763 89 "A1 = A0 = 0;\n\t"
TMBOY 47:9e361da97763 90 "R1 = [I1++];\n\t"
TMBOY 47:9e361da97763 91 "LOOP inner_prod%= LC1 = P3 >> 1;\n\t"
TMBOY 47:9e361da97763 92 "LOOP_BEGIN inner_prod%=;\n\t"
TMBOY 47:9e361da97763 93 "A1 += R0.L*R1.H, A0 += R0.L*R1.L (IS) || R1.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 94 "A1 += R0.H*R1.L, A0 += R0.H*R1.H (IS) || R1.H = W[I1++] || R0 = [I0++];\n\t"
TMBOY 47:9e361da97763 95 "LOOP_END inner_prod%=;\n\t"
TMBOY 47:9e361da97763 96 "A1 += R0.L*R1.H, A0 += R0.L*R1.L (IS) || R1.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 97 "A1 += R0.H*R1.L, A0 += R0.H*R1.H (IS) || R0 = [I0++];\n\t"
TMBOY 47:9e361da97763 98 "A0 = A0 >>> 6;\n\t"
TMBOY 47:9e361da97763 99 "A1 = A1 >>> 6;\n\t"
TMBOY 47:9e361da97763 100 "R2 = A0, R3 = A1;\n\t"
TMBOY 47:9e361da97763 101 "[P1--] = r2;\n\t"
TMBOY 47:9e361da97763 102 "[P1--] = r3;\n\t"
TMBOY 47:9e361da97763 103 "P0 += 4;\n\t"
TMBOY 47:9e361da97763 104 "LOOP_END pitch%=;\n\t"
TMBOY 47:9e361da97763 105 "L0 = 0;\n\t"
TMBOY 47:9e361da97763 106 : : "m" (_x), "m" (_y), "m" (corr), "m" (len), "m" (nb_pitch)
TMBOY 47:9e361da97763 107 : "A0", "A1", "P0", "P1", "P2", "P3", "P4", "R0", "R1", "R2", "R3", "I0", "I1", "L0", "L1", "B0", "B1", "memory"
TMBOY 47:9e361da97763 108 );
TMBOY 47:9e361da97763 109 }
TMBOY 47:9e361da97763 110
TMBOY 47:9e361da97763 111 #define OVERRIDE_COMPUTE_PITCH_ERROR
TMBOY 47:9e361da97763 112 static inline spx_word32_t compute_pitch_error(spx_word16_t *C, spx_word16_t *g, spx_word16_t pitch_control)
TMBOY 47:9e361da97763 113 {
TMBOY 47:9e361da97763 114 spx_word32_t sum;
TMBOY 47:9e361da97763 115 __asm__ __volatile__
TMBOY 47:9e361da97763 116 (
TMBOY 47:9e361da97763 117 "A0 = 0;\n\t"
TMBOY 47:9e361da97763 118
TMBOY 47:9e361da97763 119 "R0 = W[%1++];\n\t"
TMBOY 47:9e361da97763 120 "R1.L = %2.L*%5.L (IS);\n\t"
TMBOY 47:9e361da97763 121 "A0 += R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
TMBOY 47:9e361da97763 122
TMBOY 47:9e361da97763 123 "R1.L = %3.L*%5.L (IS);\n\t"
TMBOY 47:9e361da97763 124 "A0 += R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
TMBOY 47:9e361da97763 125
TMBOY 47:9e361da97763 126 "R1.L = %4.L*%5.L (IS);\n\t"
TMBOY 47:9e361da97763 127 "A0 += R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
TMBOY 47:9e361da97763 128
TMBOY 47:9e361da97763 129 "R1.L = %2.L*%3.L (IS);\n\t"
TMBOY 47:9e361da97763 130 "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
TMBOY 47:9e361da97763 131
TMBOY 47:9e361da97763 132 "R1.L = %4.L*%3.L (IS);\n\t"
TMBOY 47:9e361da97763 133 "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
TMBOY 47:9e361da97763 134
TMBOY 47:9e361da97763 135 "R1.L = %4.L*%2.L (IS);\n\t"
TMBOY 47:9e361da97763 136 "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
TMBOY 47:9e361da97763 137
TMBOY 47:9e361da97763 138 "R1.L = %2.L*%2.L (IS);\n\t"
TMBOY 47:9e361da97763 139 "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
TMBOY 47:9e361da97763 140
TMBOY 47:9e361da97763 141 "R1.L = %3.L*%3.L (IS);\n\t"
TMBOY 47:9e361da97763 142 "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
TMBOY 47:9e361da97763 143
TMBOY 47:9e361da97763 144 "R1.L = %4.L*%4.L (IS);\n\t"
TMBOY 47:9e361da97763 145 "A0 -= R1.L*R0.L (IS);\n\t"
TMBOY 47:9e361da97763 146
TMBOY 47:9e361da97763 147 "%0 = A0;\n\t"
TMBOY 47:9e361da97763 148 : "=&D" (sum), "=a" (C)
TMBOY 47:9e361da97763 149 : "d" (g[0]), "d" (g[1]), "d" (g[2]), "d" (pitch_control), "1" (C)
TMBOY 47:9e361da97763 150 : "R0", "R1", "R2", "A0"
TMBOY 47:9e361da97763 151 );
TMBOY 47:9e361da97763 152 return sum;
TMBOY 47:9e361da97763 153 }
TMBOY 47:9e361da97763 154
TMBOY 47:9e361da97763 155 #define OVERRIDE_OPEN_LOOP_NBEST_PITCH
TMBOY 47:9e361da97763 156 #ifdef OVERRIDE_OPEN_LOOP_NBEST_PITCH
TMBOY 47:9e361da97763 157 void open_loop_nbest_pitch(spx_word16_t *sw, int start, int end, int len, int *pitch, spx_word16_t *gain, int N, char *stack)
TMBOY 47:9e361da97763 158 {
TMBOY 47:9e361da97763 159 int i,j,k;
TMBOY 47:9e361da97763 160 VARDECL(spx_word32_t *best_score);
TMBOY 47:9e361da97763 161 VARDECL(spx_word32_t *best_ener);
TMBOY 47:9e361da97763 162 spx_word32_t e0;
TMBOY 47:9e361da97763 163 VARDECL(spx_word32_t *corr);
TMBOY 47:9e361da97763 164 VARDECL(spx_word32_t *energy);
TMBOY 47:9e361da97763 165
TMBOY 47:9e361da97763 166 ALLOC(best_score, N, spx_word32_t);
TMBOY 47:9e361da97763 167 ALLOC(best_ener, N, spx_word32_t);
TMBOY 47:9e361da97763 168 ALLOC(corr, end-start+1, spx_word32_t);
TMBOY 47:9e361da97763 169 ALLOC(energy, end-start+2, spx_word32_t);
TMBOY 47:9e361da97763 170
TMBOY 47:9e361da97763 171 for (i=0;i<N;i++)
TMBOY 47:9e361da97763 172 {
TMBOY 47:9e361da97763 173 best_score[i]=-1;
TMBOY 47:9e361da97763 174 best_ener[i]=0;
TMBOY 47:9e361da97763 175 pitch[i]=start;
TMBOY 47:9e361da97763 176 }
TMBOY 47:9e361da97763 177
TMBOY 47:9e361da97763 178 energy[0]=inner_prod(sw-start, sw-start, len);
TMBOY 47:9e361da97763 179 e0=inner_prod(sw, sw, len);
TMBOY 47:9e361da97763 180
TMBOY 47:9e361da97763 181 /* energy update -------------------------------------*/
TMBOY 47:9e361da97763 182
TMBOY 47:9e361da97763 183 __asm__ __volatile__
TMBOY 47:9e361da97763 184 (
TMBOY 47:9e361da97763 185 " P0 = %0;\n\t"
TMBOY 47:9e361da97763 186 " I1 = %1;\n\t"
TMBOY 47:9e361da97763 187 " L1 = 0;\n\t"
TMBOY 47:9e361da97763 188 " I2 = %2;\n\t"
TMBOY 47:9e361da97763 189 " L2 = 0;\n\t"
TMBOY 47:9e361da97763 190 " R2 = [P0++];\n\t"
TMBOY 47:9e361da97763 191 " R3 = 0;\n\t"
TMBOY 47:9e361da97763 192 " LSETUP (eu1, eu2) LC1 = %3;\n\t"
TMBOY 47:9e361da97763 193 "eu1: R1.L = W [I1--] || R0.L = W [I2--] ;\n\t"
TMBOY 47:9e361da97763 194 " R1 = R1.L * R1.L (IS);\n\t"
TMBOY 47:9e361da97763 195 " R0 = R0.L * R0.L (IS);\n\t"
TMBOY 47:9e361da97763 196 " R1 >>>= 6;\n\t"
TMBOY 47:9e361da97763 197 " R1 = R1 + R2;\n\t"
TMBOY 47:9e361da97763 198 " R0 >>>= 6;\n\t"
TMBOY 47:9e361da97763 199 " R1 = R1 - R0;\n\t"
TMBOY 47:9e361da97763 200 " R2 = MAX(R1,R3);\n\t"
TMBOY 47:9e361da97763 201 "eu2: [P0++] = R2;\n\t"
TMBOY 47:9e361da97763 202 : : "d" (energy), "d" (&sw[-start-1]), "d" (&sw[-start+len-1]),
TMBOY 47:9e361da97763 203 "a" (end-start)
TMBOY 47:9e361da97763 204 : "P0", "I1", "I2", "R0", "R1", "R2", "R3"
TMBOY 47:9e361da97763 205 #if (__GNUC__ == 4)
TMBOY 47:9e361da97763 206 , "LC1"
TMBOY 47:9e361da97763 207 #endif
TMBOY 47:9e361da97763 208 );
TMBOY 47:9e361da97763 209
TMBOY 47:9e361da97763 210 pitch_xcorr(sw, sw-end, corr, len, end-start+1, stack);
TMBOY 47:9e361da97763 211
TMBOY 47:9e361da97763 212 /* FIXME: Fixed-point and floating-point code should be merged */
TMBOY 47:9e361da97763 213 {
TMBOY 47:9e361da97763 214 VARDECL(spx_word16_t *corr16);
TMBOY 47:9e361da97763 215 VARDECL(spx_word16_t *ener16);
TMBOY 47:9e361da97763 216 ALLOC(corr16, end-start+1, spx_word16_t);
TMBOY 47:9e361da97763 217 ALLOC(ener16, end-start+1, spx_word16_t);
TMBOY 47:9e361da97763 218 /* Normalize to 180 so we can square it and it still fits in 16 bits */
TMBOY 47:9e361da97763 219 normalize16(corr, corr16, 180, end-start+1);
TMBOY 47:9e361da97763 220 normalize16(energy, ener16, 180, end-start+1);
TMBOY 47:9e361da97763 221
TMBOY 47:9e361da97763 222 if (N == 1) {
TMBOY 47:9e361da97763 223 /* optimised asm to handle N==1 case */
TMBOY 47:9e361da97763 224 __asm__ __volatile__
TMBOY 47:9e361da97763 225 (
TMBOY 47:9e361da97763 226 " I0 = %1;\n\t" /* I0: corr16[] */
TMBOY 47:9e361da97763 227 " L0 = 0;\n\t"
TMBOY 47:9e361da97763 228 " I1 = %2;\n\t" /* I1: energy */
TMBOY 47:9e361da97763 229 " L1 = 0;\n\t"
TMBOY 47:9e361da97763 230 " R2 = -1;\n\t" /* R2: best score */
TMBOY 47:9e361da97763 231 " R3 = 0;\n\t" /* R3: best energy */
TMBOY 47:9e361da97763 232 " P0 = %4;\n\t" /* P0: best pitch */
TMBOY 47:9e361da97763 233 " P1 = %4;\n\t" /* P1: counter */
TMBOY 47:9e361da97763 234 " LSETUP (sl1, sl2) LC1 = %3;\n\t"
TMBOY 47:9e361da97763 235 "sl1: R0.L = W [I0++] || R1.L = W [I1++];\n\t"
TMBOY 47:9e361da97763 236 " R0 = R0.L * R0.L (IS);\n\t"
TMBOY 47:9e361da97763 237 " R1 += 1;\n\t"
TMBOY 47:9e361da97763 238 " R4 = R0.L * R3.L;\n\t"
TMBOY 47:9e361da97763 239 " R5 = R2.L * R1.L;\n\t"
TMBOY 47:9e361da97763 240 " cc = R5 < R4;\n\t"
TMBOY 47:9e361da97763 241 " if cc R2 = R0;\n\t"
TMBOY 47:9e361da97763 242 " if cc R3 = R1;\n\t"
TMBOY 47:9e361da97763 243 " if cc P0 = P1;\n\t"
TMBOY 47:9e361da97763 244 "sl2: P1 += 1;\n\t"
TMBOY 47:9e361da97763 245 " %0 = P0;\n\t"
TMBOY 47:9e361da97763 246 : "=&d" (pitch[0])
TMBOY 47:9e361da97763 247 : "a" (corr16), "a" (ener16), "a" (end+1-start), "d" (start)
TMBOY 47:9e361da97763 248 : "P0", "P1", "I0", "I1", "R0", "R1", "R2", "R3", "R4", "R5"
TMBOY 47:9e361da97763 249 #if (__GNUC__ == 4)
TMBOY 47:9e361da97763 250 , "LC1"
TMBOY 47:9e361da97763 251 #endif
TMBOY 47:9e361da97763 252 );
TMBOY 47:9e361da97763 253
TMBOY 47:9e361da97763 254 }
TMBOY 47:9e361da97763 255 else {
TMBOY 47:9e361da97763 256 for (i=start;i<=end;i++)
TMBOY 47:9e361da97763 257 {
TMBOY 47:9e361da97763 258 spx_word16_t tmp = MULT16_16_16(corr16[i-start],corr16[i-start]);
TMBOY 47:9e361da97763 259 /* Instead of dividing the tmp by the energy, we multiply on the other side */
TMBOY 47:9e361da97763 260 if (MULT16_16(tmp,best_ener[N-1])>MULT16_16(best_score[N-1],ADD16(1,ener16[i-start])))
TMBOY 47:9e361da97763 261 {
TMBOY 47:9e361da97763 262 /* We can safely put it last and then check */
TMBOY 47:9e361da97763 263 best_score[N-1]=tmp;
TMBOY 47:9e361da97763 264 best_ener[N-1]=ener16[i-start]+1;
TMBOY 47:9e361da97763 265 pitch[N-1]=i;
TMBOY 47:9e361da97763 266 /* Check if it comes in front of others */
TMBOY 47:9e361da97763 267 for (j=0;j<N-1;j++)
TMBOY 47:9e361da97763 268 {
TMBOY 47:9e361da97763 269 if (MULT16_16(tmp,best_ener[j])>MULT16_16(best_score[j],ADD16(1,ener16[i-start])))
TMBOY 47:9e361da97763 270 {
TMBOY 47:9e361da97763 271 for (k=N-1;k>j;k--)
TMBOY 47:9e361da97763 272 {
TMBOY 47:9e361da97763 273 best_score[k]=best_score[k-1];
TMBOY 47:9e361da97763 274 best_ener[k]=best_ener[k-1];
TMBOY 47:9e361da97763 275 pitch[k]=pitch[k-1];
TMBOY 47:9e361da97763 276 }
TMBOY 47:9e361da97763 277 best_score[j]=tmp;
TMBOY 47:9e361da97763 278 best_ener[j]=ener16[i-start]+1;
TMBOY 47:9e361da97763 279 pitch[j]=i;
TMBOY 47:9e361da97763 280 break;
TMBOY 47:9e361da97763 281 }
TMBOY 47:9e361da97763 282 }
TMBOY 47:9e361da97763 283 }
TMBOY 47:9e361da97763 284 }
TMBOY 47:9e361da97763 285 }
TMBOY 47:9e361da97763 286 }
TMBOY 47:9e361da97763 287
TMBOY 47:9e361da97763 288 /* Compute open-loop gain */
TMBOY 47:9e361da97763 289 if (gain)
TMBOY 47:9e361da97763 290 {
TMBOY 47:9e361da97763 291 for (j=0;j<N;j++)
TMBOY 47:9e361da97763 292 {
TMBOY 47:9e361da97763 293 spx_word16_t g;
TMBOY 47:9e361da97763 294 i=pitch[j];
TMBOY 47:9e361da97763 295 g = DIV32(corr[i-start], 10+SHR32(MULT16_16(spx_sqrt(e0),spx_sqrt(energy[i-start])),6));
TMBOY 47:9e361da97763 296 /* FIXME: g = max(g,corr/energy) */
TMBOY 47:9e361da97763 297 if (g<0)
TMBOY 47:9e361da97763 298 g = 0;
TMBOY 47:9e361da97763 299 gain[j]=g;
TMBOY 47:9e361da97763 300 }
TMBOY 47:9e361da97763 301 }
TMBOY 47:9e361da97763 302 }
TMBOY 47:9e361da97763 303 #endif
TMBOY 47:9e361da97763 304
TMBOY 47:9e361da97763 305 #define OVERRIDE_PITCH_GAIN_SEARCH_3TAP_VQ
TMBOY 47:9e361da97763 306 #ifdef OVERRIDE_PITCH_GAIN_SEARCH_3TAP_VQ
TMBOY 47:9e361da97763 307 static int pitch_gain_search_3tap_vq(
TMBOY 47:9e361da97763 308 const signed char *gain_cdbk,
TMBOY 47:9e361da97763 309 int gain_cdbk_size,
TMBOY 47:9e361da97763 310 spx_word16_t *C16,
TMBOY 47:9e361da97763 311 spx_word16_t max_gain
TMBOY 47:9e361da97763 312 )
TMBOY 47:9e361da97763 313 {
TMBOY 47:9e361da97763 314 const signed char *ptr=gain_cdbk;
TMBOY 47:9e361da97763 315 int best_cdbk=0;
TMBOY 47:9e361da97763 316 spx_word32_t best_sum=-VERY_LARGE32;
TMBOY 47:9e361da97763 317 spx_word32_t sum=0;
TMBOY 47:9e361da97763 318 spx_word16_t g[3];
TMBOY 47:9e361da97763 319 spx_word16_t pitch_control=64;
TMBOY 47:9e361da97763 320 spx_word16_t gain_sum;
TMBOY 47:9e361da97763 321 int i;
TMBOY 47:9e361da97763 322
TMBOY 47:9e361da97763 323 /* fast asm version of VQ codebook search */
TMBOY 47:9e361da97763 324
TMBOY 47:9e361da97763 325 __asm__ __volatile__
TMBOY 47:9e361da97763 326 (
TMBOY 47:9e361da97763 327
TMBOY 47:9e361da97763 328 " P0 = %2;\n\t" /* P0: ptr to gain_cdbk */
TMBOY 47:9e361da97763 329 " L1 = 0;\n\t" /* no circ addr for L1 */
TMBOY 47:9e361da97763 330 " %0 = 0;\n\t" /* %0: best_sum */
TMBOY 47:9e361da97763 331 " %1 = 0;\n\t" /* %1: best_cbdk */
TMBOY 47:9e361da97763 332 " P1 = 0;\n\t" /* P1: loop counter */
TMBOY 47:9e361da97763 333
TMBOY 47:9e361da97763 334 " LSETUP (pgs1, pgs2) LC1 = %4;\n\t"
TMBOY 47:9e361da97763 335 "pgs1: R2 = B [P0++] (X);\n\t" /* R2: g[0] */
TMBOY 47:9e361da97763 336 " R3 = B [P0++] (X);\n\t" /* R3: g[1] */
TMBOY 47:9e361da97763 337 " R4 = B [P0++] (X);\n\t" /* R4: g[2] */
TMBOY 47:9e361da97763 338 " R2 += 32;\n\t"
TMBOY 47:9e361da97763 339 " R3 += 32;\n\t"
TMBOY 47:9e361da97763 340 " R4 += 32;\n\t"
TMBOY 47:9e361da97763 341 " R4.H = 64;\n\t" /* R4.H: pitch_control */
TMBOY 47:9e361da97763 342
TMBOY 47:9e361da97763 343 " R0 = B [P0++] (X);\n\t"
TMBOY 47:9e361da97763 344 " B0 = R0;\n\t" /* BO: gain_sum */
TMBOY 47:9e361da97763 345
TMBOY 47:9e361da97763 346 /* compute_pitch_error() -------------------------------*/
TMBOY 47:9e361da97763 347
TMBOY 47:9e361da97763 348 " I1 = %3;\n\t" /* I1: ptr to C */
TMBOY 47:9e361da97763 349 " A0 = 0;\n\t"
TMBOY 47:9e361da97763 350
TMBOY 47:9e361da97763 351 " R0.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 352 " R1.L = R2.L*R4.H (IS);\n\t"
TMBOY 47:9e361da97763 353 " A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 354
TMBOY 47:9e361da97763 355 " R1.L = R3.L*R4.H (IS);\n\t"
TMBOY 47:9e361da97763 356 " A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 357
TMBOY 47:9e361da97763 358 " R1.L = R4.L*R4.H (IS);\n\t"
TMBOY 47:9e361da97763 359 " A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 360
TMBOY 47:9e361da97763 361 " R1.L = R2.L*R3.L (IS);\n\t"
TMBOY 47:9e361da97763 362 " A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 363
TMBOY 47:9e361da97763 364 " R1.L = R4.L*R3.L (IS);\n\t"
TMBOY 47:9e361da97763 365 " A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 366
TMBOY 47:9e361da97763 367 " R1.L = R4.L*R2.L (IS);\n\t"
TMBOY 47:9e361da97763 368 " A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 369
TMBOY 47:9e361da97763 370 " R1.L = R2.L*R2.L (IS);\n\t"
TMBOY 47:9e361da97763 371 " A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 372
TMBOY 47:9e361da97763 373 " R1.L = R3.L*R3.L (IS);\n\t"
TMBOY 47:9e361da97763 374 " A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 375
TMBOY 47:9e361da97763 376 " R1.L = R4.L*R4.L (IS);\n\t"
TMBOY 47:9e361da97763 377 " R0 = (A0 -= R1.L*R0.L) (IS);\n\t"
TMBOY 47:9e361da97763 378
TMBOY 47:9e361da97763 379 /*
TMBOY 47:9e361da97763 380 Re-arrange the if-then to code efficiently on the Blackfin:
TMBOY 47:9e361da97763 381
TMBOY 47:9e361da97763 382 if (sum>best_sum && gain_sum<=max_gain) ------ (1)
TMBOY 47:9e361da97763 383
TMBOY 47:9e361da97763 384 if (sum>best_sum && !(gain_sum>max_gain)) ------ (2)
TMBOY 47:9e361da97763 385
TMBOY 47:9e361da97763 386 if (max_gain<=gain_sum) { ------ (3)
TMBOY 47:9e361da97763 387 sum = -VERY_LARGE32;
TMBOY 47:9e361da97763 388 }
TMBOY 47:9e361da97763 389 if (best_sum<=sum)
TMBOY 47:9e361da97763 390
TMBOY 47:9e361da97763 391 The blackin cc instructions are all of the form:
TMBOY 47:9e361da97763 392
TMBOY 47:9e361da97763 393 cc = x < y (or cc = x <= y)
TMBOY 47:9e361da97763 394 */
TMBOY 47:9e361da97763 395 " R1 = B0\n\t"
TMBOY 47:9e361da97763 396 " R2 = %5\n\t"
TMBOY 47:9e361da97763 397 " R3 = %6\n\t"
TMBOY 47:9e361da97763 398 " cc = R2 <= R1;\n\t"
TMBOY 47:9e361da97763 399 " if cc R0 = R3;\n\t"
TMBOY 47:9e361da97763 400 " cc = %0 <= R0;\n\t"
TMBOY 47:9e361da97763 401 " if cc %0 = R0;\n\t"
TMBOY 47:9e361da97763 402 " if cc %1 = P1;\n\t"
TMBOY 47:9e361da97763 403
TMBOY 47:9e361da97763 404 "pgs2: P1 += 1;\n\t"
TMBOY 47:9e361da97763 405
TMBOY 47:9e361da97763 406 : "=&d" (best_sum), "=&d" (best_cdbk)
TMBOY 47:9e361da97763 407 : "a" (gain_cdbk), "a" (C16), "a" (gain_cdbk_size), "a" (max_gain),
TMBOY 47:9e361da97763 408 "b" (-VERY_LARGE32)
TMBOY 47:9e361da97763 409 : "R0", "R1", "R2", "R3", "R4", "P0",
TMBOY 47:9e361da97763 410 "P1", "I1", "L1", "A0", "B0"
TMBOY 47:9e361da97763 411 #if (__GNUC__ == 4)
TMBOY 47:9e361da97763 412 , "LC1"
TMBOY 47:9e361da97763 413 #endif
TMBOY 47:9e361da97763 414 );
TMBOY 47:9e361da97763 415
TMBOY 47:9e361da97763 416 return best_cdbk;
TMBOY 47:9e361da97763 417 }
TMBOY 47:9e361da97763 418 #endif
TMBOY 47:9e361da97763 419