test.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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: vorbis coded test suite using vorbisfile
  13. last mod: $Id: test.c 13293 2007-07-24 00:09:47Z erikd $
  14. ********************************************************************/
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <math.h>
  18. #include "util.h"
  19. #include "write_read.h"
  20. #define DATA_LEN 2048
  21. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  22. static int check_output (const float * data_in, unsigned len);
  23. int
  24. main(void){
  25. static float data_out [DATA_LEN] ;
  26. static float data_in [DATA_LEN] ;
  27. /* Do safest and most used sample rates first. */
  28. int sample_rates [] = { 44100, 48000, 32000, 22050, 16000, 96000 } ;
  29. unsigned k ;
  30. int errors = 0 ;
  31. gen_windowed_sine (data_out, ARRAY_LEN (data_out), 0.95);
  32. for (k = 0 ; k < ARRAY_LEN (sample_rates); k ++) {
  33. char filename [64] ;
  34. snprintf (filename, sizeof (filename), "vorbis_%u.ogg", sample_rates [k]);
  35. printf (" %-20s : ", filename);
  36. fflush (stdout);
  37. /* Set to know value. */
  38. set_data_in (data_in, ARRAY_LEN (data_in), 3.141);
  39. write_vorbis_data_or_die (filename, sample_rates [k], data_out, ARRAY_LEN (data_out));
  40. read_vorbis_data_or_die (filename, sample_rates [k], data_in, ARRAY_LEN (data_in));
  41. if (check_output (data_in, ARRAY_LEN (data_in)) != 0)
  42. errors ++ ;
  43. else {
  44. puts ("ok");
  45. remove (filename);
  46. }
  47. }
  48. if (errors)
  49. exit (1);
  50. return 0;
  51. }
  52. static int
  53. check_output (const float * data_in, unsigned len)
  54. {
  55. float max_abs = 0.0 ;
  56. unsigned k ;
  57. for (k = 0 ; k < len ; k++) {
  58. float temp = fabs (data_in [k]);
  59. max_abs = MAX (max_abs, temp);
  60. }
  61. if (max_abs < 0.9) {
  62. printf ("Error : max_abs (%f) too small.\n", max_abs);
  63. return 1 ;
  64. } else if (max_abs > 1.0) {
  65. printf ("Error : max_abs (%f) too big.\n", max_abs);
  66. return 1 ;
  67. }
  68. return 0 ;
  69. }