window.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  5. * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
  6. * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis 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,v 1.8.2.2 2000/11/04 06:43:51 xiphmont Exp $
  15. ********************************************************************/
  16. #include <stdlib.h>
  17. #include <math.h>
  18. #include "os.h"
  19. #include "misc.h"
  20. float *_vorbis_window(int type, int window,int left,int right){
  21. float *ret=_ogg_calloc(window,sizeof(float));
  22. switch(type){
  23. case 0:
  24. /* The 'vorbis window' (window 0) is sin(sin(x)*sin(x)*2pi) */
  25. {
  26. int leftbegin=window/4-left/2;
  27. int rightbegin=window-window/4-right/2;
  28. int i;
  29. for(i=0;i<left;i++){
  30. float x=(i+.5)/left*M_PI/2.;
  31. x=sin(x);
  32. x*=x;
  33. x*=M_PI/2.;
  34. x=sin(x);
  35. ret[i+leftbegin]=x;
  36. }
  37. for(i=leftbegin+left;i<rightbegin;i++)
  38. ret[i]=1.;
  39. for(i=0;i<right;i++){
  40. float x=(right-i-.5)/right*M_PI/2.;
  41. x=sin(x);
  42. x*=x;
  43. x*=M_PI/2.;
  44. x=sin(x);
  45. ret[i+rightbegin]=x;
  46. }
  47. }
  48. break;
  49. default:
  50. free(ret);
  51. return(NULL);
  52. }
  53. return(ret);
  54. }