From 74f4b1bc3b627ba4c7e03498234d88cacdfbe97b Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 29 Sep 2021 22:52:49 +0200 Subject: Squashed 'vorbis/' content from commit d22c3ab5f git-subtree-dir: vorbis git-subtree-split: d22c3ab5f633460abc2532feee60ca0892134cbf --- vq/latticebuild.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 vq/latticebuild.c (limited to 'vq/latticebuild.c') diff --git a/vq/latticebuild.c b/vq/latticebuild.c new file mode 100644 index 0000000..acfe9ff --- /dev/null +++ b/vq/latticebuild.c @@ -0,0 +1,176 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 * + * by the Xiph.Org Foundation http://www.xiph.org/ * + * * + ******************************************************************** + + function: utility main for building codebooks from lattice descriptions + + ********************************************************************/ + +#include +#include +#include +#include +#include +#include "bookutil.h" + +/* The purpose of this util is just to finish packaging the + description into a static codebook. It used to count hits for a + histogram, but I've divorced that out to add some flexibility (it + currently generates an equal probability codebook) + + command line: + latticebuild description.vql + + the lattice description file contains two lines: + + + ... + + a threshmap (or pigeonmap) struct is generated by latticehint; + there are fun tricks one can do with the threshmap and cascades, + but the utils don't know them... + + entropy encoding is done by feeding an entry list collected from a + training set and feeding it to latticetune along with the book. + + latticebuild produces a codebook on stdout */ + +static int ilog(unsigned int v){ + int ret=0; + while(v){ + ret++; + v>>=1; + } + return(ret); +} + +int main(int argc,char *argv[]){ + codebook b; + static_codebook c; + double *quantlist; + long *hits; + + int entries=-1,dim=-1,quantvals=-1,addmul=-1,sequencep=0; + FILE *in=NULL; + char *line,*name; + long i,j; + + memset(&b,0,sizeof(b)); + memset(&c,0,sizeof(c)); + + if(argv[1]==NULL){ + fprintf(stderr,"Need a lattice description file on the command line.\n"); + exit(1); + } + + { + char *ptr; + char *filename=_ogg_calloc(strlen(argv[1])+4,1); + + strcpy(filename,argv[1]); + in=fopen(filename,"r"); + if(!in){ + fprintf(stderr,"Could not open input file %s\n",filename); + exit(1); + } + + ptr=strrchr(filename,'.'); + if(ptr){ + *ptr='\0'; + name=strdup(filename); + }else{ + name=strdup(filename); + } + + } + + /* read the description */ + line=get_line(in); + if(sscanf(line,"%d %d %d %d",&quantvals,&dim,&addmul,&sequencep)!=4){ + if(sscanf(line,"%d %d %d",&quantvals,&dim,&addmul)!=3){ + fprintf(stderr,"Syntax error reading description file (line 1)\n"); + exit(1); + } + } + entries=pow(quantvals,dim); + c.dim=dim; + c.entries=entries; + c.lengthlist=_ogg_malloc(entries*sizeof(long)); + c.maptype=1; + c.q_sequencep=sequencep; + c.quantlist=_ogg_calloc(quantvals,sizeof(long)); + + quantlist=_ogg_malloc(sizeof(double)*c.dim*c.entries); + hits=_ogg_malloc(c.entries*sizeof(long)); + for(j=0;j.00001f) break; + } + if(fac>100)break; + if(jc.q_quant)c.q_quant=ilog(c.quantlist[j]); + } + } + + /* build the [default] codeword lengths */ + memset(c.lengthlist,0,sizeof(long)*entries); + for(i=0;i