/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
- * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
- * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * 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-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 Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: function calls to collect codebook metrics
- last mod: $Id: metrics.c,v 1.10 2000/11/06 00:07:26 xiphmont Exp $
+ last mod: $Id$
********************************************************************/
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
-#include "vorbis/codebook.h"
-#include "../lib/sharedbook.h"
#include "bookutil.h"
/* collect the following metrics:
/* set up metrics */
-float meanamplitude_acc=0.;
-float meanamplitudesq_acc=0.;
-float meanerror_acc=0.;
-float meanerrorsq_acc=0.;
+float meanamplitude_acc=0.f;
+float meanamplitudesq_acc=0.f;
+float meanerror_acc=0.f;
+float meanerrorsq_acc=0.f;
float **histogram=NULL;
float **histogram_error=NULL;
float **histogram_errorsq=NULL;
float **histogram_hi=NULL;
float **histogram_lo=NULL;
-float bits=0.;
-float count=0.;
+float bits=0.f;
+float count=0.f;
static float *_now(codebook *c, int i){
return c->valuelist+i*c->c->dim;
static float _dist(int el,float *a, float *b){
int i;
- float acc=0.;
+ float acc=0.f;
for(i=0;i<el;i++){
float val=(a[i]-b[i]);
acc+=val*val;
void cell_spacing(codebook *c){
int j,k;
- float min=-1,max=-1,mean=0.,meansq=0.;
+ float min=-1.f,max=-1.f,mean=0.f,meansq=0.f;
long total=0;
/* minimum, maximum, mean, ms cell spacing */
if(c->c->lengthlist[j]>0){
float localmin=-1.;
for(k=0;k<c->c->entries;k++){
- if(c->c->lengthlist[k]>0){
- float this=_dist(c->c->dim,_now(c,j),_now(c,k));
- if(j!=k &&
- (localmin==-1 || this<localmin))
- localmin=this;
- }
+ if(c->c->lengthlist[k]>0){
+ float this=_dist(c->c->dim,_now(c,j),_now(c,k));
+ if(j!=k &&
+ (localmin==-1 || this<localmin))
+ localmin=this;
+ }
}
if(min==-1 || localmin<min)min=localmin;
char *buffer=alloca(strlen(basename)+80);
fprintf(stderr,"Done. Processed %ld data points:\n\n",
- (long)count);
+ (long)count);
fprintf(stderr,"Global statistics:******************\n\n");
fprintf(stderr,"\taverage bits per sample: %g\n\n",bits/count);
fprintf(stderr,"\tmean sample amplitude: %g\n",
- meanamplitude_acc/count);
+ meanamplitude_acc/count);
fprintf(stderr,"\tmean squared sample amplitude: %g\n\n",
- sqrt(meanamplitudesq_acc/count));
+ sqrt(meanamplitudesq_acc/count));
fprintf(stderr,"\tmean code error: %g\n",
- meanerror_acc/count);
+ meanerror_acc/count);
fprintf(stderr,"\tmean squared code error: %g\n\n",
- sqrt(meanerrorsq_acc/count));
+ sqrt(meanerrorsq_acc/count));
for(book=0;book<books;book++){
FILE *out;
for(i=0;i<n;i++){
for(k=0;k<dim;k++){
- fprintf(out,"%d, %g, %g\n",
- i*dim+k,(b->valuelist+i*dim)[k],
- sqrt((histogram_errorsq[book]+i*dim)[k]/histogram[book][i]));
+ fprintf(out,"%d, %g, %g\n",
+ i*dim+k,(b->valuelist+i*dim)[k],
+ sqrt((histogram_errorsq[book]+i*dim)[k]/histogram[book][i]));
}
}
fclose(out);
for(i=0;i<n;i++){
for(k=0;k<dim;k++){
- fprintf(out,"%d, %g, %g\n",
- i*dim+k,(b->valuelist+i*dim)[k],
- (histogram_error[book]+i*dim)[k]/histogram[book][i]);
+ fprintf(out,"%d, %g, %g\n",
+ i*dim+k,(b->valuelist+i*dim)[k],
+ (histogram_error[book]+i*dim)[k]/histogram[book][i]);
}
}
fclose(out);
for(i=0;i<n;i++){
for(k=0;k<dim;k++){
- fprintf(out,"%d, %g, %g, %g\n",
- i*dim+k,(b->valuelist+i*dim)[k],
- (b->valuelist+i*dim)[k]+(histogram_lo[book]+i*dim)[k],
- (b->valuelist+i*dim)[k]+(histogram_hi[book]+i*dim)[k]);
+ fprintf(out,"%d, %g, %g, %g\n",
+ i*dim+k,(b->valuelist+i*dim)[k],
+ (b->valuelist+i*dim)[k]+(histogram_lo[book]+i*dim)[k],
+ (b->valuelist+i*dim)[k]+(histogram_hi[book]+i*dim)[k]);
}
}
fclose(out);
}
float process_one(codebook *b,int book,float *a,int dim,int step,int addmul,
- float base){
+ float base){
int j,entry;
- float amplitude=0.;
+ float amplitude=0.f;
if(book==0){
float last=base;
histogram[book][entry]++;
bits+=vorbis_book_codelen(b,entry);
-
+
for(j=0;j<dim;j++){
float error=a[j*step];
for(bi=0;bi<books;bi++){
codebook *b=bs[bi];
int dim=b->dim;
- float base=0.;
+ float base=0.f;
if(inter){
for(i=0;i<n/dim;i++)
- base=process_one(b,bi,a+i,dim,n/dim,addmul[bi],base);
+ base=process_one(b,bi,a+i,dim,n/dim,addmul[bi],base);
}else{
for(i=0;i<=n-dim;i+=dim)
- base=process_one(b,bi,a+i,dim,1,addmul[bi],base);
+ base=process_one(b,bi,a+i,dim,1,addmul[bi],base);
}
}
void process_usage(void){
fprintf(stderr,
- "usage: vqmetrics [-i] +|*<codebook>.vqh [ +|*<codebook.vqh> ]... \n"
- " datafile.vqd [datafile.vqd]...\n\n"
- " data can be taken on stdin. -i indicates interleaved coding.\n"
- " Output goes to output files:\n"
- " basename-me.m: gnuplot: mean error by entry value\n"
- " basename-mse.m: gnuplot: mean square error by entry value\n"
- " basename-worst.m: gnuplot: worst error by entry value\n"
- " basename-distance.m: gnuplot file showing distance probability\n"
- "\n");
+ "usage: vqmetrics [-i] +|*<codebook>.vqh [ +|*<codebook.vqh> ]... \n"
+ " datafile.vqd [datafile.vqd]...\n\n"
+ " data can be taken on stdin. -i indicates interleaved coding.\n"
+ " Output goes to output files:\n"
+ " basename-me.m: gnuplot: mean error by entry value\n"
+ " basename-mse.m: gnuplot: mean square error by entry value\n"
+ " basename-worst.m: gnuplot: worst error by entry value\n"
+ " basename-distance.m: gnuplot file showing distance probability\n"
+ "\n");
}