********************************************************************
function: utility functions for loading .vqh and .vqd files
- last mod: $Id: bookutil.c,v 1.3 2000/01/06 13:57:10 xiphmont Exp $
+ last mod: $Id: bookutil.c,v 1.4 2000/01/10 10:42:01 xiphmont Exp $
********************************************************************/
{
long c=fgetc(in);
switch(c){
- case '\n':
case EOF:
+ if(sofar==0)return(NULL);
+ /* fallthrough correct */
+ case '\n':
linebuffer[sofar]='\0';
gotline=1;
break;
}
static double sequence_base=0.;
+static int v_sofar=0;
void reset_next_value(void){
value_line_buff=NULL;
sequence_base=0.;
+ v_sofar=0;
}
-int get_vector(codebook *b,FILE *in,double *a){
+int get_vector(codebook *b,FILE *in,int start, int n,double *a){
int i;
while(1){
- if(get_line_value(in,a)){
- sequence_base=0.;
+ if(v_sofar==n || get_line_value(in,a)){
+ reset_next_value();
if(get_next_value(in,a))
break;
+ for(i=0;i<start;i++){
+ sequence_base=*a;
+ get_line_value(in,a);
+ }
}
for(i=1;i<b->dim;i++)
double temp=a[b->dim-1];
for(i=0;i<b->dim;i++)a[i]-=sequence_base;
if(b->q_sequencep)sequence_base=temp;
+ v_sofar++;
return(0);
}
sequence_base=0.;
if(sscanf(line,"%ld, %ld, %ld, %ld, %d, %d",
&(b->dim),&(b->entries),&(b->q_min),&(b->q_delta),&(b->q_quant),
&(b->q_sequencep))!=6){
- fprintf(stderr,"syntax in %s in line:\t %s",filename,line);
+ fprintf(stderr,"1: syntax in %s in line:\t %s",filename,line);
exit(1);
}
line=get_line(in);
line=get_line(in);
if(sscanf(line,"%ld, %ld",&(a->aux),&(a->alloc))!=2){
- fprintf(stderr,"syntax in %s in line:\t %s",filename,line);
+ fprintf(stderr,"2: syntax in %s in line:\t %s",filename,line);
exit(1);
}
********************************************************************
function: utility functions for loading .vqh and .vqd files
- last mod: $Id: bookutil.h,v 1.2 2000/01/06 13:57:11 xiphmont Exp $
+ last mod: $Id: bookutil.h,v 1.3 2000/01/10 10:42:02 xiphmont Exp $
********************************************************************/
extern int get_next_value(FILE *in,double *value);
extern int get_next_ivalue(FILE *in,long *ivalue);
extern void reset_next_value(void);
-extern int get_vector(codebook *b,FILE *in,double *a);
+extern int get_vector(codebook *b,FILE *in,int start,int num,double *a);
extern char *find_seek_to(FILE *in,char *s);
extern codebook *codebook_load(char *filename);
********************************************************************
function: metrics and quantization code for LSP VQ codebooks
- last mod: $Id: lspdata.c,v 1.8 2000/01/05 15:04:58 xiphmont Exp $
+ last mod: $Id: lspdata.c,v 1.9 2000/01/10 10:42:03 xiphmont Exp $
********************************************************************/
if(start>0)base=b[start-1];
for(i=0;i<dim;i++)a[i]=b[i+start]-base;
if(start+dim+1>cols) /* +aux */
- a[i]=M_PI-base;
+ a[i]=a[i-1];
else
a[i]=b[i+start]-base;
********************************************************************
function: function calls to collect codebook metrics
- last mod: $Id: metrics.c,v 1.2 2000/01/07 12:11:31 xiphmont Exp $
+ last mod: $Id: metrics.c,v 1.3 2000/01/10 10:42:04 xiphmont Exp $
********************************************************************/
for(k=0;k<bb->dim;k++){
fprintf(out,"%ld, %g, %g\n",
i*bb->dim+k,(bb->valuelist+i*bb->dim)[k],
- sqrt((histogram_error+i*bb->dim)[k]/histogram[i]));
+ (histogram_error+i*bb->dim)[k]/histogram[i]);
}
}
fclose(out);
********************************************************************
function: utility main for loading and operating on codebooks
- last mod: $Id: run.c,v 1.6 2000/01/07 12:11:33 xiphmont Exp $
+ last mod: $Id: run.c,v 1.7 2000/01/10 10:42:05 xiphmont Exp $
********************************************************************/
codebook **b=calloc(1,sizeof(codebook *));
int books=0;
int input=0;
+
+ int start=0;
+ int num=-1;
argv++;
if(*argv==NULL){
while(*argv){
if(*argv[0]=='-'){
/* option */
-
-
-
+ if(argv[0][1]=='s'){
+ /* subvector */
+ if(sscanf(argv[1],"%d,%d",&start,&num)!=2){
+ num= -1;
+ if(sscanf(argv[1],"%d",&start)!=1){
+ fprintf(stderr,"Syntax error using -s\n");
+ exit(1);
+ }
+ }
+ argv+=2;
+ }
}else{
/* input file. What kind? */
char *dot;
reset_next_value();
- while(get_vector(*b,in,a)!=-1)
+ while(get_vector(*b,in,start,num,a)!=-1)
process_vector(b,a);
fclose(in);
}
reset_next_value();
- while(get_vector(*b,stdin,a)!=-1)
+ while(get_vector(*b,stdin,start,num,a)!=-1)
process_vector(b,a);
}
}
********************************************************************
function: utility main for training codebooks
- last mod: $Id: train.c,v 1.13 2000/01/05 15:05:00 xiphmont Exp $
+ last mod: $Id: train.c,v 1.14 2000/01/10 10:42:06 xiphmont Exp $
********************************************************************/
{
int i;
double b[cols];
- if(start*num+dim>cols){
+ if(start+num*dim>cols){
fprintf(stderr,"ran out of columns reading %s\n",file);
exit(1);
}
********************************************************************
function: build a VQ codebook and the encoding decision 'tree'
- last mod: $Id: vqsplit.c,v 1.11 2000/01/06 13:57:15 xiphmont Exp $
+ last mod: $Id: vqsplit.c,v 1.12 2000/01/10 10:42:07 xiphmont Exp $
********************************************************************/
void vqsp_book(vqgen *v, codebook *b, long *quantlist){
long *entryindex=malloc(sizeof(long)*v->entries);
long *pointindex=malloc(sizeof(long)*v->points);
- long *membership=malloc(sizeof(long)*v->points);
long i,j;
encode_aux *t;
t->p=malloc(sizeof(long)*t->alloc);
t->q=malloc(sizeof(long)*t->alloc);
- /* which cells do points belong to? Only do this once. */
-
- for(i=0;i<v->points;i++){
- double *ppt=_point(v,i);
- long firstentry=0;
- double firstmetric=_dist(v,_now(v,0),ppt);
-
- for(j=1;j<v->entries;j++){
- double thismetric=_dist(v,_now(v,j),ppt);
- if(thismetric<firstmetric){
- firstmetric=thismetric;
- firstentry=j;
- }
- }
-
- membership[i]=firstentry;
- }
-
-
/* first, generate the encoding decision heirarchy */
{
long pointsofar=0;