summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <xiphmont@xiph.org>2000-09-02 05:19:26 +0000
committerMonty <xiphmont@xiph.org>2000-09-02 05:19:26 +0000
commitcbc232c9744b39674fb48aef1c2362f4ea782291 (patch)
tree618379ddaf3fced3b48a4bea7aabb4f78e199792
parente7fc3692934bb45e2acf33e41193a6db17a14bad (diff)
downloadlibvorbis-git-cbc232c9744b39674fb48aef1c2362f4ea782291.tar.gz
Segher's patch. Still need to test.
Monty svn path=/branches/branch_postbeta2/vorbis/; revision=616
-rw-r--r--configure.in9
-rw-r--r--examples/decoder_example.c6
-rw-r--r--include/vorbis/codebook.h6
-rw-r--r--lib/bitwise.c435
-rw-r--r--lib/bitwise.h41
-rw-r--r--lib/block.c11
-rw-r--r--lib/bookinternal.h4
-rw-r--r--lib/codebook.c79
-rw-r--r--lib/floor0.c47
-rw-r--r--lib/lsp.c15
-rw-r--r--lib/mapping0.c21
-rw-r--r--lib/psy.c8
-rw-r--r--lib/res0.c39
-rw-r--r--lib/scales.h52
-rw-r--r--lib/sharedbook.c23
-rw-r--r--lib/time0.c19
-rw-r--r--lib/tone.c32
17 files changed, 758 insertions, 89 deletions
diff --git a/configure.in b/configure.in
index 98178cfe..67fa0821 100644
--- a/configure.in
+++ b/configure.in
@@ -1,4 +1,4 @@
-# $Id: configure.in,v 1.20.2.2 2000/08/31 08:59:58 xiphmont Exp $
+# $Id: configure.in,v 1.20.2.3 2000/09/02 05:19:24 xiphmont Exp $
AC_INIT(lib/mdct.c)
#AC_CONFIG_HEADER(config.h)
@@ -61,9 +61,10 @@ else
case $host in
*86-*-linux*)
DEBUG="-g -Wall -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char"
- OPT="-O20 -ffast-math -D_REENTRANT -fsigned-char"
- PROFILE="-pg -g -O20 -ffast-math -D_REENTRANT -fsigned-char"
-
+ OPT="-O20 -ffast-math -mno-ieee-fp -D_REENTRANT -fsigned-char"
+# PROFILE="-Wall -W -pg -O20 -ffast-math -D_REENTRANT -fsigned-char -fno-inline -static"
+ PROFILE="-Wall -W -pg -O20 -ffast-math -mno-ieee-fp -D_REENTRANT -fsigned-char -fno-inline -static"
+
# glibc < 2.1.3 has a serious FP bug in the math inline header
# that will cripple Vorbis. Look to see if the magic FP stack
# clobber is missing in the mathinline header, thus indicating
diff --git a/examples/decoder_example.c b/examples/decoder_example.c
index eefdb100..35fb4a0d 100644
--- a/examples/decoder_example.c
+++ b/examples/decoder_example.c
@@ -12,7 +12,7 @@
********************************************************************
function: simple example decoder
- last mod: $Id: decoder_example.c,v 1.11.2.2 2000/08/31 08:59:58 xiphmont Exp $
+ last mod: $Id: decoder_example.c,v 1.11.2.3 2000/09/02 05:19:24 xiphmont Exp $
********************************************************************/
@@ -239,7 +239,11 @@ int main(int argc, char **argv){
ogg_int16_t *ptr=convbuffer+i;
float *mono=pcm[i];
for(j=0;j<bout;j++){
+#if 1
int val=mono[j]*32767.;
+#else /* optional dither */
+ int val=mono[j]*32767.+drand48()-0.5;
+#endif
/* might as well guard against clipping */
if(val>32767){
val=32767;
diff --git a/include/vorbis/codebook.h b/include/vorbis/codebook.h
index b1cc6224..4a3b9ce4 100644
--- a/include/vorbis/codebook.h
+++ b/include/vorbis/codebook.h
@@ -12,7 +12,7 @@
********************************************************************
function: codebook types
- last mod: $Id: codebook.h,v 1.6.4.1 2000/08/31 08:59:58 xiphmont Exp $
+ last mod: $Id: codebook.h,v 1.6.4.2 2000/09/02 05:19:24 xiphmont Exp $
********************************************************************/
@@ -94,6 +94,10 @@ typedef struct encode_aux_pigeonhole{
} encode_aux_pigeonhole;
typedef struct decode_aux{
+ long *tab;
+ int *tabl;
+ int tabn;
+
long *ptr0;
long *ptr1;
long aux; /* number of tree entries */
diff --git a/lib/bitwise.c b/lib/bitwise.c
new file mode 100644
index 00000000..305800e3
--- /dev/null
+++ b/lib/bitwise.c
@@ -0,0 +1,435 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
+ * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
+ * PLEASE READ THESE TERMS DISTRIBUTING. *
+ * *
+ * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
+ * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
+ * http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: packing variable sized words into an octet stream
+ last mod: $Id: bitwise.c,v 1.12.4.1 2000/09/02 05:19:24 xiphmont Exp $
+
+ ********************************************************************/
+
+/* We're 'LSb' endian; if we write a word but read individual bits,
+ then we'll read the lsb first */
+
+#include <string.h>
+#include <stdlib.h>
+#include "bitwise.h"
+#include "misc.h"
+#include "os.h"
+
+#define BUFFER_INCREMENT 256
+
+static unsigned long mask[]=
+{0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
+ 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
+ 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
+ 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
+ 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
+ 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
+ 0x3fffffff,0x7fffffff,0xffffffff };
+
+void _oggpack_writeinit(oggpack_buffer *b){
+ memset(b,0,sizeof(oggpack_buffer));
+ b->ptr=b->buffer=malloc(BUFFER_INCREMENT);
+ b->buffer[0]='\0';
+ b->storage=BUFFER_INCREMENT;
+}
+
+void _oggpack_reset(oggpack_buffer *b){
+ b->ptr=b->buffer;
+ b->buffer[0]=0;
+ b->endbit=b->endbyte=0;
+}
+
+void _oggpack_writeclear(oggpack_buffer *b){
+ free(b->buffer);
+ memset(b,0,sizeof(oggpack_buffer));
+}
+
+void _oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
+ memset(b,0,sizeof(oggpack_buffer));
+ b->buffer=b->ptr=buf;
+ b->storage=bytes;
+}
+
+/* Takes only up to 32 bits. */
+void _oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
+ if(b->endbyte+4>=b->storage){
+ b->buffer=realloc(b->buffer,b->storage+BUFFER_INCREMENT);
+ b->storage+=BUFFER_INCREMENT;
+ b->ptr=b->buffer+b->endbyte;
+ }
+
+ value&=mask[bits];
+ bits+=b->endbit;
+
+ b->ptr[0]|=value<<b->endbit;
+
+ if(bits>=8){
+ b->ptr[1]=value>>(8-b->endbit);
+ if(bits>=16){
+ b->ptr[2]=value>>(16-b->endbit);
+ if(bits>=24){
+ b->ptr[3]=value>>(24-b->endbit);
+ if(bits>=32){
+ if(b->endbit)
+ b->ptr[4]=value>>(32-b->endbit);
+ else
+ b->ptr[4]=0;
+ }
+ }
+ }
+ }
+
+ b->endbyte+=bits/8;
+ b->ptr+=bits/8;
+ b->endbit=bits&7;
+}
+
+/* Read in bits without advancing the bitptr; bits <= 32 */
+long _oggpack_look(oggpack_buffer *b,int bits){
+ unsigned long ret;
+ unsigned long m=mask[bits];
+
+ bits+=b->endbit;
+
+ if(b->endbyte+4>=b->storage){
+ /* not the main path */
+ if(b->endbyte+(bits-1)/8>=b->storage)return(-1);
+ }
+
+ ret=b->ptr[0]>>b->endbit;
+ if(bits>8){
+ ret|=b->ptr[1]<<(8-b->endbit);
+ if(bits>16){
+ ret|=b->ptr[2]<<(16-b->endbit);
+ if(bits>24){
+ ret|=b->ptr[3]<<(24-b->endbit);
+ if(bits>32 && b->endbit)
+ ret|=b->ptr[4]<<(32-b->endbit);
+ }
+ }
+ }
+ return(m&ret);
+}
+
+long _oggpack_look1(oggpack_buffer *b){
+ if(b->endbyte>=b->storage)return(-1);
+ return((b->ptr[0]>>b->endbit)&1);
+}
+
+/* Read in bits without advancing the bitptr; bits <= 8 */
+/* we never return 'out of bits'; we'll handle it on _adv */
+long _oggpack_look_huff(oggpack_buffer *b,int bits){
+ unsigned long ret;
+ unsigned long m=mask[bits];
+
+ bits+=b->endbit;
+
+ ret=b->ptr[0]>>b->endbit;
+ if(bits>8){
+ ret|=b->ptr[1]<<(8-b->endbit);
+ }
+ return(m&ret);
+}
+
+void _oggpack_adv(oggpack_buffer *b,int bits){
+ bits+=b->endbit;
+ b->ptr+=bits/8;
+ b->endbyte+=bits/8;
+ b->endbit=bits&7;
+}
+
+void _oggpack_adv1(oggpack_buffer *b){
+ if(++(b->endbit)>7){
+ b->endbit=0;
+ b->ptr++;
+ b->endbyte++;
+ }
+}
+
+/* have to check for overflow now. return -1 on overflow */
+int _oggpack_adv_huff(oggpack_buffer *b,int bits){
+ if(b->endbyte+(b->endbit+bits-1)/8>=b->storage)return(-1);
+ bits+=b->endbit;
+ b->ptr+=bits/8;
+ b->endbyte+=bits/8;
+ b->endbit=bits&7;
+ return 0;
+}
+
+/* bits <= 32 */
+long _oggpack_read(oggpack_buffer *b,int bits){
+ unsigned long ret;
+ unsigned long m=mask[bits];
+
+ bits+=b->endbit;
+
+ if(b->endbyte+4>=b->storage){
+ /* not the main path */
+ ret=-1;
+ if(b->endbyte+(bits-1)/8>=b->storage)goto overflow;
+ }
+
+ ret=b->ptr[0]>>b->endbit;
+ if(bits>8){
+ ret|=b->ptr[1]<<(8-b->endbit);
+ if(bits>16){
+ ret|=b->ptr[2]<<(16-b->endbit);
+ if(bits>24){
+ ret|=b->ptr[3]<<(24-b->endbit);
+ if(bits>32 && b->endbit){
+ ret|=b->ptr[4]<<(32-b->endbit);
+ }
+ }
+ }
+ }
+ ret&=m;
+
+ overflow:
+
+ b->ptr+=bits/8;
+ b->endbyte+=bits/8;
+ b->endbit=bits&7;
+ return(ret);
+}
+
+long _oggpack_read1(oggpack_buffer *b){
+ unsigned long ret;
+
+ if(b->endbyte>=b->storage){
+ /* not the main path */
+ ret=-1;
+ goto overflow;
+ }
+
+ ret=(b->ptr[0]>>b->endbit)&1;
+
+ overflow:
+
+ b->endbit++;
+ if(b->endbit>7){
+ b->endbit=0;
+ b->ptr++;
+ b->endbyte++;
+ }
+ return(ret);
+}
+
+long _oggpack_bytes(oggpack_buffer *b){
+ return(b->endbyte+(b->endbit+7)/8);
+}
+
+long _oggpack_bits(oggpack_buffer *b){
+ return(b->endbyte*8+b->endbit);
+}
+
+unsigned char *_oggpack_buffer(oggpack_buffer *b){
+ return(b->buffer);
+}
+
+/* Self test of the bitwise routines; everything else is based on
+ them, so they damned well better be solid. */
+
+#ifdef _V_SELFTEST
+#include <stdio.h>
+
+static int ilog(unsigned int v){
+ int ret=0;
+ while(v){
+ ret++;
+ v>>=1;
+ }
+ return(ret);
+}
+
+oggpack_buffer o;
+oggpack_buffer r;
+
+void report(char *in){
+ fprintf(stderr,"%s",in);
+ exit(1);
+}
+
+void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
+ long bytes,i;
+ unsigned char *buffer;
+
+ _oggpack_reset(&o);
+ for(i=0;i<vals;i++)
+ _oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
+ buffer=_oggpack_buffer(&o);
+ bytes=_oggpack_bytes(&o);
+ if(bytes!=compsize)report("wrong number of bytes!\n");
+ for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
+ for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
+ report("wrote incorrect value!\n");
+ }
+ _oggpack_readinit(&r,buffer,bytes);
+ for(i=0;i<vals;i++){
+ int tbit=bits?bits:ilog(b[i]);
+ if(_oggpack_look(&r,tbit)==-1)
+ report("out of data!\n");
+ if(_oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
+ report("looked at incorrect value!\n");
+ if(tbit==1)
+ if(_oggpack_look1(&r)!=(b[i]&mask[tbit]))
+ report("looked at single bit incorrect value!\n");
+ if(tbit==1){
+ if(_oggpack_read1(&r)!=(b[i]&mask[tbit]))
+ report("read incorrect single bit value!\n");
+ }else{
+ if(_oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
+ report("read incorrect value!\n");
+ }
+ }
+ if(_oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
+}
+
+int main(void){
+ unsigned char *buffer;
+ long bytes,i;
+ static unsigned long testbuffer1[]=
+ {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
+ 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
+ int test1size=43;
+
+ static unsigned long testbuffer2[]=
+ {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
+ 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
+ 85525151,0,12321,1,349528352};
+ int test2size=21;
+
+ static unsigned long large[]=
+ {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
+ 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
+ 85525151,0,12321,1,2146528352};
+
+ static unsigned long testbuffer3[]=
+ {1,0,14,0,1,0,12,0,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,1,1,1,0,0,1,
+ 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
+ int test3size=56;
+
+ int onesize=33;
+ static int one[]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
+ 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
+ 223,4};
+
+ int twosize=6;
+ static int two[]={61,255,255,251,231,29};
+
+ int threesize=54;
+ static int three[]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
+ 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
+ 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
+ 100,52,4,14,18,86,77,1};
+
+ int foursize=38;
+ static int four[]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
+ 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
+ 28,2,133,0,1};
+
+ int fivesize=45;
+ static int five[]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
+ 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
+ 84,75,159,2,1,0,132,192,8,0,0,18,22};
+
+ int sixsize=7;
+ static int six[]={17,177,170,242,169,19,148};
+
+ /* Test read/write together */
+ /* Later we test against pregenerated bitstreams */
+ _oggpack_writeinit(&o);
+
+ fprintf(stderr,"\nSmall preclipped packing: ");
+ cliptest(testbuffer1,test1size,0,one,onesize);
+ fprintf(stderr,"ok.");
+
+ fprintf(stderr,"\nNull bit call: ");
+ cliptest(testbuffer3,test3size,0,two,twosize);
+ fprintf(stderr,"ok.");
+
+ fprintf(stderr,"\nLarge preclipped packing: ");
+ cliptest(testbuffer2,test2size,0,three,threesize);
+ fprintf(stderr,"ok.");
+
+ fprintf(stderr,"\n32 bit preclipped packing: ");
+ _oggpack_reset(&o);
+ for(i=0;i<test2size;i++)
+ _oggpack_write(&o,large[i],32);
+ buffer=_oggpack_buffer(&o);
+ bytes=_oggpack_bytes(&o);
+ _oggpack_readinit(&r,buffer,bytes);
+ for(i=0;i<test2size;i++){
+ if(_oggpack_look(&r,32)==-1)report("out of data. failed!");
+ if(_oggpack_look(&r,32)!=large[i]){
+ fprintf(stderr,"%ld != %ld (%lx!=%lx):",_oggpack_look(&r,32),large[i],
+ _oggpack_look(&r,32),large[i]);
+ report("read incorrect value!\n");
+ }
+ _oggpack_adv(&r,32);
+ }
+ if(_oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
+ fprintf(stderr,"ok.");
+
+ fprintf(stderr,"\nSmall unclipped packing: ");
+ cliptest(testbuffer1,test1size,7,four,foursize);
+ fprintf(stderr,"ok.");
+
+ fprintf(stderr,"\nLarge unclipped packing: ");
+ cliptest(testbuffer2,test2size,17,five,fivesize);
+ fprintf(stderr,"ok.");
+
+ fprintf(stderr,"\nSingle bit unclicpped packing: ");
+ cliptest(testbuffer3,test3size,1,six,sixsize);
+ fprintf(stderr,"ok.");
+
+ fprintf(stderr,"\nTesting read past end: ");
+ _oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
+ for(i=0;i<64;i++){
+ if(_oggpack_read(&r,1)!=0){
+ fprintf(stderr,"failed; got -1 prematurely.\n");
+ exit(1);
+ }
+ }
+ if(_oggpack_look(&r,1)!=-1 ||
+ _oggpack_read(&r,1)!=-1){
+ fprintf(stderr,"failed; read past end without -1.\n");
+ exit(1);
+ }
+ _oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
+ if(_oggpack_read(&r,30)!=0 || _oggpack_read(&r,16)!=0){
+ fprintf(stderr,"failed 2; got -1 prematurely.\n");
+ exit(1);
+ }
+
+ if(_oggpack_look(&r,18)!=0 ||
+ _oggpack_look(&r,18)!=0){
+ fprintf(stderr,"failed 3; got -1 prematurely.\n");
+ exit(1);
+ }
+ if(_oggpack_look(&r,19)!=-1 ||
+ _oggpack_look(&r,19)!=-1){
+ fprintf(stderr,"failed; read past end without -1.\n");
+ exit(1);
+ }
+ if(_oggpack_look(&r,32)!=-1 ||
+ _oggpack_look(&r,32)!=-1){
+ fprintf(stderr,"failed; read past end without -1.\n");
+ exit(1);
+ }
+ fprintf(stderr,"ok.\n\n");
+
+
+ return(0);
+}
+#endif
+#undef BUFFER_INCREMENT
diff --git a/lib/bitwise.h b/lib/bitwise.h
new file mode 100644
index 00000000..bf96e78b
--- /dev/null
+++ b/lib/bitwise.h
@@ -0,0 +1,41 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
+ * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
+ * PLEASE READ THESE TERMS DISTRIBUTING. *
+ * *
+ * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
+ * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
+ * http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: packing variable sized words into an octet stream
+ last mod: $Id: bitwise.h,v 1.6.4.1 2000/09/02 05:19:24 xiphmont Exp $
+
+ ********************************************************************/
+
+#ifndef _V_BITW_H_
+#define _V_BITW_H_
+
+#include "vorbis/codec.h"
+
+extern void _oggpack_writeinit(oggpack_buffer *b);
+extern void _oggpack_reset(oggpack_buffer *b);
+extern void _oggpack_writeclear(oggpack_buffer *b);
+extern void _oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
+extern void _oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
+extern long _oggpack_look(oggpack_buffer *b,int bits);
+extern long _oggpack_look_huff(oggpack_buffer *b,int bits);
+extern long _oggpack_look1(oggpack_buffer *b);
+extern void _oggpack_adv(oggpack_buffer *b,int bits);
+extern int _oggpack_adv_huff(oggpack_buffer *b,int bits);
+extern void _oggpack_adv1(oggpack_buffer *b);
+extern long _oggpack_read(oggpack_buffer *b,int bits);
+extern long _oggpack_read1(oggpack_buffer *b);
+extern long _oggpack_bytes(oggpack_buffer *b);
+extern long _oggpack_bits(oggpack_buffer *b);
+extern unsigned char *_oggpack_buffer(oggpack_buffer *b);
+
+#endif
diff --git a/lib/block.c b/lib/block.c
index b6bd7681..f2411e40 100644
--- a/lib/block.c
+++ b/lib/block.c
@@ -12,7 +12,7 @@
********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.38.2.1 2000/08/31 09:00:00 xiphmont Exp $
+ last mod: $Id: block.c,v 1.38.2.2 2000/09/02 05:19:24 xiphmont Exp $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
@@ -584,7 +584,7 @@ int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
return(0);
}
-/* Unike in analysis, the window is only partially applied for each
+/* Unlike in analysis, the window is only partially applied for each
block. The time domain envelope is not yet handled at the point of
calling (as it relies on the previous block). */
@@ -660,13 +660,14 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
for(j=0;j<vi->channels;j++){
float *pcm=v->pcm[j]+beginW;
-
+ float *p=vb->pcm[j];
+
/* the overlap/add section */
for(i=beginSl;i<endSl;i++)
- pcm[i]+=vb->pcm[j][i];
+ pcm[i]+=p[i];
/* the remaining section */
for(;i<sizeW;i++)
- pcm[i]=vb->pcm[j][i];
+ pcm[i]=p[i];
}
/* track the frame number... This is for convenience, but also
diff --git a/lib/bookinternal.h b/lib/bookinternal.h
index 2b2b7f91..6f0627d2 100644
--- a/lib/bookinternal.h
+++ b/lib/bookinternal.h
@@ -12,7 +12,7 @@
********************************************************************
function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: bookinternal.h,v 1.8.6.1 2000/08/31 09:00:00 xiphmont Exp $
+ last mod: $Id: bookinternal.h,v 1.8.6.2 2000/09/02 05:19:24 xiphmont Exp $
********************************************************************/
@@ -35,5 +35,7 @@ extern int vorbis_book_encodevs(codebook *book, float *a, oggpack_buffer *b,
extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
extern long vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
int step,int stagetype);
+extern long s_vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
+ int step,int stagetype);
#endif
diff --git a/lib/codebook.c b/lib/codebook.c
index ca6824eb..260c15c8 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.17.4.1 2000/08/31 09:00:00 xiphmont Exp $
+ last mod: $Id: codebook.c,v 1.17.4.2 2000/09/02 05:19:24 xiphmont Exp $
********************************************************************/
@@ -268,7 +268,7 @@ and doesn't change.
Residue0 encoding interleaves, uses multiple stages, and each stage
peels of a specific amount of resolution from a lattice (thus we want
-to match by threshhold, not nearest match). Residue doesn't *have* to
+to match by threshold, not nearest match). Residue doesn't *have* to
be encoded that way, but to change it, one will need to add more
infrastructure on the encode side (decode side is specced and simpler) */
@@ -309,14 +309,23 @@ int vorbis_book_encodevs(codebook *book,float *a,oggpack_buffer *b,
Cascades may be additive or multiplicitive; this is not inherent in
the codebook, but set in the code using the codebook. Like
interleaving, it's easiest to do it here.
- stage==0 -> declarative (set the value)
- stage==1 -> additive
- stage==2 -> multiplicitive */
+ addmul==0 -> declarative (set the value)
+ addmul==1 -> additive
+ addmul==2 -> multiplicitive */
/* returns the entry number or -1 on eof *************************************/
long vorbis_book_decode(codebook *book, oggpack_buffer *b){
long ptr=0;
decode_aux *t=book->decode_tree;
+ int lok = _oggpack_look(b, t->tabn);
+
+ if (lok >= 0) {
+ ptr = t->tab[lok];
+ _oggpack_adv(b, t->tabl[lok]);
+ if (ptr <= 0)
+ return -ptr;
+ }
+
do{
switch(_oggpack_read1(b)){
case 0:
@@ -337,22 +346,74 @@ long vorbis_book_decodevs(codebook *book,float *a,oggpack_buffer *b,
int step,int addmul){
long entry=vorbis_book_decode(book,b);
int i,o;
+ float *t;
if(entry==-1)return(-1);
+ t = book->valuelist+entry*book->dim;
+ switch(addmul){
+ case -1:
+ for(i=0,o=0;i<book->dim-3;i+=4,o+=4*step) {
+ a[o]=t[i];
+ a[o+step]=t[i+1];
+ a[o+2*step]=t[i+2];
+ a[o+3*step]=t[i+3];
+ }
+ for(;i<book->dim;i++,o+=step)
+ a[o]=t[i];
+ break;
+ case 0:
+ for(i=0,o=0;i<book->dim-3;i+=4,o+=4*step) {
+ a[o]+=t[i];
+ a[o+step]+=t[i+1];
+ a[o+2*step]+=t[i+2];
+ a[o+3*step]+=t[i+3];
+ }
+ for(;i<book->dim;i++,o+=step)
+ a[o]+=t[i];
+ break;
+ case 1:
+ for(i=0,o=0;i<book->dim-3;i+=4,o+=4*step) {
+ a[o]*=t[i];
+ a[o+step]*=t[i+1];
+ a[o+2*step]*=t[i+2];
+ a[o+3*step]*=t[i+3];
+ }
+ for(;i<book->dim;i++,o+=step)
+ a[o]*=t[i];
+ break;
+ }
+ return(entry);
+}
+
+/* returns 0 on OK or -1 on eof *************************************/
+long s_vorbis_book_decodevs(codebook *book,float *a,oggpack_buffer *b,
+ int step,int addmul){
+ long entry[step];
+ float *t[step];
+ int i,j,o;
+
+ for (i = 0; i < step; i++) {
+ entry[i]=vorbis_book_decode(book,b);
+ if(entry[i]==-1)return(-1);
+ t[i] = book->valuelist+entry[i]*book->dim;
+ }
switch(addmul){
case -1:
for(i=0,o=0;i<book->dim;i++,o+=step)
- a[o]=(book->valuelist+entry*book->dim)[i];
+ for (j=0;j<step;j++)
+ a[o+j]=t[j][i];
break;
case 0:
for(i=0,o=0;i<book->dim;i++,o+=step)
- a[o]+=(book->valuelist+entry*book->dim)[i];
+ for (j=0;j<step;j++)
+ a[o+j]+=t[j][i];
break;
case 1:
for(i=0,o=0;i<book->dim;i++,o+=step)
- a[o]*=(book->valuelist+entry*book->dim)[i];
+ for (j=0;j<step;j++)
+ a[o+j]*=t[j][i];
break;
}
- return(entry);
+ return(0);
}
#ifdef _V_SELFTEST
diff --git a/lib/floor0.c b/lib/floor0.c
index 8a3518ea..b3006b54 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.23.2.2 2000/08/31 09:00:00 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.23.2.3 2000/09/02 05:19:25 xiphmont Exp $
********************************************************************/
@@ -70,14 +70,14 @@ static long _f0_fit(codebook *book,
/***********************************************/
-static void free_info(vorbis_info_floor *i){
+static void floor0_free_info(vorbis_info_floor *i){
if(i){
memset(i,0,sizeof(vorbis_info_floor0));
free(i);
}
}
-static void free_look(vorbis_look_floor *i){
+static void floor0_free_look(vorbis_look_floor *i){
vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
if(i){
if(look->linearmap)free(look->linearmap);
@@ -88,7 +88,7 @@ static void free_look(vorbis_look_floor *i){
}
}
-static void pack (vorbis_info_floor *i,oggpack_buffer *opb){
+static void floor0_pack (vorbis_info_floor *i,oggpack_buffer *opb){
vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
int j;
_oggpack_write(opb,info->order,8);
@@ -101,7 +101,7 @@ static void pack (vorbis_info_floor *i,oggpack_buffer *opb){
_oggpack_write(opb,info->books[j],8);
}
-static vorbis_info_floor *unpack (vorbis_info *vi,oggpack_buffer *opb){
+static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
int j;
vorbis_info_floor0 *info=malloc(sizeof(vorbis_info_floor0));
info->order=_oggpack_read(opb,8);
@@ -122,7 +122,7 @@ static vorbis_info_floor *unpack (vorbis_info *vi,oggpack_buffer *opb){
}
return(info);
err_out:
- free_info(info);
+ floor0_free_info(info);
return(NULL);
}
@@ -134,7 +134,7 @@ static vorbis_info_floor *unpack (vorbis_info *vi,oggpack_buffer *opb){
Note that the scale depends on the sampling rate as well as the
linear block and mapping sizes */
-static vorbis_look_floor *look (vorbis_dsp_state *vd,vorbis_info_mode *mi,
+static vorbis_look_floor *floor0_look (vorbis_dsp_state *vd,vorbis_info_mode *mi,
vorbis_info_floor *i){
int j;
float scale;
@@ -257,8 +257,27 @@ void _lsp_to_curve(float *curve,float *lsp,float amp,
}
+void s_lsp_to_curve(float *curve,float *lsp,float amp,
+ vorbis_look_floor0 *l,char *name,long frameno,
+ float ampdB){
+ /* l->m+1 must be less than l->ln, but guard in case we get a bad stream */
+ float *lcurve=alloca(sizeof(double)*l->ln);
+ int i;
+
+ if(amp==0){
+ memset(curve,0,sizeof(double)*l->n);
+ return;
+ }
+ vorbis_lsp_to_curve(lcurve,l->ln,lsp,l->m,amp,l->lsp_look);
+
+ for (i = 0; i < l->ln; i++)
+ lcurve[i] = fromdB(lcurve[i]-ampdB);
+ for(i=0;i<l->n;i++)curve[i]=lcurve[l->linearmap[i]];
+
+}
+
static long seq=0;
-static int forward(vorbis_block *vb,vorbis_look_floor *i,
+static int floor0_forward(vorbis_block *vb,vorbis_look_floor *i,
float *in,float *out){
long j;
vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
@@ -364,8 +383,7 @@ static int forward(vorbis_block *vb,vorbis_look_floor *i,
#endif
/* take the coefficients back to a spectral envelope curve */
- _lsp_to_curve(out,work,amp,look,"Ffloor",seq++);
- for(j=0;j<look->n;j++)out[j]= fromdB(out[j]-info->ampdB);
+ s_lsp_to_curve(out,work,amp,look,"Ffloor",seq++,info->ampdB);
return(1);
}
@@ -374,7 +392,7 @@ static int forward(vorbis_block *vb,vorbis_look_floor *i,
return(0);
}
-static int inverse(vorbis_block *vb,vorbis_look_floor *i,float *out){
+static int floor0_inverse(vorbis_block *vb,vorbis_look_floor *i,float *out){
vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
vorbis_info_floor0 *info=look->vi;
int j,k;
@@ -399,9 +417,7 @@ static int inverse(vorbis_block *vb,vorbis_look_floor *i,float *out){
}
/* take the coefficients back to a spectral envelope curve */
- _lsp_to_curve(out,out,amp,look,"",0);
-
- for(j=0;j<look->n;j++)out[j]=fromdB(out[j]-info->ampdB);
+ s_lsp_to_curve(out,out,amp,look,"",0,info->ampdB);
return(1);
}
}
@@ -413,7 +429,8 @@ static int inverse(vorbis_block *vb,vorbis_look_floor *i,float *out){
/* export hooks */
vorbis_func_floor floor0_exportbundle={
- &pack,&unpack,&look,&free_info,&free_look,&forward,&inverse
+ &floor0_pack,&floor0_unpack,&floor0_look,&floor0_free_info,
+ &floor0_free_look,&floor0_forward,&floor0_inverse
};
diff --git a/lib/lsp.c b/lib/lsp.c
index bc1dbcc0..a2a4ab2b 100644
--- a/lib/lsp.c
+++ b/lib/lsp.c
@@ -12,7 +12,7 @@
********************************************************************
function: LSP (also called LSF) conversion routines
- last mod: $Id: lsp.c,v 1.9.2.1 2000/08/31 09:00:00 xiphmont Exp $
+ last mod: $Id: lsp.c,v 1.9.2.2 2000/09/02 05:19:25 xiphmont Exp $
The LSP generation code is taken (with minimal modification) from
"On the Computation of the LSP Frequencies" by Joseph Rothweiler
@@ -46,14 +46,13 @@ void vorbis_lsp_to_curve(float *curve,int n,float *lsp,int m,float amp,
for(i=0;i<m;i++)coslsp[i]=2*cos(lsp[i]);
for(k=0;k<n;k++){
- float p=.70710678118654752440;
- float q=.70710678118654752440;
- for(j=0;j<m;){
- p*= *w-coslsp[j++];
- q*= *w-coslsp[j++];
+ double p=.5;
+ double q=.5;
+ for(j=0;j<m;j+=2){
+ p*= w[k]-coslsp[j];
+ q*= w[k]-coslsp[j+1];
}
- curve[k]=amp/sqrt(p*p*(1.+ *w*.5)+q*q*(1.- *w*.5));
- w++;
+ curve[k]=amp/sqrt(p*p*(2.+ w[k])+q*q*(2.- w[k]));
}
}
diff --git a/lib/mapping0.c b/lib/mapping0.c
index 8f6ad6f9..0f7c050a 100644
--- a/lib/mapping0.c
+++ b/lib/mapping0.c
@@ -12,7 +12,7 @@
********************************************************************
function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.15.2.1 2000/08/31 09:00:00 xiphmont Exp $
+ last mod: $Id: mapping0.c,v 1.15.2.2 2000/09/02 05:19:25 xiphmont Exp $
********************************************************************/
@@ -56,14 +56,14 @@ typedef struct {
invalidate decay */
} vorbis_look_mapping0;
-static void free_info(vorbis_info_mapping *i){
+static void mapping0_free_info(vorbis_info_mapping *i){
if(i){
memset(i,0,sizeof(vorbis_info_mapping0));
free(i);
}
}
-static void free_look(vorbis_look_mapping *look){
+static void mapping0_free_look(vorbis_look_mapping *look){
int i;
vorbis_look_mapping0 *l=(vorbis_look_mapping0 *)look;
if(l){
@@ -93,7 +93,7 @@ static void free_look(vorbis_look_mapping *look){
}
}
-static vorbis_look_mapping *look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
+static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
vorbis_info_mapping *m){
int i;
vorbis_info *vi=vd->vi;
@@ -143,7 +143,7 @@ static vorbis_look_mapping *look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
return(look);
}
-static void pack(vorbis_info *vi,vorbis_info_mapping *vm,oggpack_buffer *opb){
+static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,oggpack_buffer *opb){
int i;
vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
@@ -161,7 +161,7 @@ static void pack(vorbis_info *vi,vorbis_info_mapping *vm,oggpack_buffer *opb){
}
/* also responsible for range checking */
-static vorbis_info_mapping *unpack(vorbis_info *vi,oggpack_buffer *opb){
+static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
int i;
vorbis_info_mapping0 *info=calloc(1,sizeof(vorbis_info_mapping0));
memset(info,0,sizeof(vorbis_info_mapping0));
@@ -186,7 +186,7 @@ static vorbis_info_mapping *unpack(vorbis_info *vi,oggpack_buffer *opb){
return info;
err_out:
- free_info(info);
+ mapping0_free_info(info);
return(NULL);
}
@@ -201,7 +201,7 @@ static vorbis_info_mapping *unpack(vorbis_info *vi,oggpack_buffer *opb){
/* no time mapping implementation for now */
static long seq=0;
-static int forward(vorbis_block *vb,vorbis_look_mapping *l){
+static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
vorbis_dsp_state *vd=vb->vd;
vorbis_info *vi=vd->vi;
vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
@@ -303,7 +303,7 @@ static int forward(vorbis_block *vb,vorbis_look_mapping *l){
return(0);
}
-static int inverse(vorbis_block *vb,vorbis_look_mapping *l){
+static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){
vorbis_dsp_state *vd=vb->vd;
vorbis_info *vi=vd->vi;
vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
@@ -374,7 +374,8 @@ static int inverse(vorbis_block *vb,vorbis_look_mapping *l){
/* export hooks */
vorbis_func_mapping mapping0_exportbundle={
- &pack,&unpack,&look,&free_info,&free_look,&forward,&inverse
+ &mapping0_pack,&mapping0_unpack,&mapping0_look,&mapping0_free_info,
+ &mapping0_free_look,&mapping0_forward,&mapping0_inverse
};
diff --git a/lib/psy.c b/lib/psy.c
index 2854dc80..3c463ab5 100644
--- a/lib/psy.c
+++ b/lib/psy.c
@@ -12,7 +12,7 @@
********************************************************************
function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.26.2.2 2000/08/31 09:00:01 xiphmont Exp $
+ last mod: $Id: psy.c,v 1.26.2.3 2000/09/02 05:19:25 xiphmont Exp $
********************************************************************/
@@ -515,7 +515,7 @@ static void bark_noise(long n,float *b,float *f,float *noise){
memset(norm,0,n*sizeof(float));
while(hi<n){
- val=todB(f[i]*f[i])+400.;
+ val=todB_nn(f[i]*f[i])+400.;
del=1./(i-lo);
noise[lo]+=val*del;
noise[i]-=val*del;
@@ -540,7 +540,7 @@ static void bark_noise(long n,float *b,float *f,float *noise){
long hii=hi-i;
for(;i<n;i++){
- val=todB(f[i]*f[i])+400.;
+ val=todB_nn(f[i]*f[i])+400.;
del=1./(hii);
noise[i]-=val*del;
norm[i]-=del;
@@ -552,7 +552,7 @@ static void bark_noise(long n,float *b,float *f,float *noise){
norm[i]-=del;
}
for(i=1,lo=n-ilo;lo<n;lo++,i++){
- val=todB(f[n-i]*f[n-i])+400.;
+ val=todB_nn(f[n-i]*f[n-i])+400.;
del=1./ilo;
noise[lo]+=val*del;
norm[lo]+=del;
diff --git a/lib/res0.c b/lib/res0.c
index 370eca48..0f908430 100644
--- a/lib/res0.c
+++ b/lib/res0.c
@@ -12,7 +12,7 @@
********************************************************************
function: residue backend 0 implementation
- last mod: $Id: res0.c,v 1.17.2.1 2000/08/31 09:00:01 xiphmont Exp $
+ last mod: $Id: res0.c,v 1.17.2.2 2000/09/02 05:19:25 xiphmont Exp $
********************************************************************/
@@ -45,14 +45,14 @@ typedef struct {
int **decodemap;
} vorbis_look_residue0;
-void free_info(vorbis_info_residue *i){
+void res0_free_info(vorbis_info_residue *i){
if(i){
memset(i,0,sizeof(vorbis_info_residue0));
free(i);
}
}
-void free_look(vorbis_look_residue *i){
+void res0_free_look(vorbis_look_residue *i){
int j;
if(i){
vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
@@ -67,7 +67,7 @@ void free_look(vorbis_look_residue *i){
}
}
-void pack(vorbis_info_residue *vr,oggpack_buffer *opb){
+void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
int j,acc=0;
_oggpack_write(opb,info->begin,24);
@@ -87,7 +87,7 @@ void pack(vorbis_info_residue *vr,oggpack_buffer *opb){
}
/* vorbis_info is for range checking */
-vorbis_info_residue *unpack(vorbis_info *vi,oggpack_buffer *opb){
+vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
int j,acc=0;
vorbis_info_residue0 *info=calloc(1,sizeof(vorbis_info_residue0));
@@ -112,11 +112,11 @@ vorbis_info_residue *unpack(vorbis_info *vi,oggpack_buffer *opb){
return(info);
errout:
- free_info(info);
+ res0_free_info(info);
return(NULL);
}
-vorbis_look_residue *look (vorbis_dsp_state *vd,vorbis_info_mode *vm,
+vorbis_look_residue *res0_look (vorbis_dsp_state *vd,vorbis_info_mode *vm,
vorbis_info_residue *vr){
vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
vorbis_look_residue0 *look=calloc(1,sizeof(vorbis_look_residue0));
@@ -235,9 +235,8 @@ static int _decodepart(oggpack_buffer *opb,float *work,float *vec, int n,
for(j=0;j<stages;j++){
int dim=books[j]->dim;
int step=n/dim;
- for(i=0;i<step;i++)
- if(vorbis_book_decodevs(books[j],work+i,opb,step,0)==-1)
- return(-1);
+ if(s_vorbis_book_decodevs(books[j],work+i,opb,step,0)==-1)
+ return(-1);
}
for(i=0;i<n;i++)
@@ -246,7 +245,7 @@ static int _decodepart(oggpack_buffer *opb,float *work,float *vec, int n,
return(0);
}
-int forward(vorbis_block *vb,vorbis_look_residue *vl,
+int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
float **in,int ch){
long i,j,k,l;
vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
@@ -290,7 +289,7 @@ int forward(vorbis_block *vb,vorbis_look_residue *vl,
/* we code the partition words for each channel, then the residual
words for a partition per channel until we've written all the
residual words for that partition word. Then write the next
- parition channel words... */
+ partition channel words... */
for(i=info->begin,l=0;i<info->end;){
/* first we encode a partition codeword for each channel */
@@ -324,7 +323,7 @@ int forward(vorbis_block *vb,vorbis_look_residue *vl,
}
/* a truncated packet here just means 'stop working'; it's not an error */
-int inverse(vorbis_block *vb,vorbis_look_residue *vl,float **in,int ch){
+int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,float **in,int ch){
long i,j,k,l,transend=vb->pcmend/2;
vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
vorbis_info_residue0 *info=look->info;
@@ -378,11 +377,11 @@ int inverse(vorbis_block *vb,vorbis_look_residue *vl,float **in,int ch){
}
vorbis_func_residue residue0_exportbundle={
- &pack,
- &unpack,
- &look,
- &free_info,
- &free_look,
- &forward,
- &inverse
+ &res0_pack,
+ &res0_unpack,
+ &res0_look,
+ &res0_free_info,
+ &res0_free_look,
+ &res0_forward,
+ &res0_inverse
};
diff --git a/lib/scales.h b/lib/scales.h
new file mode 100644
index 00000000..a19abba2
--- /dev/null
+++ b/lib/scales.h
@@ -0,0 +1,52 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
+ * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
+ * PLEASE READ THESE TERMS DISTRIBUTING. *
+ * *
+ * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
+ * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
+ * http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: linear scale -> dB, Bark and Mel scales
+ last mod: $Id: scales.h,v 1.5.6.1 2000/09/02 05:19:25 xiphmont Exp $
+
+ ********************************************************************/
+
+#ifndef _V_SCALE_H_
+#define _V_SCALES_H_
+
+#include <math.h>
+
+/* 20log10(x) */
+#define DYNAMIC_RANGE_dB 200.
+#define todB(x) ((x)==0?-9.e40:log(fabs(x))*8.6858896)
+#define todB_nn(x) ((x)==0?-9.e40:log(x)*8.6858896)
+#define fromdB(x) (exp((x)*.11512925))
+
+
+/* The bark scale equations are approximations, since the original
+ table was somewhat hand rolled. The below are chosen to have the
+ best possible fit to the rolled tables, thus their somewhat odd
+ appearance (these are more accurate and over a longer range than
+ the oft-quoted bark equations found in the texts I have). The
+ approximations are valid from 0 - 30kHz (nyquist) or so.
+
+ all f in Hz, z in Bark */
+
+#define toBARK(f) (13.1*atan(.00074*(f))+2.24*atan((f)*(f)*1.85e-8)+1e-4*(f))
+#define fromBARK(z) (102.*(z)-2.*pow(z,2.)+.4*pow(z,3)+pow(1.46,z)-1.)
+#define toMEL(f) (log(1.+(f)*.001)*1442.695)
+#define fromMEL(m) (1000.*exp((m)/1442.695)-1000.)
+
+/* Frequency to octave. We arbitrarily declare 125.0 Hz to be octave
+ 0.0 */
+
+#define toOC(f) (log(f)*1.442695-6.965784)
+#define fromOC(o) (exp(((o)+6.965784)*.693147))
+
+#endif
+
diff --git a/lib/sharedbook.c b/lib/sharedbook.c
index b598f678..54c7ca51 100644
--- a/lib/sharedbook.c
+++ b/lib/sharedbook.c
@@ -12,7 +12,7 @@
********************************************************************
function: basic shared codebook operations
- last mod: $Id: sharedbook.c,v 1.7.4.2 2000/08/31 09:00:02 xiphmont Exp $
+ last mod: $Id: sharedbook.c,v 1.7.4.3 2000/09/02 05:19:25 xiphmont Exp $
********************************************************************/
@@ -142,7 +142,7 @@ long *_make_words(long *l,long n){
/* build the decode helper tree from the codewords */
decode_aux *_make_decode_tree(codebook *c){
const static_codebook *s=c->c;
- long top=0,i,j;
+ long top=0,i,j,n;
decode_aux *t=malloc(sizeof(decode_aux));
long *ptr0=t->ptr0=calloc(c->entries*2,sizeof(long));
long *ptr1=t->ptr1=calloc(c->entries*2,sizeof(long));
@@ -173,6 +173,25 @@ decode_aux *_make_decode_tree(codebook *c){
}
}
free(codelist);
+
+ t->tabn = _ilog(c->entries)-4; /* this is magic */
+ if(t->tabn<5)t->tabn=5;
+ n = 1<<t->tabn;
+ t->tab = malloc(n*sizeof(long));
+ t->tabl = malloc(n*sizeof(int));
+ for (i = 0; i < n; i++) {
+ long p = 0;
+ for (j = 0; j < t->tabn && (p > 0 || j == 0); j++) {
+ if (i & (1 << j))
+ p = ptr1[p];
+ else
+ p = ptr0[p];
+ }
+ /* now j == length, and p == -code */
+ t->tab[i] = p;
+ t->tabl[i] = j;
+ }
+
return(t);
}
diff --git a/lib/time0.c b/lib/time0.c
index 4fa644f9..9744d779 100644
--- a/lib/time0.c
+++ b/lib/time0.c
@@ -12,7 +12,7 @@
********************************************************************
function: time backend 0 (dummy)
- last mod: $Id: time0.c,v 1.5.8.1 2000/08/31 09:00:02 xiphmont Exp $
+ last mod: $Id: time0.c,v 1.5.8.2 2000/09/02 05:19:25 xiphmont Exp $
********************************************************************/
@@ -22,30 +22,31 @@
#include "registry.h"
#include "misc.h"
-static void pack (vorbis_info_time *i,oggpack_buffer *opb){
+static void time0_pack (vorbis_info_time *i,oggpack_buffer *opb){
}
-static vorbis_info_time *unpack (vorbis_info *vi,oggpack_buffer *opb){
+static vorbis_info_time *time0_unpack (vorbis_info *vi,oggpack_buffer *opb){
return "";
}
-static vorbis_look_time *look (vorbis_dsp_state *vd,vorbis_info_mode *mi,
+static vorbis_look_time *time0_look (vorbis_dsp_state *vd,vorbis_info_mode *mi,
vorbis_info_time *i){
return "";
}
-static void free_info(vorbis_info_time *i){
+static void time0_free_info(vorbis_info_time *i){
}
-static void free_look(vorbis_look_time *i){
+static void time0_free_look(vorbis_look_time *i){
}
-static int forward(vorbis_block *vb,vorbis_look_time *i,
+static int time0_forward(vorbis_block *vb,vorbis_look_time *i,
float *in,float *out){
return(0);
}
-static int inverse(vorbis_block *vb,vorbis_look_time *i,
+static int time0_inverse(vorbis_block *vb,vorbis_look_time *i,
float *in,float *out){
return(0);
}
/* export hooks */
vorbis_func_time time0_exportbundle={
- &pack,&unpack,&look,&free_info,&free_look,&forward,&inverse
+ &time0_pack,&time0_unpack,&time0_look,&time0_free_info,
+ &time0_free_look,&time0_forward,&time0_inverse
};
diff --git a/lib/tone.c b/lib/tone.c
new file mode 100644
index 00000000..3cc32b36
--- /dev/null
+++ b/lib/tone.c
@@ -0,0 +1,32 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+void usage(){
+ fprintf(stderr,"tone <frequency_Hz> [<amplitude>]\n");
+ exit(1);
+}
+
+int main (int argc,char *argv[]){
+ int i;
+ double f;
+ double amp=32767.;
+
+ if(argc<2)usage();
+ f=atof(argv[1]);
+ if(argc>=3)amp=atof(argv[2])*32767.;
+
+ for(i=0;i<44100*10;i++){
+ long val=rint(amp*sin(i/44100.*f*2*M_PI));
+ if(val>32767.)val=32767.;
+ if(val<-32768.)val=-32768.;
+
+ fprintf(stdout,"%c%c%c%c",
+ (char)(val&0xff),
+ (char)((val>>8)&0xff),
+ (char)(val&0xff),
+ (char)((val>>8)&0xff));
+ }
+ return(0);
+}
+