[xiph-commits] r9636 - trunk/ghost/libghost
jm at svn.xiph.org
jm at svn.xiph.org
Thu Jul 28 17:29:36 PDT 2005
Author: jm
Date: 2005-07-28 17:29:33 -0700 (Thu, 28 Jul 2005)
New Revision: 9636
Modified:
trunk/ghost/libghost/lifting.c
trunk/ghost/libghost/lifting.h
trunk/ghost/libghost/testghost.c
Log:
Got predict, update and backward update to work
Modified: trunk/ghost/libghost/lifting.c
===================================================================
--- trunk/ghost/libghost/lifting.c 2005-07-28 21:10:29 UTC (rev 9635)
+++ trunk/ghost/libghost/lifting.c 2005-07-29 00:29:33 UTC (rev 9636)
@@ -28,47 +28,47 @@
int i,j;
float *r, *rstart; /* residue/modified value */
float *y; /* prediction start */
-
+ int stride2 = 2*stride;
/* Prediction */
if (basis->predict_delay > 1)
- rstart = x-2*stride*(basis->predict_delay-1);
+ rstart = x-stride2*(basis->predict_delay-1);
else
rstart = x;
r = rstart;
- y = x + 1 - 2*stride*(basis->predict_length - basis->predict_delay);
+ y = x + 1 - stride2*(basis->predict_length - basis->predict_delay);
- for (i=0;i<len;i++)
+ for (i=0;i<len;i+=stride2)
{
float sum = 0;
- float *p = basis->predict;
+ const float *p = basis->predict;
float *y2 = y;
for (j=0;j<basis->predict_length;j++)
{
sum += *p++ * *y2;
- y2 += stride;
+ y2 += stride2;
}
*r -= sum;
- r += stride;
- y += stride;
+ r += stride2;
+ y += stride2;
}
-
+ //return;
/* Update */
- r = rstart + 1 - 2*stride*basis->update_delay;
- y = rstart - 2*stride*(basis->update_length - basis->update_delay - 1);
+ r = rstart + 1 - stride2*basis->update_delay;
+ y = rstart - stride2*(basis->update_length - basis->update_delay - 1);
- for (i=0;i<len;i++)
+ for (i=0;i<len;i+=stride2)
{
float sum = 0;
- float *p = basis->update;
+ const float *p = basis->update;
float *y2 = y;
for (j=0;j<basis->update_length;j++)
{
sum += *p++ * *y2;
- y2 += stride;
+ y2 += stride2;
}
*r += sum;
- r += stride;
- y += stride;
+ r += stride2;
+ y += stride2;
}
}
@@ -77,11 +77,32 @@
int i,j;
float *r, *rstart; /* residue/modified value */
float *y; /* prediction start */
+ int stride2 = 2*stride;
if (basis->predict_delay > 1)
rstart = x-2*stride*(basis->predict_delay-1);
else
rstart = x;
+ /* De-update */
+ r = rstart + 1 - stride2*basis->update_delay;
+ y = rstart - stride2*(basis->update_length - basis->update_delay - 1);
+
+ for (i=0;i<len;i+=stride2)
+ {
+ float sum = 0;
+ const float *p = basis->update;
+ float *y2 = y;
+ for (j=0;j<basis->update_length;j++)
+ {
+ sum += *p++ * *y2;
+ y2 += stride2;
+ }
+ *r -= sum;
+ r += stride2;
+ y += stride2;
+ }
+
+
}
Modified: trunk/ghost/libghost/lifting.h
===================================================================
--- trunk/ghost/libghost/lifting.h 2005-07-28 21:10:29 UTC (rev 9635)
+++ trunk/ghost/libghost/lifting.h 2005-07-29 00:29:33 UTC (rev 9636)
@@ -24,10 +24,10 @@
#define _LIFTING_H
struct LiftingBasis {
- float *predict;
+ const float *predict;
int predict_length;
int predict_delay;
- float *update;
+ const float *update;
int update_length;
int update_delay;
};
Modified: trunk/ghost/libghost/testghost.c
===================================================================
--- trunk/ghost/libghost/testghost.c 2005-07-28 21:10:29 UTC (rev 9635)
+++ trunk/ghost/libghost/testghost.c 2005-07-29 00:29:33 UTC (rev 9636)
@@ -26,11 +26,20 @@
#include "sinusoids.h"
#include "ghost.h"
#include "pitch.h"
+#include "lifting.h"
+#include <stdlib.h>
+const float predict[11] = {-0.00499385545085393, 0.0110380571786845, -0.018414597815401, 0.0275862067026581, -0.0393646739536688, 0.055303264488734, -0.0787612707745417, 0.118522526792966, -0.29689, 0.80484, 0.4211};
+const float update[11] = {-0.000749078317628089, 0.00165570857680267, -0.00276218967231015, 0.00413793100539871, -0.00590470109305032, 0.0082954896733101, -0.0118141906161813, 0.0226, -0.07844, 0.34242, 0.221};
+
+
int main(int argc, char **argv)
{
GhostEncState *state;
FILE *fin;
+ struct LiftingBasis bas;
+ float x[1200];
+ int i;
/*float x[256];
float y[256];
float w[2] = {.05, .2};
@@ -44,6 +53,29 @@
printf ("%f %f\n", ai[0], bi[0]);
printf ("%f %f\n", ai[1], bi[1]);
*/
+ bas.predict_delay=1;
+ bas.predict_length=11;
+ bas.update_delay=1;
+ bas.update_length=11;
+ bas.predict = predict;
+ bas.update = update;
+ for (i=0;i<1200;i++)
+ {
+ //x[i] = 2*((1.f*rand())/RAND_MAX) - 1;
+ x[i] = sin(.3*i);
+ }
+ for (i=0;i<1024;i++)
+ printf ("%f ", x[i+30]);
+ printf ("\n");
+ lifting_forward(x+30, &bas, 1024, 1);
+ for (i=0;i<1024;i++)
+ printf ("%f ", x[i+30]);
+ printf ("\n");
+ lifting_backward(x+30, &bas, 1024, 1);
+ for (i=0;i<1024;i++)
+ printf ("%f ", x[i+30]);
+ printf ("\n");
+ return 0;
fin = fopen("test.sw", "r");
state = ghost_encoder_state_new(48000);
while (1)
More information about the commits
mailing list