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: metrics and quantization code for LSP VQ codebooks
15 last mod: $Id: lspdata.c,v 1.8 2000/01/05 15:04:58 xiphmont Exp $
17 ********************************************************************/
25 char *vqext_booktype="LSPdata";
26 quant_meta q={0,0,0,1}; /* set sequence data */
29 /* LSP training metric. We weight error proportional to distance
30 *between* LSP vector values. The idea of this metric is not to set
31 final cells, but get the midpoint spacing into a form conducive to
32 what we want, which is weighting toward preserving narrower
35 double global_maxdel=M_PI;
36 #define FUDGE (global_maxdel-weight[i])
39 double *vqext_weight(vqgen *v,double *p){
44 double predist=(p[i]-lastp);
45 double postdist=(p[i+1]-p[i]);
46 weight[i]=(predist<postdist?predist:postdist);
52 /* candidate,actual */
53 double vqext_metric(vqgen *v,double *e, double *p){
58 double val=(p[i]-e[i])*FUDGE;
61 return sqrt(acc/v->elements);
64 /* Data files are line-vectors, starting with zero. If we want to
65 train on a subvector starting in the middle, we need to adjust the
66 data as if it was starting at zero. we also need to add the 'aux'
67 value, which is an extra point at the end so we have leading and
70 /* assume vqext_aux==1 */
71 void vqext_addpoint_adj(vqgen *v,double *b,int start,int dim,int cols){
72 double *a=alloca(sizeof(double)*(dim+1)); /* +aux */
76 if(start>0)base=b[start-1];
77 for(i=0;i<dim;i++)a[i]=b[i+start]-base;
78 if(start+dim+1>cols) /* +aux */
83 vqgen_addpoint(v,a,a+dim);
86 /* we just need to calc the global_maxdel from the training set */
87 void vqext_preprocess(vqgen *v){
91 for(j=0;j<v->points;j++){
93 for(k=0;k<v->elements+v->aux;k++){
94 double p=_point(v,j)[k];
95 if(p-last>global_maxdel)global_maxdel=p-last;
101 weight=malloc(sizeof(double)*v->elements);