1 /* Copyright (C) 2002 Jean-Marc Valin
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 - Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 - Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 - Neither the name of the Xiph.org Foundation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include "stack_alloc.h"
42 #include <xmmintrin.h>
44 #elif defined(SHORTCUTS) && (defined(ARM4_ASM) || defined(ARM5E_ASM))
46 #elif defined(BFIN_ASM)
51 int scal_quant(spx_word16_t in, const spx_word16_t *boundary, int entries)
54 while (i<entries-1 && in>boundary[0])
62 int scal_quant32(spx_word32_t in, const spx_word32_t *boundary, int entries)
65 while (i<entries-1 && in>boundary[0])
74 #ifndef OVERRIDE_VQ_NBEST
75 /*Finds the indices of the n-best entries in a codebook*/
76 void vq_nbest(spx_word16_t *in, const spx_word16_t *codebook, int len, int entries, spx_word32_t *E, int N, int *nbest, spx_word32_t *best_dist, char *stack)
80 for (i=0;i<entries;i++)
84 dist = MAC16_16(dist,in[j],*codebook++);
86 dist=SUB32(SHR32(E[i],1),dist);
90 if (i<N || dist<best_dist[N-1])
92 for (k=N-1; (k >= 1) && (k > used || dist < best_dist[k-1]); k--)
94 best_dist[k]=best_dist[k-1];
95 nbest[k] = nbest[k-1];
108 #ifndef OVERRIDE_VQ_NBEST_SIGN
109 /*Finds the indices of the n-best entries in a codebook with sign*/
110 void vq_nbest_sign(spx_word16_t *in, const spx_word16_t *codebook, int len, int entries, spx_word32_t *E, int N, int *nbest, spx_word32_t *best_dist, char *stack)
112 int i,j,k, sign, used;
114 for (i=0;i<entries;i++)
118 dist = MAC16_16(dist,in[j],*codebook++);
128 dist = ADD32(dist,SHR32(E[i],1));
130 dist = ADD32(dist,.5f*E[i]);
132 if (i<N || dist<best_dist[N-1])
134 for (k=N-1; (k >= 1) && (k > used || dist < best_dist[k-1]); k--)
136 best_dist[k]=best_dist[k-1];
137 nbest[k] = nbest[k-1];