util.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. last mod: $Id: util.c 13293 2007-07-24 00:09:47Z erikd $
  14. ********************************************************************/
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <math.h>
  18. #include <string.h>
  19. #include <errno.h>
  20. #include <vorbis/codec.h>
  21. #include <vorbis/vorbisenc.h>
  22. #include "util.h"
  23. void
  24. gen_windowed_sine (float *data, int len, float maximum)
  25. { int k ;
  26. memset (data, 0, len * sizeof (float)) ;
  27. len /= 2 ;
  28. for (k = 0 ; k < len ; k++)
  29. { data [k] = sin (2.0 * k * M_PI * 1.0 / 32.0 + 0.4) ;
  30. /* Apply Hanning Window. */
  31. data [k] *= maximum * (0.5 - 0.5 * cos (2.0 * M_PI * k / ((len) - 1))) ;
  32. }
  33. return ;
  34. }
  35. void
  36. set_data_in (float * data, unsigned len, float value)
  37. { unsigned k ;
  38. for (k = 0 ; k < len ; k++)
  39. data [k] = value ;
  40. }