summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <xiphmont@xiph.org>2000-02-07 20:03:17 +0000
committerMonty <xiphmont@xiph.org>2000-02-07 20:03:17 +0000
commitfd3ef6e3c313e86074cc8205075e8866f53af73c (patch)
tree94b2c0e048ff16732b4d0aef6c6119da29f9e2d8
parent3cb5a9983428d6dd7cd57398c903347e66c9cc2e (diff)
downloadlibvorbis-git-fd3ef6e3c313e86074cc8205075e8866f53af73c.tar.gz
There's work left to do, but progress toward first cut: lib and
examples are back together and running. Monty svn path=/trunk/vorbis/; revision=255
-rw-r--r--lib/codebook.c32
-rw-r--r--lib/envelope.c7
-rw-r--r--lib/floor0.c34
3 files changed, 40 insertions, 33 deletions
diff --git a/lib/codebook.c b/lib/codebook.c
index d55baa20..f21bc7f3 100644
--- a/lib/codebook.c
+++ b/lib/codebook.c
@@ -12,7 +12,7 @@
********************************************************************
function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.7 2000/02/06 13:40:39 xiphmont Exp $
+ last mod: $Id: codebook.c,v 1.8 2000/02/07 20:03:15 xiphmont Exp $
********************************************************************/
@@ -361,12 +361,24 @@ int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
return(book->c->lengthlist[a]);
}
-/* returns the number of bits and *modifies a* to the residual error *****/
+static double _dist(int el,double *a, double *b){
+ int i;
+ double acc=0.;
+ for(i=0;i<el;i++){
+ double val=(a[i]-b[i]);
+ acc+=val*val;
+ }
+ return acc;
+}
+
+/* returns the number of bits and *modifies a* to the quantized value *****/
int vorbis_book_encodev(codebook *book, double *a, oggpack_buffer *b){
encode_aux *t=book->c->encode_tree;
int dim=book->dim;
int ptr=0,k;
+#if 1
+ /* optimized, using the decision tree */
while(1){
double c=0.;
double *p=book->valuelist+t->p[ptr];
@@ -381,7 +393,19 @@ int vorbis_book_encodev(codebook *book, double *a, oggpack_buffer *b){
ptr= -t->ptr1[ptr];
if(ptr<=0)break;
}
- for(k=0;k<dim;k++)a[k]-=(book->valuelist-ptr*dim)[k];
+#else
+ /* brute force */
+ double this,best=_dist(book->dim,a,book->valuelist);
+ int i;
+ for(i=1;i<book->entries;i++){
+ this=_dist(book->dim,a,book->valuelist+i*book->dim);
+ if(this<best){
+ ptr=-i;
+ best=this;
+ }
+ }
+#endif
+ memcpy(a,book->valuelist-ptr*dim,dim*sizeof(double));
return(vorbis_book_encode(book,-ptr,b));
}
@@ -581,7 +605,7 @@ int main(){
exit(1);
}
for(i=0;i<TESTSIZE;i++)
- if(fabs(testvec[ptr][i]-qv[i]-iv[i])>.000001){
+ if(fabs(qv[i]-iv[i])>.000001){
fprintf(stderr,"input (%g) != output (%g) at position (%ld)\n",
iv[i],testvec[ptr][i]-qv[i],i);
exit(1);
diff --git a/lib/envelope.c b/lib/envelope.c
index 5f80473e..6d076405 100644
--- a/lib/envelope.c
+++ b/lib/envelope.c
@@ -12,7 +12,7 @@
********************************************************************
function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.c,v 1.14 2000/01/22 13:28:18 xiphmont Exp $
+ last mod: $Id: envelope.c,v 1.15 2000/02/07 20:03:16 xiphmont Exp $
Preecho calculation.
@@ -59,11 +59,12 @@ static void _ve_deltas(double *deltas,double *pcm,int n,double *window,
for(j=0;j<n;j++){
double acc=0.;
- memcpy(out,pcm+j*winsize,winsize);
+ memcpy(out,pcm+j*winsize,winsize*sizeof(double));
for(i=0;i<winsize;i++)
out[i]*=window[i];
-
+
mdct_forward(m,out,out);
+
for(i=winsize/10;i<winsize/2;i++)
acc+=fabs(out[i]);
if(deltas[j]<acc)deltas[j]=acc;
diff --git a/lib/floor0.c b/lib/floor0.c
index e18689f9..4b8df141 100644
--- a/lib/floor0.c
+++ b/lib/floor0.c
@@ -12,7 +12,7 @@
********************************************************************
function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.6 2000/02/06 13:39:40 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.7 2000/02/07 20:03:17 xiphmont Exp $
********************************************************************/
@@ -111,33 +111,20 @@ static int forward(vorbis_block *vb,vorbis_look_floor *i,
vorbis_lpc_to_lsp(out,out,look->m);
memcpy(work,out,sizeof(double)*look->m);
- for(j=12;j<20;j++)
- fprintf(stderr,"%0.3g, ",out[j]);
- fprintf(stderr,"\n");
-
- /* code the spectral envelope, and keep track of the actual quantized
- values */
+ /* code the spectral envelope, and keep track of the actual
+ quantized values; we don't want creeping error as each block is
+ nailed to the last quantized value of the previous block. */
_oggpack_write(&vb->opb,amp*32768,18);
{
codebook *b=vb->vd->fullbooks+info->books[0];
double last=0.;
for(j=0;j<look->m;){
- double next=out[j+b->dim-1];
- for(k=0;k<b->dim;k++,j++)out[j]-=last;
- last=next;
- }
- }
-
- for(k=0;k<info->stages;k++){
- codebook *b=vb->vd->fullbooks+info->books[k];
- for(j=0;j<look->m;j+=b->dim)
+ for(k=0;k<b->dim;k++)out[j+k]-=last;
vorbis_book_encodev(b,out+j,&vb->opb);
+ for(k=0;k<b->dim;k++,j++)out[j]+=last;
+ last=out[j-1];
+ }
}
-
- for(j=0;j<look->m;j++)
- out[j]=work[j]-out[j];
-
-
/* take the coefficients back to a spectral envelope curve */
vorbis_lsp_to_lpc(out,out,look->m);
@@ -168,11 +155,6 @@ static int inverse(vorbis_block *vb,vorbis_look_floor *i,double *out){
}
}
- for(j=12;j<20;j++)
- fprintf(stderr,"%0.3g, ",out[j]);
- fprintf(stderr,"\n");
-
-
/* take the coefficients back to a spectral envelope curve */
vorbis_lsp_to_lpc(out,out,look->m);
vorbis_lpc_to_curve(out,out,amp,&look->lpclook);