fixed an SBR bug/cheat using a bunch of ugly hacks
[ghost.git] / libghost / lifting.c
blob4896503ee44075f0f98ca8746f2cec0472f8e1f8
1 /**
2 @file lifting.c
3 @brief Lifting wavelet transform
4 */
6 /* Copyright (C) 2005
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "lifting.h"
26 void lifting_forward(float *x, struct LiftingBasis *basis, int len, int stride)
28 int i,j;
29 float *r, *rstart; /* residue/modified value */
30 float *y; /* prediction start */
31 int stride2 = 2*stride;
32 /* Prediction */
33 if (basis->predict_delay > 1)
34 rstart = x-stride2*(basis->predict_delay-1);
35 else
36 rstart = x;
37 r = rstart;
38 y = x + 1 - stride2*(basis->predict_length - basis->predict_delay);
40 for (i=0;i<len;i+=stride2)
42 float sum = 0;
43 const float *p = basis->predict;
44 float *y2 = y;
45 for (j=0;j<basis->predict_length;j++)
47 sum += *p++ * *y2;
48 y2 += stride2;
50 *r -= sum;
51 r += stride2;
52 y += stride2;
54 //return;
55 /* Update */
56 r = rstart + 1 - stride2*basis->update_delay;
57 y = rstart - stride2*(basis->update_length - basis->update_delay);
59 for (i=0;i<len;i+=stride2)
61 float sum = 0;
62 const float *p = basis->update;
63 float *y2 = y;
64 for (j=0;j<basis->update_length;j++)
66 sum += *p++ * *y2;
67 y2 += stride2;
69 *r += sum;
70 r += stride2;
71 y += stride2;
75 void lifting_backward(float *x, struct LiftingBasis *basis, int len, int stride)
77 int i,j;
78 float *r, *rstart, *ustart; /* residue/modified value */
79 float *y; /* prediction start */
80 int stride2 = 2*stride;
82 if (basis->predict_delay > 1)
83 rstart = x-2*stride*(basis->predict_delay-1);
84 else
85 rstart = x;
87 /* De-update */
88 ustart = rstart + 1 - stride2*basis->update_delay;
89 y = rstart - stride2*(basis->update_length - basis->update_delay);
90 r = ustart;
92 for (i=0;i<len;i+=stride2)
94 float sum = 0;
95 const float *p = basis->update;
96 float *y2 = y;
97 for (j=0;j<basis->update_length;j++)
99 sum += *p++ * *y2;
100 y2 += stride2;
102 *r -= sum;
103 r += stride2;
104 y += stride2;
107 /* De-predict */
108 if (basis->predict_delay > 1)
109 rstart = ustart-stride2*(basis->predict_delay-1)-1;
110 else
111 rstart = ustart-1;
112 r = rstart;
113 y = ustart - stride2*(basis->predict_length - basis->predict_delay);
115 for (i=0;i<len;i+=stride2)
117 float sum = 0;
118 const float *p = basis->predict;
119 float *y2 = y;
120 for (j=0;j<basis->predict_length;j++)
122 sum += *p++ * *y2;
123 y2 += stride2;
125 *r += sum;
126 r += stride2;
127 y += stride2;