Commit 5365ea64 authored by Monty's avatar Monty
Browse files


The lib and vq, at least, build again.  Tackling the examples and xmms
now.  There are still unfinished portions of the lib rearranging
(notably, floor0.c and res0.c)

Monty

svn path=/trunk/vorbis/; revision=244
parent cab466d0
# vorbis makefile configured for use with gcc on any platform
# $Id: Makefile.in,v 1.3 2000/01/22 13:28:07 xiphmont Exp $
# $Id: Makefile.in,v 1.4 2000/01/28 09:04:57 xiphmont Exp $
###############################################################################
# #
......@@ -28,7 +28,7 @@ RANLIB=@RANLIB@
LIBS=@LIBS@ -lm
HFILES = ../include/vorbis/codec.h ../include/vorbis/vorbisfile.h \
../include/vorbis/internal.h ../include/vorbis/backend.h \
../include/vorbis/internal.h ../include/vorbis/backends.h \
../include/vorbis/codebook.h
OFILES = encoder_example.o decoder_example.o chaining_example.o
BINFILES = encoder_example decoder_example chaining_example
......
......@@ -12,7 +12,7 @@
********************************************************************
function: simple example encoder
last mod: $Id: encoder_example.c,v 1.4 2000/01/22 13:28:09 xiphmont Exp $
last mod: $Id: encoder_example.c,v 1.5 2000/01/28 09:04:58 xiphmont Exp $
********************************************************************/
......@@ -38,6 +38,8 @@ int main(){
vorbis_info vi; /* struct that stores all the static vorbis bitstream
settings */
vorbis_comment vc; /* struct that stores all the user comments */
settings */
vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
vorbis_block vb; /* local working space for packet->PCM decode */
......
......@@ -13,7 +13,7 @@
function: libvorbis backend and mapping structures; needed for
static mode headers
last mod: $Id: backends.h,v 1.2 2000/01/22 13:28:10 xiphmont Exp $
last mod: $Id: backends.h,v 1.3 2000/01/28 09:04:59 xiphmont Exp $
********************************************************************/
......@@ -59,7 +59,7 @@ typedef struct{
int (*forward) (struct vorbis_block *,vorbis_look_floor *,
double *,double *);
int (*inverse) (struct vorbis_block *,vorbis_look_floor *,
double *,double *);
double *);
} vorbis_func_floor;
typedef struct{
......@@ -79,9 +79,9 @@ typedef struct{
void (*free_info) (vorbis_info_residue *);
void (*free_look) (vorbis_look_residue *);
int (*forward) (struct vorbis_block *,vorbis_look_residue *,
double *,double *);
double **,int **,int);
int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
double *,double *);
double **,int);
} vorbis_func_residue;
typedef struct vorbis_info_residue0{
......@@ -96,7 +96,8 @@ typedef struct vorbis_info_residue0{
/* Mapping backend generic *****************************************/
typedef struct{
void (*pack) (vorbis_info_mapping *,oggpack_buffer *);
void (*pack) (vorbis_info *,vorbis_info_mapping *,
oggpack_buffer *);
vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
vorbis_look_mapping *(*look) (vorbis_info *,vorbis_info_mode *,
vorbis_info_mapping *);
......
......@@ -1165,7 +1165,7 @@ static encode_aux _vq_aux_lsp20_0 = {
1694, 1694
};
static codebook _vq_book_lsp20_0 = {
static static_codebook _vq_book_lsp20_0 = {
4, 256, 4152003, 2812515, 8, 1,
_vq_quantlist_lsp20_0,
_vq_lengthlist_lsp20_0,
......
......@@ -1689,7 +1689,7 @@ static encode_aux _vq_aux_lsp32_0 = {
2743, 2743
};
static codebook _vq_book_lsp32_0 = {
static static_codebook _vq_book_lsp32_0 = {
4, 256, 4089638, 2558033, 8, 1,
_vq_quantlist_lsp32_0,
_vq_lengthlist_lsp32_0,
......
......@@ -12,7 +12,7 @@
********************************************************************
function: codebook types
last mod: $Id: codebook.h,v 1.3 2000/01/22 10:40:36 xiphmont Exp $
last mod: $Id: codebook.h,v 1.4 2000/01/28 09:05:00 xiphmont Exp $
********************************************************************/
......@@ -69,7 +69,7 @@ typedef struct decode_aux{
typedef struct codebook{
long dim; /* codebook dimensions (elements per vector) */
long entries; /* codebook entries */
static_codebook *c;
const static_codebook *c;
double *valuelist; /* list of dim*entries actual entry values */
long *codelist; /* list of bitstream codewords for each entry */
......
......@@ -12,7 +12,7 @@
********************************************************************
function: libvorbis codec headers
last mod: $Id: codec.h,v 1.5 2000/01/22 13:28:11 xiphmont Exp $
last mod: $Id: codec.h,v 1.6 2000/01/28 09:05:01 xiphmont Exp $
********************************************************************/
......@@ -294,14 +294,14 @@ typedef struct vorbis_block{
/* the comments are not part of vorbis_info so that vorbis_info can be
static storage */
typedef struct vorbis_comments{
typedef struct vorbis_comment{
/* unlimited user comment fields. libvorbis writes 'libvorbis'
whatever vendor is set to in encode */
char **user_comments;
int comments;
char *vendor;
} vorbis_comments;
} vorbis_comment;
/* libvorbis encodes in two abstraction layers; first we perform DSP
......@@ -353,18 +353,21 @@ extern int ogg_page_pageno(ogg_page *og);
/* Vorbis PRIMITIVES: general ***************************************/
extern int vorbis_info_init(vorbis_info *vi,vorbis_comments *vc);
extern int vorbis_comment_init(vorbis_comments *vc);
extern int vorbis_comment_add(vorbis_comments *vc, char *comment);
extern int vorbis_comment_clear(vorbis_comments *vc);
extern void vorbis_info_init(vorbis_info *vi);
extern void vorbis_info_clear(vorbis_info *vi);
extern void vorbis_comment_init(vorbis_comment *vc);
extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
extern void vorbis_comment_clear(vorbis_comment *vc);
extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
extern int vorbis_block_clear(vorbis_block *vb);
extern void vorbis_dsp_clear(vorbis_dsp_state *v);
/* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
vorbis_comment *vc,
ogg_packet *op,
ogg_packet *op_comm,
ogg_packet *op_code);
......@@ -374,7 +377,7 @@ extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
/* Vorbis PRIMITIVES: synthesis layer *******************************/
extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comments *vc,
extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
ogg_packet *op);
extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
......
......@@ -12,7 +12,7 @@
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
last mod: $Id: vorbisfile.h,v 1.1 2000/01/05 03:10:47 xiphmont Exp $
last mod: $Id: vorbisfile.h,v 1.2 2000/01/28 09:05:02 xiphmont Exp $
********************************************************************/
......@@ -37,6 +37,7 @@ typedef struct {
long *serialnos;
int64_t *pcmlengths;
vorbis_info *vi;
vorbis_comment *vc;
/* Decoding working state local storage */
int64_t pcm_offset;
......@@ -72,6 +73,7 @@ extern int64_t ov_pcm_tell(OggVorbis_File *vf);
extern double ov_time_tell(OggVorbis_File *vf);
extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
int bigendianp,int word,int sgned,int *bitstream);
......
# vorbis makefile configured for use with gcc on any platform
# $Id: Makefile.in,v 1.23 2000/01/22 13:28:13 xiphmont Exp $
# $Id: Makefile.in,v 1.24 2000/01/28 09:05:05 xiphmont Exp $
###############################################################################
# #
......@@ -28,14 +28,14 @@ RANLIB=@RANLIB@
LIBS=@LIBS@ -lm
HFILES = ../include/vorbis/codec.h ../include/vorbis/vorbisfile.h \
../include/vorbis/internal.h ../include/vorbis/backend.h \
../include/vorbis/internal.h ../include/vorbis/backends.h \
../include/vorbis/codebook.h \
bitwise.h envelope.h lpc.h lsp.h bookinternal.h misc.h\
psy.h smallft.h window.h scales.h os.h mdct.h registry.h
LFILES = framing.o mdct.o smallft.o block.o envelope.o window.o\
lsp.o lpc.o analysis.o synthesis.o psy.o info.o bitwise.o\
time0.o floor0.o res0.o mapping0.o registry.o\
spectrum.o codebook.o vorbisfile.o
codebook.o vorbisfile.o
all:
$(MAKE) target CFLAGS="$(OPT)"
......
......@@ -12,7 +12,7 @@
********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
last mod: $Id: block.c,v 1.23 2000/01/22 13:28:15 xiphmont Exp $
last mod: $Id: block.c,v 1.24 2000/01/28 09:05:06 xiphmont Exp $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
......@@ -204,11 +204,6 @@ static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi){
vi->map_param[maptype]);
}
/* finish the codebooks */
v->fullbooks=calloc(vi->books,sizeof(codebook));
for(i=0;i<vi->books;i++)
vorbis_book_finish(v->fullbooks+i,vi->book_param[i]);
/* initialize the storage vectors to a decent size greater than the
minimum */
......@@ -237,9 +232,14 @@ static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi){
/* arbitrary settings and spec-mandated numbers get filled in here */
int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
int i;
_vds_shared_init(v,vi);
/* finish the codebooks */
v->fullbooks=calloc(vi->books,sizeof(codebook));
for(i=0;i<vi->books;i++)
vorbis_book_init_encode(v->fullbooks+i,vi->book_param[i]);
/* Initialize the envelope multiplier storage */
v->envelope_storage=v->pcm_storage/vi->envelopesa;
......@@ -522,8 +522,14 @@ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
}
int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
int i;
_vds_shared_init(v,vi);
/* finish the codebooks */
v->fullbooks=calloc(vi->books,sizeof(codebook));
for(i=0;i<vi->books;i++)
vorbis_book_init_decode(v->fullbooks+i,vi->book_param[i]);
/* Adjust centerW to allow an easier mechanism for determining output */
v->pcm_returned=v->centerW;
v->centerW-= vi->blocksizes[v->W]/4+vi->blocksizes[v->lW]/4;
......
......@@ -12,7 +12,7 @@
********************************************************************
function: basic codebook pack/unpack/code/decode operations
last mod: $Id: bookinternal.h,v 1.4 2000/01/22 13:28:16 xiphmont Exp $
last mod: $Id: bookinternal.h,v 1.5 2000/01/28 09:05:07 xiphmont Exp $
********************************************************************/
......@@ -22,10 +22,13 @@
#include "vorbis/codebook.h"
#include "bitwise.h"
extern void vorbis_book_finish(codebook *dest,const static_codebook *source);
extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
extern void vorbis_staticbook_clear(static_codebook *b);
extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
extern void vorbis_book_clear(codebook *b);
extern int vorbis_book_pack(codebook *c,oggpack_buffer *b);
extern int vorbis_book_unpack(oggpack_buffer *b,codebook *c);
extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
extern int vorbis_book_encodev(codebook *book, double *a, oggpack_buffer *b);
......
......@@ -12,7 +12,7 @@
********************************************************************
function: basic codebook pack/unpack/code/decode operations
last mod: $Id: codebook.c,v 1.3 2000/01/22 13:28:17 xiphmont Exp $
last mod: $Id: codebook.c,v 1.4 2000/01/28 09:05:08 xiphmont Exp $
********************************************************************/
......@@ -33,20 +33,7 @@ static int ilog(unsigned int v){
return(ret);
}
static long _float24_pack(double val){
int sign=0;
long exp;
long mant;
if(val<0){
sign=0x800000;
val= -val;
}
exp= floor(log(val)/log(2));
mant=rint(ldexp(val,17-exp));
exp=(exp+VQ_FEXP_BIAS)<<18;
return(sign|exp|mant);
}
/* code that packs the 24 bit float can be found in vq/bookutil.c */
static double _float24_unpack(long val){
double mant=val&0x3ffff;
......@@ -121,8 +108,43 @@ long *_make_words(long *l,long n){
return(r);
}
/* 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;
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));
long *codelist=_make_words(s->lengthlist,s->entries);
if(codelist==NULL)return(NULL);
t->aux=c->entries*2;
for(i=0;i<c->entries;i++){
long ptr=0;
for(j=0;j<s->lengthlist[i]-1;j++){
int bit=(codelist[i]>>j)&1;
if(!bit){
if(!ptr0[ptr])
ptr0[ptr]= ++top;
ptr=ptr0[ptr];
}else{
if(!ptr1[ptr])
ptr1[ptr]= ++top;
ptr=ptr1[ptr];
}
}
if(!((codelist[i]>>j)&1))
ptr0[ptr]=-i;
else
ptr1[ptr]=-i;
}
free(codelist);
return(t);
}
/* unpack the quantized list of values for encode/decode ***********/
static double *_book_unquantize(static_codebook *b){
static double *_book_unquantize(const static_codebook *b){
long j,k;
double mindel=_float24_unpack(b->q_min);
double delta=_float24_unpack(b->q_delta);
......@@ -139,8 +161,23 @@ static double *_book_unquantize(static_codebook *b){
return(r);
}
void vorbis_staticbook_clear(static_codebook *b){
if(b->quantlist)free(b->quantlist);
if(b->lengthlist)free(b->lengthlist);
if(b->encode_tree){
free(b->encode_tree->ptr0);
free(b->encode_tree->ptr1);
free(b->encode_tree->p);
free(b->encode_tree->q);
memset(b->encode_tree,0,sizeof(encode_aux));
free(b->encode_tree);
}
memset(b,0,sizeof(static_codebook));
}
void vorbis_book_clear(codebook *b){
/* static book is not cleared. It exists only in encode */
/* static book is not cleared; we're likely called on the lookup and
the static codebook belongs to the info struct */
if(b->decode_tree){
free(b->decode_tree->ptr0);
free(b->decode_tree->ptr1);
......@@ -152,19 +189,33 @@ void vorbis_book_clear(codebook *b){
memset(b,0,sizeof(codebook));
}
int vorbis_book_finish(codebook *c, static_codebook *s){
int vorbis_book_init_encode(codebook *c,const static_codebook *s){
memset(c,0,sizeof(codebook));
c->c=s;
c->entries=s->entries;
c->dim=s->dim;
c->codelist=_make_words(s->lengthlist,s->entries);
c->valuelist=_book_unquantize(s);
return(0);
}
int vorbis_book_init_decode(codebook *c,const static_codebook *s){
memset(c,0,sizeof(codebook));
c->c=s;
c->elements=s->elements;
c->entries=s->entries;
c->dim=s->dim;
c->codelist=_make_words(c->lengthlist,c->entries);
c->valuelist=_book_unquantize(c);
c->valuelist=_book_unquantize(s);
c->decode_tree=_make_decode_tree(c);
if(c->decode_tree==NULL)goto err_out;
return(0);
err_out:
vorbis_book_clear(c);
return(-1);
}
/* packs the given codebook into the bitstream **************************/
int vorbis_book_pack(static_codebook *c,oggpack_buffer *opb){
int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
long i,j;
int ordered=0;
......@@ -235,45 +286,41 @@ int vorbis_book_pack(static_codebook *c,oggpack_buffer *opb){
/* unpacks a codebook from the packet buffer into the codebook struct,
readies the codebook auxiliary structures for decode *************/
int vorbis_book_unpack(oggpack_buffer *opb,codebook *c){
int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
long i,j;
long *lengthlist=NULL;
long *codelist=NULL;
static codebook s;
memset(c,0,sizeof(codebook));
memset(&s,0,sizeof(s));
memset(s,0,sizeof(static_codebook));
/* make sure alignment is correct */
if(_oggpack_read(opb,24)!=0x564342)goto _eofout;
/* first the basic parameters */
c->dim=_oggpack_read(opb,16);
c->entries=_oggpack_read(opb,24);
if(c->entries==-1)goto _eofout;
s->dim=_oggpack_read(opb,16);
s->entries=_oggpack_read(opb,24);
if(s->entries==-1)goto _eofout;
/* codeword ordering.... length ordered or unordered? */
switch(_oggpack_read(opb,1)){
case 0:
/* unordered */
lengthlist=malloc(sizeof(long)*c->entries);
for(i=0;i<c->entries;i++){
s->lengthlist=malloc(sizeof(long)*s->entries);
for(i=0;i<s->entries;i++){
long num=_oggpack_read(opb,5);
if(num==-1)goto _eofout;
lengthlist[i]=num+1;
s->lengthlist[i]=num+1;
}
break;
case 1:
/* ordered */
{
long length=_oggpack_read(opb,5)+1;
lengthlist=malloc(sizeof(long)*c->entries);
for(i=0;i<c->entries;){
long num=_oggpack_read(opb,ilog(c->entries-i));
s->lengthlist=malloc(sizeof(long)*s->entries);
for(i=0;i<s->entries;){
long num=_oggpack_read(opb,ilog(s->entries-i));
if(num==-1)goto _eofout;
for(j=0;j<num;j++,i++)
lengthlist[i]=length;
s->lengthlist[i]=length;
length++;
}
}
......@@ -283,60 +330,20 @@ int vorbis_book_unpack(oggpack_buffer *opb,codebook *c){
return(-1);
}
/* now we generate the codewords for the given lengths */
codelist=_make_words(c->lengthlist,c->entries);
if(codelist==NULL)goto _errout;
/* ...and the decode helper tree from the codewords */
{
long top=0;
decode_aux *t=c->decode_tree=malloc(sizeof(decode_aux));
long *ptr0=t->ptr0=calloc(c->entries*2,sizeof(long));
long *ptr1=t->ptr1=calloc(c->entries*2,sizeof(long));
t->aux=c->entries*2;
for(i=0;i<c->entries;i++){
long ptr=0;
for(j=0;j<lengthlist[i]-1;j++){
int bit=(codelist[i]>>j)&1;
if(!bit){
if(!ptr0[ptr])
ptr0[ptr]= ++top;
ptr=ptr0[ptr];
}else{
if(!ptr1[ptr])
ptr1[ptr]= ++top;
ptr=ptr1[ptr];
}
}
if(!((codelist[i]>>j)&1))
ptr0[ptr]=-i;
else
ptr1[ptr]=-i;
}
}
/* no longer needed */
free(lengthlist);
free(codelist);
/* Do we have a mapping to unpack? */
if(_oggpack_read(opb,1)){
/* values that define the dequantization */
s.q_min=_oggpack_read(opb,24);
s.q_delta=_oggpack_read(opb,24);
s.q_quant=_oggpack_read(opb,4)+1;
s.q_sequencep=_oggpack_read(opb,1);
s.dim=c->dim;
s.entries=c->entries;
s->q_min=_oggpack_read(opb,24);
s->q_delta=_oggpack_read(opb,24);
s->q_quant=_oggpack_read(opb,4)+1;
s->q_sequencep=_oggpack_read(opb,1);
/* quantized values */
s.quantlist=malloc(sizeof(double)*c->entries*c->dim);
for(i=0;i<c->entries*c->dim;i++)
s.quantlist[i]=_oggpack_read(opb,s.q_quant);
if(s.quantlist[i-1]==-1)goto _eofout;
c->valuelist=_book_unquantize(&s);
free(s.quantlist);memset(&s,0,sizeof(s));
s->quantlist=malloc(sizeof(double)*s->entries*s->dim);
for(i=0;i<s->entries*s->dim;i++)
s->quantlist[i]=_oggpack_read(opb,s->q_quant);
if(s->quantlist[i-1]==-1)goto _eofout;
}
/* all set */
......@@ -344,12 +351,8 @@ int vorbis_book_unpack(oggpack_buffer *opb,codebook *c){
_errout:
_eofout:
if(lengthlist)free(lengthlist);
if(s.quantlist)free(s.quantlist);
if(codelist)free(codelist);
vorbis_book_clear(c);
return(-1);
vorbis_staticbook_clear(s);
return(-1);
}
/* returns the number of bits ***************************************/
......@@ -539,6 +542,7 @@ int main(){
while(testlist[ptr]){
codebook c;
static_codebook s;
double *qv=alloca(sizeof(double)*TESTSIZE);
double *iv=alloca(sizeof(double)*TESTSIZE);
memcpy(qv,testvec[ptr],sizeof(double)*TESTSIZE);
......@@ -547,8 +551,9 @@ int main(){
/* pack the codebook, write the testvector */
_oggpack_reset(&write);
vorbis_book_finish(&c,testlist[ptr]); /* get it into memory we can write */
vorbis_book_pack(&c,&write);
vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
we can write */
vorbis_book_pack(testlist[ptr],&write);
fprintf(stderr,"Codebook size %ld bytes... ",_oggpack_bytes(&write));
for(i=0;i<TESTSIZE;i+=TESTDIM)
vorbis_book_encodev(&c,qv+i,&write);
......@@ -559,10 +564,15 @@ int main(){
/* transfer the write data to a read buffer and unpack/read */
_oggpack_readinit(&read,_oggpack_buffer(&write),_oggpack_bytes(&write));
if(vorbis_book_unpack(&read,&c)){
if(vorbis_book_unpack(&read,&s)){
fprintf(stderr,"Error unpacking codebook.\n");
exit(1);
}
if(vorbis_book_init_decode(&c,&s)){
fprintf(stderr,"Error initializing codebook.\n");
exit(1);
}
for(i=0;i<TESTSIZE;i+=TESTDIM)
if(vorbis_book_d