cascade.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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: function call to do simple data cascading
  13. last mod: $Id$
  14. ********************************************************************/
  15. /* this one outputs residue to stdout. */
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. #include <math.h>
  19. #include "bookutil.h"
  20. /* set up metrics */
  21. float count=0.f;
  22. void process_preprocess(codebook **bs,char *basename){
  23. }
  24. void process_postprocess(codebook **b,char *basename){
  25. fprintf(stderr,"Done. \n");
  26. }
  27. float process_one(codebook *b,float *a,int dim,int step,int addmul,
  28. float base){
  29. int j;
  30. if(b->c->q_sequencep){
  31. float temp;
  32. for(j=0;j<dim;j++){
  33. temp=a[j*step];
  34. a[j*step]-=base;
  35. }
  36. base=temp;
  37. }
  38. vorbis_book_besterror(b,a,step,addmul);
  39. return base;
  40. }
  41. void process_vector(codebook **bs,int *addmul,int inter,float *a,int n){
  42. int i,bi=0;
  43. int booknum=0;
  44. while(*bs){
  45. float base=0.f;
  46. codebook *b=*bs;
  47. int dim=b->dim;
  48. if(inter){
  49. for(i=0;i<n/dim;i++)
  50. base=process_one(b,a+i,dim,n/dim,addmul[bi],base);
  51. }else{
  52. for(i=0;i<=n-dim;i+=dim)
  53. base=process_one(b,a+i,dim,1,addmul[bi],base);
  54. }
  55. bs++;
  56. booknum++;
  57. bi++;
  58. }
  59. for(i=0;i<n;i++)
  60. fprintf(stdout,"%f, ",a[i]);
  61. fprintf(stdout,"\n");
  62. if((long)(count++)%100)spinnit("working.... lines: ",count);
  63. }
  64. void process_usage(void){
  65. fprintf(stderr,
  66. "usage: vqcascade [-i] +|*<codebook>.vqh [ +|*<codebook.vqh> ]... \n"
  67. " datafile.vqd [datafile.vqd]...\n\n"
  68. " data can be taken on stdin. residual error data sent to\n"
  69. " stdout.\n\n");
  70. }