blob: 429ff4c3ee6830edc944e0b23e54858ae82eecb1 [file] [log] [blame]
Jean-Marc Valin35a1f882008-03-26 10:34:23 +11001/* (C) 2007-2008 Jean-Marc Valin, CSIRO
Jean-Marc Valin41af4212007-11-30 18:35:37 +11002*/
3/*
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15 - Neither the name of the Xiph.org Foundation nor the names of its
16 contributors may be used to endorse or promote products derived from
17 this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
Jean-Marc Valin02fa9132008-02-20 12:09:29 +110032#ifdef HAVE_CONFIG_H
33#include "config.h"
34#endif
35
Jean-Marc Valin3ca9b1d2008-02-27 23:50:31 +110036#include "mathops.h"
Jean-Marc Valin29ccab82007-12-06 15:39:38 +110037#include "cwrs.h"
Jean-Marc Valin9cace642007-12-06 17:44:09 +110038#include "vq.h"
Jean-Marc Valin9a0bba12008-02-20 14:08:50 +110039#include "arch.h"
Jean-Marc Valinb60340f2008-02-26 15:41:51 +110040#include "os_support.h"
Jean-Marc Valin164a2292009-07-22 07:48:35 -040041#include "rate.h"
Jean-Marc Valin41af4212007-11-30 18:35:37 +110042
Jean-Marc Valind5e54362009-09-30 20:50:41 -040043#ifndef M_PI
44#define M_PI 3.141592653
45#endif
46
Jean-Marc Valina7750b92009-08-29 22:52:03 +010047static void exp_rotation(celt_norm_t *X, int len, int dir, int stride, int K)
48{
49 int i, k, iter;
50 celt_word16_t c, s;
51 celt_word16_t gain, theta;
52 celt_norm_t *Xptr;
Jean-Marc Valin75732de2009-09-29 22:35:32 -040053 gain = celt_div((celt_word32_t)MULT16_16(Q15_ONE,len),(celt_word32_t)(3+len+6*K));
Jean-Marc Valina7750b92009-08-29 22:52:03 +010054 /* FIXME: Make that HALF16 instead of HALF32 */
55 theta = SUB16(Q15ONE, HALF32(MULT16_16_Q15(gain,gain)));
56 /*if (len==30)
57 {
58 for (i=0;i<len;i++)
59 X[i] = 0;
60 X[14] = 1;
61}*/
62 c = celt_cos_norm(EXTEND32(theta));
63 s = dir*celt_cos_norm(EXTEND32(SUB16(Q15ONE,theta))); /* sin(theta) */
Jean-Marc Valin75732de2009-09-29 22:35:32 -040064 if (len > 8*stride)
65 stride *= len/(8*stride);
Jean-Marc Valina7750b92009-08-29 22:52:03 +010066 iter = 1;
67 for (k=0;k<iter;k++)
68 {
69 /* We could use MULT16_16_P15 instead of MULT16_16_Q15 for more accuracy,
70 but at this point, I really don't think it's necessary */
71 Xptr = X;
72 for (i=0;i<len-stride;i++)
73 {
74 celt_norm_t x1, x2;
75 x1 = Xptr[0];
76 x2 = Xptr[stride];
77 Xptr[stride] = MULT16_16_Q15(c,x2) + MULT16_16_Q15(s,x1);
78 *Xptr++ = MULT16_16_Q15(c,x1) - MULT16_16_Q15(s,x2);
79 }
80 Xptr = &X[len-2*stride-1];
81 for (i=len-2*stride-1;i>=0;i--)
82 {
83 celt_norm_t x1, x2;
84 x1 = Xptr[0];
85 x2 = Xptr[stride];
86 Xptr[stride] = MULT16_16_Q15(c,x2) + MULT16_16_Q15(s,x1);
87 *Xptr-- = MULT16_16_Q15(c,x1) - MULT16_16_Q15(s,x2);
88 }
89 }
90 /*if (len==30)
91 {
92 for (i=0;i<len;i++)
93 printf ("%f ", X[i]);
94 printf ("\n");
95 exit(0);
96}*/
97}
98
99
Jean-Marc Valin35a1f882008-03-26 10:34:23 +1100100/** Takes the pitch vector and the decoded residual vector, computes the gain
101 that will give ||p+g*y||=1 and mixes the residual with the pitch. */
Jean-Marc Valinf7a1e162009-10-07 06:56:03 -0400102static void normalise_residual(int * restrict iy, celt_norm_t * restrict X, int N, int K, celt_word32_t Ryy)
Jean-Marc Valind4018c32008-02-27 10:09:48 +1100103{
104 int i;
Jean-Marc Valina847b772008-02-27 17:46:49 +1100105 celt_word32_t g;
Jean-Marc Valinf6dc1eb2009-10-06 20:08:49 -0400106
107 g = celt_rsqrt(Ryy);
Jean-Marc Valind4018c32008-02-27 10:09:48 +1100108
Jean-Marc Valin6ea8bae2008-04-15 08:01:33 +1000109 i=0;
Jean-Marc Valinf6dc1eb2009-10-06 20:08:49 -0400110 do
Jean-Marc Valinf7a1e162009-10-07 06:56:03 -0400111 X[i] = SHR16(MULT16_16_16(g, iy[i]),1);
Jean-Marc Valin6ea8bae2008-04-15 08:01:33 +1000112 while (++i < N);
Jean-Marc Valind4018c32008-02-27 10:09:48 +1100113}
114
Jean-Marc Valin095c1782009-09-17 22:38:34 -0400115void alg_quant(celt_norm_t *X, int N, int K, int spread, ec_enc *enc)
Jean-Marc Valin41af4212007-11-30 18:35:37 +1100116{
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100117 VARDECL(celt_norm_t, y);
118 VARDECL(int, iy);
Jean-Marc Valin1dab60c2008-09-16 13:29:37 -0400119 VARDECL(celt_word16_t, signx);
Jean-Marc Valin6ea8bae2008-04-15 08:01:33 +1000120 int j, is;
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100121 celt_word16_t s;
Jean-Marc Valin846d4e22008-02-12 13:48:48 +1100122 int pulsesLeft;
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100123 celt_word32_t sum;
Jean-Marc Valin095c1782009-09-17 22:38:34 -0400124 celt_word32_t xy, yy;
Jean-Marc Valinf9584772008-03-27 12:22:44 +1100125 int N_1; /* Inverse of N, in Q14 format (even for float) */
Jean-Marc Valinf675adc2008-02-28 12:15:17 +1100126#ifdef FIXED_POINT
Jean-Marc Valind748cd52008-03-01 07:27:03 +1100127 int yshift;
128#endif
129 SAVE_STACK;
130
Jean-Marc Valin164a2292009-07-22 07:48:35 -0400131 K = get_pulses(K);
Jean-Marc Valind748cd52008-03-01 07:27:03 +1100132#ifdef FIXED_POINT
Jean-Marc Valin98c86c72008-03-27 08:40:45 +1100133 yshift = 13-celt_ilog2(K);
Jean-Marc Valinf675adc2008-02-28 12:15:17 +1100134#endif
Jean-Marc Valin9d8d9b32008-02-27 16:17:39 +1100135
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100136 ALLOC(y, N, celt_norm_t);
137 ALLOC(iy, N, int);
Jean-Marc Valin1dab60c2008-09-16 13:29:37 -0400138 ALLOC(signx, N, celt_word16_t);
Jean-Marc Valin124d1cd2008-03-28 00:33:04 +1100139 N_1 = 512/N;
Jean-Marc Valina7750b92009-08-29 22:52:03 +0100140
141 if (spread)
142 exp_rotation(X, N, 1, spread, K);
Jean-Marc Valin3d152a52008-04-15 07:46:48 +1000143
144 sum = 0;
Jean-Marc Valindff9b7e2008-04-21 11:43:51 +1000145 j=0; do {
Jean-Marc Valin49134382008-03-25 16:07:05 +1100146 if (X[j]>0)
147 signx[j]=1;
Jean-Marc Valin6cde5dd2008-12-04 21:21:41 -0500148 else {
Jean-Marc Valin49134382008-03-25 16:07:05 +1100149 signx[j]=-1;
Jean-Marc Valin6cde5dd2008-12-04 21:21:41 -0500150 X[j]=-X[j];
Jean-Marc Valin6cde5dd2008-12-04 21:21:41 -0500151 }
Jean-Marc Valin3d152a52008-04-15 07:46:48 +1000152 iy[j] = 0;
153 y[j] = 0;
Jean-Marc Valindff9b7e2008-04-21 11:43:51 +1000154 } while (++j<N);
Jean-Marc Valinbd718ba2008-03-25 14:15:41 +1100155
Jean-Marc Valin095c1782009-09-17 22:38:34 -0400156 xy = yy = 0;
Jean-Marc Valin0d587d82008-02-14 21:29:50 +1100157
Jean-Marc Valin846d4e22008-02-12 13:48:48 +1100158 pulsesLeft = K;
Jean-Marc Valin8256ed42008-12-12 20:50:56 -0500159
160 /* Do a pre-search by projecting on the pyramid */
Jean-Marc Valina733f082008-12-04 22:52:26 -0500161 if (K > (N>>1))
162 {
Jean-Marc Valin8256ed42008-12-12 20:50:56 -0500163 celt_word16_t rcp;
Gregory Maxwell61832f12008-12-22 18:15:42 -0500164 sum=0;
Jean-Marc Valina733f082008-12-04 22:52:26 -0500165 j=0; do {
166 sum += X[j];
167 } while (++j<N);
Jean-Marc Valin6d454d82009-06-30 10:31:00 -0400168
169#ifdef FIXED_POINT
170 if (sum <= K)
171#else
172 if (sum <= EPSILON)
173#endif
Jean-Marc Valin8256ed42008-12-12 20:50:56 -0500174 {
Jean-Marc Valinda1156a2009-07-01 01:27:48 -0400175 X[0] = QCONST16(1.f,14);
Jean-Marc Valin6d454d82009-06-30 10:31:00 -0400176 j=1; do
177 X[j]=0;
178 while (++j<N);
Jean-Marc Valinda1156a2009-07-01 01:27:48 -0400179 sum = QCONST16(1.f,14);
Jean-Marc Valin8256ed42008-12-12 20:50:56 -0500180 }
181 /* Do we have sufficient accuracy here? */
182 rcp = EXTRACT16(MULT16_32_Q16(K-1, celt_rcp(sum)));
Jean-Marc Valina733f082008-12-04 22:52:26 -0500183 j=0; do {
Jean-Marc Valin09dc5a12008-12-05 00:28:28 -0500184#ifdef FIXED_POINT
Jean-Marc Valin137241d2008-12-06 23:44:55 -0500185 /* It's really important to round *towards zero* here */
Jean-Marc Valin8256ed42008-12-12 20:50:56 -0500186 iy[j] = MULT16_16_Q15(X[j],rcp);
Jean-Marc Valin09dc5a12008-12-05 00:28:28 -0500187#else
Jean-Marc Valin8256ed42008-12-12 20:50:56 -0500188 iy[j] = floor(rcp*X[j]);
Jean-Marc Valin09dc5a12008-12-05 00:28:28 -0500189#endif
Jean-Marc Valinc7635b42008-12-04 23:26:32 -0500190 y[j] = SHL16(iy[j],yshift);
191 yy = MAC16_16(yy, y[j],y[j]);
192 xy = MAC16_16(xy, X[j],y[j]);
Jean-Marc Valin09dc5a12008-12-05 00:28:28 -0500193 y[j] *= 2;
Jean-Marc Valina733f082008-12-04 22:52:26 -0500194 pulsesLeft -= iy[j];
195 } while (++j<N);
196 }
Jean-Marc Valin137241d2008-12-06 23:44:55 -0500197 celt_assert2(pulsesLeft>=1, "Allocated too many pulses in the quick pass");
Jean-Marc Valin8256ed42008-12-12 20:50:56 -0500198
Jean-Marc Valin095c1782009-09-17 22:38:34 -0400199 while (pulsesLeft > 0)
Jean-Marc Valin41af4212007-11-30 18:35:37 +1100200 {
Jean-Marc Valin846d4e22008-02-12 13:48:48 +1100201 int pulsesAtOnce=1;
Jean-Marc Valin35a1f882008-03-26 10:34:23 +1100202 int best_id;
Jean-Marc Valined317c92008-04-15 17:31:23 +1000203 celt_word16_t magnitude;
Jean-Marc Valin7bb339d2008-09-21 21:11:39 -0400204 celt_word32_t best_num = -VERY_LARGE16;
205 celt_word16_t best_den = 0;
Jean-Marc Valin0bc5f7f2008-04-20 17:16:18 +1000206#ifdef FIXED_POINT
207 int rshift;
208#endif
Jean-Marc Valinbd718ba2008-03-25 14:15:41 +1100209 /* Decide on how many pulses to find at once */
Jean-Marc Valin124d1cd2008-03-28 00:33:04 +1100210 pulsesAtOnce = (pulsesLeft*N_1)>>9; /* pulsesLeft/N */
Jean-Marc Valincab576e2008-02-12 17:21:14 +1100211 if (pulsesAtOnce<1)
212 pulsesAtOnce = 1;
Jean-Marc Valin0bc5f7f2008-04-20 17:16:18 +1000213#ifdef FIXED_POINT
214 rshift = yshift+1+celt_ilog2(K-pulsesLeft+pulsesAtOnce);
215#endif
Jean-Marc Valined317c92008-04-15 17:31:23 +1000216 magnitude = SHL16(pulsesAtOnce, yshift);
Jean-Marc Valin846d4e22008-02-12 13:48:48 +1100217
Jean-Marc Valin35a1f882008-03-26 10:34:23 +1100218 best_id = 0;
Jean-Marc Valined317c92008-04-15 17:31:23 +1000219 /* The squared magnitude term gets added anyway, so we might as well
220 add it outside the loop */
Jean-Marc Valin1dab60c2008-09-16 13:29:37 -0400221 yy = MAC16_16(yy, magnitude,magnitude);
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100222 /* Choose between fast and accurate strategy depending on where we are in the search */
Jean-Marc Valined317c92008-04-15 17:31:23 +1000223 /* This should ensure that anything we can process will have a better score */
Jean-Marc Valin7bb339d2008-09-21 21:11:39 -0400224 j=0;
225 do {
226 celt_word16_t Rxy, Ryy;
227 /* Select sign based on X[j] alone */
Jean-Marc Valin6cde5dd2008-12-04 21:21:41 -0500228 s = magnitude;
Jean-Marc Valin7bb339d2008-09-21 21:11:39 -0400229 /* Temporary sums of the new pulse(s) */
230 Rxy = EXTRACT16(SHR32(MAC16_16(xy, s,X[j]),rshift));
231 /* We're multiplying y[j] by two so we don't have to do it here */
232 Ryy = EXTRACT16(SHR32(MAC16_16(yy, s,y[j]),rshift));
Jean-Marc Valin35a1f882008-03-26 10:34:23 +1100233
Jean-Marc Valined317c92008-04-15 17:31:23 +1000234 /* Approximate score: we maximise Rxy/sqrt(Ryy) (we're guaranteed that
Jean-Marc Valin7bb339d2008-09-21 21:11:39 -0400235 Rxy is positive because the sign is pre-computed) */
236 Rxy = MULT16_16_Q15(Rxy,Rxy);
Jean-Marc Valin35a1f882008-03-26 10:34:23 +1100237 /* The idea is to check for num/den >= best_num/best_den, but that way
Jean-Marc Valin7bb339d2008-09-21 21:11:39 -0400238 we can do it without any division */
239 /* OPT: Make sure to use conditional moves here */
240 if (MULT16_16(best_den, Rxy) > MULT16_16(Ryy, best_num))
241 {
242 best_den = Ryy;
243 best_num = Rxy;
244 best_id = j;
245 }
246 } while (++j<N);
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100247
Jean-Marc Valin35a1f882008-03-26 10:34:23 +1100248 j = best_id;
Jean-Marc Valin6cde5dd2008-12-04 21:21:41 -0500249 is = pulsesAtOnce;
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100250 s = SHL16(is, yshift);
Jean-Marc Valinbd718ba2008-03-25 14:15:41 +1100251
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100252 /* Updating the sums of the new pulse(s) */
253 xy = xy + MULT16_16(s,X[j]);
Jean-Marc Valined317c92008-04-15 17:31:23 +1000254 /* We're multiplying y[j] by two so we don't have to do it here */
255 yy = yy + MULT16_16(s,y[j]);
Jean-Marc Valinbd718ba2008-03-25 14:15:41 +1100256
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100257 /* Only now that we've made the final choice, update y/iy */
Jean-Marc Valined317c92008-04-15 17:31:23 +1000258 /* Multiplying y[j] by 2 so we don't have to do it everywhere else */
259 y[j] += 2*s;
Jean-Marc Valin44c63352008-03-25 21:28:40 +1100260 iy[j] += is;
Jean-Marc Valin846d4e22008-02-12 13:48:48 +1100261 pulsesLeft -= pulsesAtOnce;
Jean-Marc Valin41af4212007-11-30 18:35:37 +1100262 }
Jean-Marc Valin6cde5dd2008-12-04 21:21:41 -0500263 j=0;
264 do {
Jean-Marc Valin6cde5dd2008-12-04 21:21:41 -0500265 X[j] = MULT16_16(signx[j],X[j]);
266 if (signx[j] < 0)
267 iy[j] = -iy[j];
268 } while (++j<N);
Jean-Marc Valinbd718ba2008-03-25 14:15:41 +1100269 encode_pulses(iy, N, K, enc);
Jean-Marc Valin5fa59952008-02-14 13:50:44 +1100270
Jean-Marc Valina4833ff2008-01-10 15:34:00 +1100271 /* Recompute the gain in one pass to reduce the encoder-decoder mismatch
Jean-Marc Valinbd718ba2008-03-25 14:15:41 +1100272 due to the recursive computation used in quantisation. */
Jean-Marc Valinf7a1e162009-10-07 06:56:03 -0400273 normalise_residual(iy, X, N, K, EXTRACT16(SHR32(yy,2*yshift)));
Jean-Marc Valina7750b92009-08-29 22:52:03 +0100274 if (spread)
275 exp_rotation(X, N, -1, spread, K);
Jean-Marc Valin8600f692008-02-29 15:14:12 +1100276 RESTORE_STACK;
Jean-Marc Valin41af4212007-11-30 18:35:37 +1100277}
278
Jean-Marc Valinbd718ba2008-03-25 14:15:41 +1100279
Jean-Marc Valin879fbfd2008-02-20 17:17:13 +1100280/** Decode pulse vector and combine the result with the pitch vector to produce
281 the final normalised signal in the current band. */
Jean-Marc Valin095c1782009-09-17 22:38:34 -0400282void alg_unquant(celt_norm_t *X, int N, int K, int spread, ec_dec *dec)
Jean-Marc Valin0d227d82007-12-31 16:12:12 +1100283{
Jean-Marc Valinf6dc1eb2009-10-06 20:08:49 -0400284 int i;
285 celt_word32_t Ryy;
Jean-Marc Valin31b79d12008-03-12 17:17:23 +1100286 VARDECL(int, iy);
Jean-Marc Valin8600f692008-02-29 15:14:12 +1100287 SAVE_STACK;
Jean-Marc Valin164a2292009-07-22 07:48:35 -0400288 K = get_pulses(K);
Jean-Marc Valin9a0bba12008-02-20 14:08:50 +1100289 ALLOC(iy, N, int);
Jean-Marc Valin5fa59952008-02-14 13:50:44 +1100290 decode_pulses(iy, N, K, dec);
Jean-Marc Valinf6dc1eb2009-10-06 20:08:49 -0400291 Ryy = 0;
292 i=0;
293 do {
294 Ryy = MAC16_16(Ryy, iy[i], iy[i]);
295 } while (++i < N);
Jean-Marc Valinf7a1e162009-10-07 06:56:03 -0400296 normalise_residual(iy, X, N, K, Ryy);
Jean-Marc Valina7750b92009-08-29 22:52:03 +0100297 if (spread)
298 exp_rotation(X, N, -1, spread, K);
Jean-Marc Valin8600f692008-02-29 15:14:12 +1100299 RESTORE_STACK;
Jean-Marc Valin0d227d82007-12-31 16:12:12 +1100300}
301
Jean-Marc Valinca53b7c2009-03-26 20:23:14 -0400302celt_word16_t renormalise_vector(celt_norm_t *X, celt_word16_t value, int N, int stride)
Jean-Marc Valin6361ad82008-07-20 23:14:31 -0400303{
304 int i;
305 celt_word32_t E = EPSILON;
Jean-Marc Valinca53b7c2009-03-26 20:23:14 -0400306 celt_word16_t rE;
Jean-Marc Valin6361ad82008-07-20 23:14:31 -0400307 celt_word16_t g;
308 celt_norm_t *xptr = X;
309 for (i=0;i<N;i++)
310 {
311 E = MAC16_16(E, *xptr, *xptr);
312 xptr += stride;
313 }
314
Jean-Marc Valinca53b7c2009-03-26 20:23:14 -0400315 rE = celt_sqrt(E);
Jean-Marc Valincd29b022009-07-01 09:59:21 -0400316#ifdef FIXED_POINT
317 if (rE <= 128)
318 g = Q15ONE;
319 else
320#endif
321 g = MULT16_16_Q15(value,celt_rcp(SHL32(rE,9)));
Jean-Marc Valin6361ad82008-07-20 23:14:31 -0400322 xptr = X;
323 for (i=0;i<N;i++)
324 {
325 *xptr = PSHR32(MULT16_16(g, *xptr),8);
326 xptr += stride;
327 }
Jean-Marc Valinca53b7c2009-03-26 20:23:14 -0400328 return rE;
Jean-Marc Valin6361ad82008-07-20 23:14:31 -0400329}
330
Jean-Marc Valind5e54362009-09-30 20:50:41 -0400331static void fold(const CELTMode *m, int N, const celt_norm_t * restrict Y, celt_norm_t * restrict P, int N0, int B)
Jean-Marc Valin4841a0a2007-12-03 13:54:30 +1100332{
Jean-Marc Valindf38f2b2008-07-20 20:36:54 -0400333 int j;
Jean-Marc Valind5e54362009-09-30 20:50:41 -0400334 int id = N0 % B;
Jean-Marc Valindf38f2b2008-07-20 20:36:54 -0400335 /* Here, we assume that id will never be greater than N0, i.e. that
Jean-Marc Valin5eef2642008-08-06 23:06:31 -0400336 no band is wider than N0. In the unlikely case it happens, we set
337 everything to zero */
Jean-Marc Valin4e5b7bc2009-07-03 15:09:07 -0400338 /*{
339 int offset = (N0*C - (id+C*N))/2;
340 if (offset > C*N0/16)
341 offset = C*N0/16;
342 offset -= offset % (C*B);
343 if (offset < 0)
344 offset = 0;
345 //printf ("%d\n", offset);
346 id += offset;
347 }*/
Jean-Marc Valind5e54362009-09-30 20:50:41 -0400348 if (id+N>N0)
349 for (j=0;j<N;j++)
Jean-Marc Valin5eef2642008-08-06 23:06:31 -0400350 P[j] = 0;
351 else
Jean-Marc Valind5e54362009-09-30 20:50:41 -0400352 for (j=0;j<N;j++)
Jean-Marc Valin5eef2642008-08-06 23:06:31 -0400353 P[j] = Y[id++];
Jean-Marc Valin2c733062008-07-17 16:22:23 -0400354}
355
Jean-Marc Valind5e54362009-09-30 20:50:41 -0400356void intra_fold(const CELTMode *m, int N, const celt_norm_t * restrict Y, celt_norm_t * restrict P, int N0, int B)
Jean-Marc Valin2c733062008-07-17 16:22:23 -0400357{
Jean-Marc Valin6361ad82008-07-20 23:14:31 -0400358 fold(m, N, Y, P, N0, B);
Jean-Marc Valind5e54362009-09-30 20:50:41 -0400359 renormalise_vector(P, Q15ONE, N, 1);
Jean-Marc Valin0e20ca02008-02-11 15:33:53 +1100360}
361