genericdata.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: generic euclidian distance metric for VQ codebooks
  13. last mod: $Id$
  14. ********************************************************************/
  15. #include <stdlib.h>
  16. #include <math.h>
  17. #include <stdio.h>
  18. #include "vqgen.h"
  19. #include "vqext.h"
  20. char *vqext_booktype="GENERICdata";
  21. int vqext_aux=0;
  22. quant_meta q={0,0,0,0}; /* non sequence data; each scalar
  23. independent */
  24. void vqext_quantize(vqgen *v,quant_meta *q){
  25. vqgen_quantize(v,q);
  26. }
  27. float *vqext_weight(vqgen *v,float *p){
  28. /*noop*/
  29. return(p);
  30. }
  31. /* candidate,actual */
  32. float vqext_metric(vqgen *v,float *e, float *p){
  33. int i;
  34. float acc=0.f;
  35. for(i=0;i<v->elements;i++){
  36. float val=p[i]-e[i];
  37. acc+=val*val;
  38. }
  39. return sqrt(acc/v->elements);
  40. }
  41. void vqext_addpoint_adj(vqgen *v,float *b,int start,int dim,int cols,int num){
  42. vqgen_addpoint(v,b+start,NULL);
  43. }
  44. void vqext_preprocess(vqgen *v){
  45. /* noop */
  46. }