cascade.c 2.5 KB

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