Making sure there's no exported symbol with a speex_ prefix when compiling
[speexdsp.git] / tmv / cb_search_tm.h
1 /* Copyright (C) 2007 Hong Zhiqian */\r
2 /**\r
3    @file cb_search_tm.h\r
4    @author Hong Zhiqian\r
5    @brief Various compatibility routines for Speex (TriMedia version)\r
6 */\r
7 /*\r
8    Redistribution and use in source and binary forms, with or without\r
9    modification, are permitted provided that the following conditions\r
10    are met:\r
11    \r
12    - Redistributions of source code must retain the above copyright\r
13    notice, this list of conditions and the following disclaimer.\r
14    \r
15    - Redistributions in binary form must reproduce the above copyright\r
16    notice, this list of conditions and the following disclaimer in the\r
17    documentation and/or other materials provided with the distribution.\r
18    \r
19    - Neither the name of the Xiph.org Foundation nor the names of its\r
20    contributors may be used to endorse or promote products derived from\r
21    this software without specific prior written permission.\r
22    \r
23    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
24    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
25    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
26    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR\r
27    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
28    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
29    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
30    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
31    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
32    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
33    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
34 */\r
35 \r
36 #include <ops/custom_defs.h>\r
37 #include "profile_tm.h"\r
38 \r
39 #ifdef FIXED_POINT\r
40 \r
41 #define OVERRIDE_COMPUTE_WEIGHTED_CODEBOOK\r
42 static void compute_weighted_codebook(\r
43         const signed char * restrict shape_cb, \r
44         const Int16 * restrict r, \r
45         Int16 * restrict resp, \r
46         Int16 * restrict resp2, \r
47         Int32 * restrict E, \r
48         int shape_cb_size, int subvect_size, char *stack)\r
49 {\r
50         register int i, j;\r
51         register int quadsize;\r
52 \r
53         TMDEBUG_ALIGNMEM(r);\r
54         TMDEBUG_ALIGNMEM(resp);\r
55         TMDEBUG_ALIGNMEM(resp2);\r
56 \r
57         COMPUTEWEIGHTEDCODEBOOK_START();\r
58 \r
59         quadsize = subvect_size << 2;\r
60 \r
61         for ( i=0 ; i<shape_cb_size ; i+=4 )\r
62         {       register int e0, e1, e2, e3;\r
63                 \r
64                 e0 = e1 = e2 = e3 = 0;\r
65                 for( j=0 ; j<subvect_size ; ++j )\r
66                 {\r
67                         register int k, rr;\r
68                         register int resj0, resj1, resj2, resj3;\r
69                         \r
70                         resj0 = resj1 = resj2 = resj3 = 0;\r
71 \r
72                         for ( k=0 ; k<=j ; ++k )\r
73                         {       rr = r[j-k];\r
74                                 \r
75                                 resj0 += shape_cb[k] * rr;\r
76                                 resj1 += shape_cb[k+subvect_size] * rr;\r
77                                 resj2 += shape_cb[k+2*subvect_size] * rr;\r
78                                 resj3 += shape_cb[k+3*subvect_size] * rr;\r
79                         }\r
80 \r
81                         resj0 >>= 13;\r
82                         resj1 >>= 13;\r
83                         resj2 >>= 13;\r
84                         resj3 >>= 13;\r
85 \r
86                         e0 += resj0 * resj0;\r
87                         e1 += resj1 * resj1;\r
88                         e2 += resj2 * resj2;\r
89                         e3 += resj3 * resj3;\r
90                         \r
91                         resp[j]                                 = resj0;\r
92                         resp[j+subvect_size]    = resj1;\r
93                         resp[j+2*subvect_size]  = resj2;\r
94                         resp[j+3*subvect_size]  = resj3;\r
95                 }\r
96 \r
97                 E[i]            = e0;\r
98                 E[i+1]          = e1;\r
99                 E[i+2]          = e2;\r
100                 E[i+3]          = e3;\r
101 \r
102                 resp            += quadsize;\r
103                 shape_cb        += quadsize;\r
104         }\r
105         \r
106 #ifndef REMARK_ON\r
107         (void)resp2;\r
108         (void)stack;\r
109 #endif\r
110 \r
111         COMPUTEWEIGHTEDCODEBOOK_STOP();\r
112 }\r
113 \r
114 #define OVERRIDE_TARGET_UPDATE\r
115 static inline void target_update(Int16 * restrict t, Int16 g, Int16 * restrict r, int len)\r
116 {\r
117         register int n;\r
118         register int gr1, gr2, t1, t2, r1, r2;\r
119         register int quadsize;\r
120 \r
121         TARGETUPDATE_START();\r
122 \r
123         quadsize = len & 0xFFFFFFFC;\r
124         \r
125         for ( n=0; n<quadsize ; n+=4 )\r
126         {       gr1 = pack16lsb(PSHR32((g * r[n]),13)  , PSHR32((g * r[n+1]),13));\r
127                 gr2 = pack16lsb(PSHR32((g * r[n+2]),13), PSHR32((g * r[n+3]),13));\r
128                 \r
129                 t1      = pack16lsb(t[n],  t[n+1]);\r
130                 t2      = pack16lsb(t[n+2],t[n+3]);\r
131 \r
132                 r1      = dspidualsub(t1, gr1);\r
133                 r2      = dspidualsub(t2, gr2);\r
134 \r
135                 t[n]    = asri(16,r1);\r
136                 t[n+1]  = sex16(r1);\r
137                 t[n+2]  = asri(16,r2);\r
138                 t[n+3]  = sex16(r2);\r
139         }\r
140 \r
141         for ( n=quadsize ; n<len ; ++n )\r
142         {       t[n] = SUB16(t[n],PSHR32(MULT16_16(g,r[n]),13));\r
143         }\r
144 \r
145         TARGETUPDATE_STOP();\r
146 }\r
147 \r
148 #endif\r
149 \r