genericdata.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /********************************************************************
  2. * *
  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. *
  7. * *
  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/ *
  11. * *
  12. ********************************************************************
  13. function: generic euclidian distance metric for VQ codebooks
  14. last mod: $Id: genericdata.c,v 1.5.8.1 2000/08/31 09:00:02 xiphmont Exp $
  15. ********************************************************************/
  16. #include <stdlib.h>
  17. #include <math.h>
  18. #include <stdio.h>
  19. #include "vqgen.h"
  20. #include "vqext.h"
  21. char *vqext_booktype="GENERICdata";
  22. int vqext_aux=0;
  23. quant_meta q={0,0,0,0}; /* non sequence data; each scalar
  24. independent */
  25. void vqext_quantize(vqgen *v,quant_meta *q){
  26. vqgen_quantize(v,q);
  27. }
  28. float *vqext_weight(vqgen *v,float *p){
  29. /*noop*/
  30. return(p);
  31. }
  32. /* candidate,actual */
  33. float vqext_metric(vqgen *v,float *e, float *p){
  34. int i;
  35. float acc=0.;
  36. for(i=0;i<v->elements;i++){
  37. float val=p[i]-e[i];
  38. acc+=val*val;
  39. }
  40. return sqrt(acc/v->elements);
  41. }
  42. void vqext_addpoint_adj(vqgen *v,float *b,int start,int dim,int cols,int num){
  43. vqgen_addpoint(v,b+start,NULL);
  44. }
  45. void vqext_preprocess(vqgen *v){
  46. /* noop */
  47. }