1 /********************************************************************
3 * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS DISTRIBUTING. *
8 * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
9 * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: utility main for setting entropy encoding parameters
16 last mod: $Id: latticetune.c,v 1.3 2000/10/12 03:13:02 xiphmont Exp $
18 ********************************************************************/
25 #include "vorbis/codebook.h"
26 #include "../lib/sharedbook.h"
29 /* This util takes a training-collected file listing codewords used in
30 LSP fitting, then generates new codeword lengths for maximally
31 efficient integer-bits entropy encoding.
34 latticetune book.vqh input.vqd [unused_entriesp]
36 latticetune produces book.vqh on stdout */
38 int main(int argc,char *argv[]){
44 int entries=-1,dim=-1,guard=1;
50 fprintf(stderr,"Need a lattice codebook on the command line.\n");
54 fprintf(stderr,"Need a codeword data file on the command line.\n");
57 if(argv[3]!=NULL)guard=0;
61 char *filename=strdup(argv[1]);
63 b=codebook_load(filename);
64 c=(static_codebook *)(b->c);
66 ptr=strrchr(filename,'.');
69 name=strdup(filename);
71 name=strdup(filename);
76 fprintf(stderr,"Provided book is not a latticebook.\n");
83 hits=malloc(entries*sizeof(long));
84 lengths=calloc(entries,sizeof(long));
85 for(j=0;j<entries;j++)hits[j]=guard;
87 in=fopen(argv[2],"r");
89 fprintf(stderr,"Could not open input file %s\n",argv[2]);
93 if(!strcmp(argv[0],"latticetune")){
99 if(!(lines&0xfff))spinnit("codewords so far...",lines);
101 if(sscanf(line,"%ld",&code)==1)
108 if(!strcmp(argv[0],"restune")){
116 if(!(lines&0xfff))spinnit("codewords so far...",lines);
120 while(*temp==' ')temp++;
121 for(cols=0;*temp;cols++){
122 while(*temp>32)temp++;
123 while(*temp==' ')temp++;
125 vec=alloca(sizeof(float)*cols);
130 if(get_line_value(in,vec+j)){
131 fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
137 code=_best(b,vec+j,step);
147 /* build the codeword lengths */
148 build_tree_from_lengths0(entries,hits,lengths);
150 c->lengthlist=lengths;
151 write_codebook(stdout,name,c);