Chris@1: /******************************************************************** Chris@1: * * Chris@1: * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * Chris@1: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * Chris@1: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * Chris@1: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * Chris@1: * * Chris@1: * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 * Chris@1: * by the Xiph.Org Foundation http://www.xiph.org/ * Chris@1: * * Chris@1: ******************************************************************** Chris@1: Chris@1: function: utility main for setting entropy encoding parameters Chris@1: for lattice codebooks Chris@1: last mod: $Id: latticetune.c 16037 2009-05-26 21:10:58Z xiphmont $ Chris@1: Chris@1: ********************************************************************/ Chris@1: Chris@1: #include Chris@1: #include Chris@1: #include Chris@1: #include Chris@1: #include Chris@1: #include "bookutil.h" Chris@1: Chris@1: static int strrcmp_i(char *s,char *cmp){ Chris@1: return(strncmp(s+strlen(s)-strlen(cmp),cmp,strlen(cmp))); Chris@1: } Chris@1: Chris@1: /* This util takes a training-collected file listing codewords used in Chris@1: LSP fitting, then generates new codeword lengths for maximally Chris@1: efficient integer-bits entropy encoding. Chris@1: Chris@1: command line: Chris@1: latticetune book.vqh input.vqd [unused_entriesp] Chris@1: Chris@1: latticetune produces book.vqh on stdout */ Chris@1: Chris@1: int main(int argc,char *argv[]){ Chris@1: codebook *b; Chris@1: static_codebook *c; Chris@1: long *lengths; Chris@1: long *hits; Chris@1: Chris@1: int entries=-1,dim=-1,guard=1; Chris@1: FILE *in=NULL; Chris@1: char *line,*name; Chris@1: long j; Chris@1: Chris@1: if(argv[1]==NULL){ Chris@1: fprintf(stderr,"Need a lattice codebook on the command line.\n"); Chris@1: exit(1); Chris@1: } Chris@1: if(argv[2]==NULL){ Chris@1: fprintf(stderr,"Need a codeword data file on the command line.\n"); Chris@1: exit(1); Chris@1: } Chris@1: if(argv[3]!=NULL)guard=0; Chris@1: Chris@1: { Chris@1: char *ptr; Chris@1: char *filename=strdup(argv[1]); Chris@1: Chris@1: b=codebook_load(filename); Chris@1: c=(static_codebook *)(b->c); Chris@1: Chris@1: ptr=strrchr(filename,'.'); Chris@1: if(ptr){ Chris@1: *ptr='\0'; Chris@1: name=strdup(filename); Chris@1: }else{ Chris@1: name=strdup(filename); Chris@1: } Chris@1: } Chris@1: Chris@1: if(c->maptype!=1){ Chris@1: fprintf(stderr,"Provided book is not a latticebook.\n"); Chris@1: exit(1); Chris@1: } Chris@1: Chris@1: entries=b->entries; Chris@1: dim=b->dim; Chris@1: Chris@1: hits=_ogg_malloc(entries*sizeof(long)); Chris@1: lengths=_ogg_calloc(entries,sizeof(long)); Chris@1: for(j=0;jlengthlist=lengths; Chris@1: write_codebook(stdout,name,c); Chris@1: Chris@1: { Chris@1: long bins=_book_maptype1_quantvals(c); Chris@1: long i,k,base=c->lengthlist[0]; Chris@1: for(i=0;ilengthlist[i]>base)base=c->lengthlist[i]; Chris@1: Chris@1: for(j=0;jlengthlist[j]){ Chris@1: int indexdiv=1; Chris@1: fprintf(stderr,"%4ld: ",j); Chris@1: for(k=0;kdim;k++){ Chris@1: int index= (j/indexdiv)%bins; Chris@1: fprintf(stderr,"%+3.1f,", c->quantlist[index]*_float32_unpack(c->q_delta)+ Chris@1: _float32_unpack(c->q_min)); Chris@1: indexdiv*=bins; Chris@1: } Chris@1: fprintf(stderr,"\t|"); Chris@1: for(k=0;klengthlist[j];k++)fprintf(stderr,"*"); Chris@1: fprintf(stderr,"\n"); Chris@1: } Chris@1: } Chris@1: } Chris@1: Chris@1: fprintf(stderr,"\r " Chris@1: "\nDone.\n"); Chris@1: exit(0); Chris@1: }