[xiph-commits] r13454 - trunk/ghost/libghost
jm at svn.xiph.org
jm at svn.xiph.org
Mon Aug 6 02:50:16 PDT 2007
Author: jm
Date: 2007-08-06 02:50:14 -0700 (Mon, 06 Aug 2007)
New Revision: 13454
Modified:
trunk/ghost/libghost/adpcm.c
Log:
work in progress (adpcm)
Modified: trunk/ghost/libghost/adpcm.c
===================================================================
--- trunk/ghost/libghost/adpcm.c 2007-08-06 00:12:36 UTC (rev 13453)
+++ trunk/ghost/libghost/adpcm.c 2007-08-06 09:50:14 UTC (rev 13454)
@@ -22,30 +22,44 @@
#include <math.h>
-void adpcm_quant(float *x, float *a, int *q, int N, int len)
+typedef struct {
+ int N;
+ float *coef;
+ float *mem;
+} ADPCMState;
+
+ADPCMState *adpcm_init(int N)
{
+ int i;
+ ADPCMState *st = malloc(sizeof(ADPCMState));
+ st->N = N;
+ st->coef = malloc(N*sizeof(float));
+ st->mem = malloc(N*sizeof(float));
+ for (i=0;i<N;i++)
+ {
+ st->coef[i] = 0;
+ st->mem[i] = 0;
+ }
+}
+
+void adpcm_quant(ADPCMState *st, float *x, int *q, int len)
+{
int i,j;
+ int N=st->N;
+ float *a = st->coef;
+
for (i=0;i<len;i++)
{
float p = 0;
/* Prediction: conceptual code, this will segfault (or worse) */
for (j=0;j<N;j++)
- p += a[j]*q[i-j-1];
+ p += a[j]*x[i-j-1];
/* Difference */
q[i] = rint(x[i]-p);
+ x[i] = q[i]+p;
/* Adaptation: conceptual code, this will segfault (or worse) */
for (j=0;j<N;j++)
a[j] += q[i]*q[i-j-1]/(q[i]*q[i]);
}
}
-void adpcm_unquant(int *q, float *a, float *x, int len)
-{
- int i;
- for (i=0;i<len;i++)
- {
- float p = 0;
- x[i] = q[i]+p;
- }
-}
-
More information about the commits
mailing list