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/latticetune.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 vq/latticetune.c (limited to 'vq/latticetune.c') diff --git a/vq/latticetune.c b/vq/latticetune.c new file mode 100644 index 0000000..193d4d1 --- /dev/null +++ b/vq/latticetune.c @@ -0,0 +1,163 @@ +/******************************************************************** + * * + * 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 setting entropy encoding parameters + for lattice codebooks + + ********************************************************************/ + +#include +#include +#include +#include +#include +#include "bookutil.h" + +static int strrcmp_i(char *s,char *cmp){ + return(strncmp(s+strlen(s)-strlen(cmp),cmp,strlen(cmp))); +} + +/* This util takes a training-collected file listing codewords used in + LSP fitting, then generates new codeword lengths for maximally + efficient integer-bits entropy encoding. + + command line: + latticetune book.vqh input.vqd [unused_entriesp] + + latticetune produces book.vqh on stdout */ + +int main(int argc,char *argv[]){ + codebook *b; + static_codebook *c; + long *lengths; + long *hits; + + int entries=-1,dim=-1,guard=1; + FILE *in=NULL; + char *line,*name; + long j; + + if(argv[1]==NULL){ + fprintf(stderr,"Need a lattice codebook on the command line.\n"); + exit(1); + } + if(argv[2]==NULL){ + fprintf(stderr,"Need a codeword data file on the command line.\n"); + exit(1); + } + if(argv[3]!=NULL)guard=0; + + { + char *ptr; + char *filename=strdup(argv[1]); + + b=codebook_load(filename); + c=(static_codebook *)(b->c); + + ptr=strrchr(filename,'.'); + if(ptr){ + *ptr='\0'; + name=strdup(filename); + }else{ + name=strdup(filename); + } + } + + if(c->maptype!=1){ + fprintf(stderr,"Provided book is not a latticebook.\n"); + exit(1); + } + + entries=b->entries; + dim=b->dim; + + hits=_ogg_malloc(entries*sizeof(long)); + lengths=_ogg_calloc(entries,sizeof(long)); + for(j=0;jlengthlist=lengths; + write_codebook(stdout,name,c); + + { + long bins=_book_maptype1_quantvals(c); + long i,k,base=c->lengthlist[0]; + for(i=0;ilengthlist[i]>base)base=c->lengthlist[i]; + + for(j=0;jlengthlist[j]){ + int indexdiv=1; + fprintf(stderr,"%4ld: ",j); + for(k=0;kdim;k++){ + int index= (j/indexdiv)%bins; + fprintf(stderr,"%+3.1f,", c->quantlist[index]*_float32_unpack(c->q_delta)+ + _float32_unpack(c->q_min)); + indexdiv*=bins; + } + fprintf(stderr,"\t|"); + for(k=0;klengthlist[j];k++)fprintf(stderr,"*"); + fprintf(stderr,"\n"); + } + } + } + + fprintf(stderr,"\r " + "\nDone.\n"); + exit(0); +} -- cgit v1.1