util.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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-2007 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: utility functions for vorbis codec test suite.
  13. ********************************************************************/
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <math.h>
  17. #include <string.h>
  18. #include <errno.h>
  19. #include <vorbis/codec.h>
  20. #include <vorbis/vorbisenc.h>
  21. #include "util.h"
  22. void
  23. gen_windowed_sine (float *data, int len, float maximum)
  24. { int k ;
  25. memset (data, 0, len * sizeof (float)) ;
  26. len /= 2 ;
  27. for (k = 0 ; k < len ; k++)
  28. { data [k] = sin (2.0 * k * M_PI * 1.0 / 32.0 + 0.4) ;
  29. /* Apply Hanning Window. */
  30. data [k] *= maximum * (0.5 - 0.5 * cos (2.0 * M_PI * k / ((len) - 1))) ;
  31. }
  32. return ;
  33. }
  34. void
  35. set_data_in (float * data, unsigned len, float value)
  36. { unsigned k ;
  37. for (k = 0 ; k < len ; k++)
  38. data [k] = value ;
  39. }