/tags/rel-0-6-0/FreeSpeech/audio_blocks/src/window.c

# · C · 66 lines · 37 code · 8 blank · 21 comment · 4 complexity · d61e4662ef16e65edf2d952cf03b395e MD5 · raw file

  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: window functions
  14. last mod: $Id: window.c 1439 2001-08-01 16:26:54Z jmvalin $
  15. ********************************************************************/
  16. #include <stdlib.h>
  17. #include <math.h>
  18. #include "window.h"
  19. //#include "os.h"
  20. //#include "misc.h"
  21. //@implements MDCT
  22. double *_vorbis_window(int type, int window,int left,int right){
  23. double *ret=calloc(window,sizeof(double));
  24. switch(type){
  25. case 0:
  26. /* The 'vorbis window' (window 0) is sin(sin(x)*sin(x)*2pi) */
  27. {
  28. int leftbegin=window/4-left/2;
  29. int rightbegin=window-window/4-right/2;
  30. int i;
  31. for(i=0;i<left;i++){
  32. double x=(i+.5)/left*M_PI/2.;
  33. x=sin(x);
  34. x*=x;
  35. x*=M_PI/2.;
  36. x=sin(x);
  37. ret[i+leftbegin]=x;
  38. }
  39. for(i=leftbegin+left;i<rightbegin;i++)
  40. ret[i]=1.;
  41. for(i=0;i<right;i++){
  42. double x=(right-i-.5)/right*M_PI/2.;
  43. x=sin(x);
  44. x*=x;
  45. x*=M_PI/2.;
  46. x=sin(x);
  47. ret[i+rightbegin]=x;
  48. }
  49. }
  50. break;
  51. default:
  52. free(ret);
  53. return(NULL);
  54. }
  55. return(ret);
  56. }