/********************************************************************
* *
- * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
- * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
- * PLEASE READ THESE TERMS DISTRIBUTING. *
+ * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
+ * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
- * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
- * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
- * http://www.xiph.org/ *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
+ * by the XIPHOPHORUS Company http://www.xiph.org/ *
* *
********************************************************************
function: utility main for setting entropy encoding parameters
for lattice codebooks
- last mod: $Id: latticetune.c,v 1.1 2000/07/17 12:55:37 xiphmont Exp $
+ last mod: $Id: latticetune.c,v 1.6 2001/02/02 03:52:27 xiphmont Exp $
********************************************************************/
#include <math.h>
#include <string.h>
#include <errno.h>
-#include "vorbis/codebook.h"
-#include "../lib/sharedbook.h"
#include "bookutil.h"
+static char *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.
entries=b->entries;
dim=b->dim;
- hits=malloc(entries*sizeof(long));
- lengths=calloc(entries,sizeof(long));
+ hits=_ogg_malloc(entries*sizeof(long));
+ lengths=_ogg_calloc(entries,sizeof(long));
for(j=0;j<entries;j++)hits[j]=guard;
in=fopen(argv[2],"r");
exit(1);
}
- {
+ if(!strrcmp_i(argv[0],"latticetune")){
long lines=0;
line=setup_line(in);
while(line){
line=setup_line(in);
}
}
+
+ if(!strrcmp_i(argv[0],"restune")){
+ long step;
+ long lines=0;
+ long cols=-1;
+ float *vec;
+ line=setup_line(in);
+ while(line){
+ int code;
+ if(!(lines&0xfff))spinnit("codewords so far...",lines);
+
+ if(cols==-1){
+ char *temp=line;
+ while(*temp==' ')temp++;
+ for(cols=0;*temp;cols++){
+ while(*temp>32)temp++;
+ while(*temp==' ')temp++;
+ }
+ vec=alloca(sizeof(float)*cols);
+ step=cols/dim;
+ }
+
+ for(j=0;j<cols;j++)
+ if(get_line_value(in,vec+j)){
+ fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
+ exit(1);
+ }
+
+ for(j=0;j<step;j++){
+ lines++;
+ code=_best(b,vec+j,step);
+ hits[code]++;
+ }
+
+ line=setup_line(in);
+ }
+ }
+
fclose(in);
/* build the codeword lengths */