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 lpc_bfin.h
TMBOY 47:9e361da97763 4 @author Jean-Marc Valin
TMBOY 47:9e361da97763 5 @brief Functions for LPC (Linear Prediction Coefficients) analysis (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_SPEEX_AUTOCORR
TMBOY 47:9e361da97763 37 void _spx_autocorr(
TMBOY 47:9e361da97763 38 const spx_word16_t *x, /* in: [0...n-1] samples x */
TMBOY 47:9e361da97763 39 spx_word16_t *ac, /* out: [0...lag-1] ac values */
TMBOY 47:9e361da97763 40 int lag,
TMBOY 47:9e361da97763 41 int n
TMBOY 47:9e361da97763 42 )
TMBOY 47:9e361da97763 43 {
TMBOY 47:9e361da97763 44 spx_word32_t d;
TMBOY 47:9e361da97763 45 const spx_word16_t *xs;
TMBOY 47:9e361da97763 46 int i, j;
TMBOY 47:9e361da97763 47 spx_word32_t ac0=1;
TMBOY 47:9e361da97763 48 spx_word32_t ac32[11], *ac32top;
TMBOY 47:9e361da97763 49 int shift, ac_shift;
TMBOY 47:9e361da97763 50 ac32top = ac32+lag-1;
TMBOY 47:9e361da97763 51 int lag_1, N_lag;
TMBOY 47:9e361da97763 52 int nshift;
TMBOY 47:9e361da97763 53 lag_1 = lag-1;
TMBOY 47:9e361da97763 54 N_lag = n-lag_1;
TMBOY 47:9e361da97763 55 for (j=0;j<n;j++)
TMBOY 47:9e361da97763 56 ac0 = ADD32(ac0,SHR32(MULT16_16(x[j],x[j]),8));
TMBOY 47:9e361da97763 57 ac0 = ADD32(ac0,n);
TMBOY 47:9e361da97763 58 shift = 8;
TMBOY 47:9e361da97763 59 while (shift && ac0<0x40000000)
TMBOY 47:9e361da97763 60 {
TMBOY 47:9e361da97763 61 shift--;
TMBOY 47:9e361da97763 62 ac0 <<= 1;
TMBOY 47:9e361da97763 63 }
TMBOY 47:9e361da97763 64 ac_shift = 18;
TMBOY 47:9e361da97763 65 while (ac_shift && ac0<0x40000000)
TMBOY 47:9e361da97763 66 {
TMBOY 47:9e361da97763 67 ac_shift--;
TMBOY 47:9e361da97763 68 ac0 <<= 1;
TMBOY 47:9e361da97763 69 }
TMBOY 47:9e361da97763 70
TMBOY 47:9e361da97763 71 xs = x+lag-1;
TMBOY 47:9e361da97763 72 nshift = -shift;
TMBOY 47:9e361da97763 73 __asm__ __volatile__
TMBOY 47:9e361da97763 74 (
TMBOY 47:9e361da97763 75 "P2 = %0;\n\t"
TMBOY 47:9e361da97763 76 "I0 = P2;\n\t" /* x in I0 */
TMBOY 47:9e361da97763 77 "B0 = P2;\n\t" /* x in B0 */
TMBOY 47:9e361da97763 78 "R0 = %3;\n\t" /* len in R0 */
TMBOY 47:9e361da97763 79 "P3 = %3;\n\t" /* len in R0 */
TMBOY 47:9e361da97763 80 "P4 = %4;\n\t" /* nb_pitch in R0 */
TMBOY 47:9e361da97763 81 "R1 = R0 << 1;\n\t" /* number of bytes in x */
TMBOY 47:9e361da97763 82 "L0 = R1;\n\t"
TMBOY 47:9e361da97763 83 "P0 = %1;\n\t"
TMBOY 47:9e361da97763 84 "P1 = %2;\n\t"
TMBOY 47:9e361da97763 85 "B1 = P1;\n\t"
TMBOY 47:9e361da97763 86 "R4 = %5;\n\t"
TMBOY 47:9e361da97763 87 "L1 = 0;\n\t" /*Disable looping on I1*/
TMBOY 47:9e361da97763 88
TMBOY 47:9e361da97763 89 "r0 = [I0++];\n\t"
TMBOY 47:9e361da97763 90 "R2 = 0;R3=0;"
TMBOY 47:9e361da97763 91 "LOOP pitch%= LC0 = P4 >> 1;\n\t"
TMBOY 47:9e361da97763 92 "LOOP_BEGIN pitch%=;\n\t"
TMBOY 47:9e361da97763 93 "I1 = P0;\n\t"
TMBOY 47:9e361da97763 94 "A1 = A0 = 0;\n\t"
TMBOY 47:9e361da97763 95 "R1 = [I1++];\n\t"
TMBOY 47:9e361da97763 96 "LOOP inner_prod%= LC1 = P3 >> 1;\n\t"
TMBOY 47:9e361da97763 97 "LOOP_BEGIN inner_prod%=;\n\t"
TMBOY 47:9e361da97763 98 "A1 += R0.L*R1.H, A0 += R0.L*R1.L (IS) || R1.L = W[I1++];\n\t"
TMBOY 47:9e361da97763 99 "A1 += R0.H*R1.L, A0 += R0.H*R1.H (IS) || R1.H = W[I1++] || R0 = [I0++];\n\t"
TMBOY 47:9e361da97763 100 "LOOP_END inner_prod%=;\n\t"
TMBOY 47:9e361da97763 101 "A0 = ASHIFT A0 by R4.L;\n\t"
TMBOY 47:9e361da97763 102 "A1 = ASHIFT A1 by R4.L;\n\t"
TMBOY 47:9e361da97763 103
TMBOY 47:9e361da97763 104 "R2 = A0, R3 = A1;\n\t"
TMBOY 47:9e361da97763 105 "[P1--] = R2;\n\t"
TMBOY 47:9e361da97763 106 "[P1--] = R3;\n\t"
TMBOY 47:9e361da97763 107 "P0 += 4;\n\t"
TMBOY 47:9e361da97763 108 "LOOP_END pitch%=;\n\t"
TMBOY 47:9e361da97763 109 : : "m" (xs), "m" (x), "m" (ac32top), "m" (N_lag), "m" (lag_1), "m" (nshift)
TMBOY 47:9e361da97763 110 : "A0", "A1", "P0", "P1", "P2", "P3", "P4", "R0", "R1", "R2", "R3", "R4", "I0", "I1", "L0", "L1", "B0", "B1", "memory"
TMBOY 47:9e361da97763 111 );
TMBOY 47:9e361da97763 112 d=0;
TMBOY 47:9e361da97763 113 for (j=0;j<n;j++)
TMBOY 47:9e361da97763 114 {
TMBOY 47:9e361da97763 115 d = ADD32(d,SHR32(MULT16_16(x[j],x[j]), shift));
TMBOY 47:9e361da97763 116 }
TMBOY 47:9e361da97763 117 ac32[0] = d;
TMBOY 47:9e361da97763 118
TMBOY 47:9e361da97763 119 for (i=0;i<lag;i++)
TMBOY 47:9e361da97763 120 {
TMBOY 47:9e361da97763 121 d=0;
TMBOY 47:9e361da97763 122 for (j=i;j<lag_1;j++)
TMBOY 47:9e361da97763 123 {
TMBOY 47:9e361da97763 124 d = ADD32(d,SHR32(MULT16_16(x[j],x[j-i]), shift));
TMBOY 47:9e361da97763 125 }
TMBOY 47:9e361da97763 126 if (i)
TMBOY 47:9e361da97763 127 ac32[i] += d;
TMBOY 47:9e361da97763 128 ac[i] = SHR32(ac32[i], ac_shift);
TMBOY 47:9e361da97763 129 }
TMBOY 47:9e361da97763 130 }
TMBOY 47:9e361da97763 131