test.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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$
  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, float allowable);
  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. int ch;
  32. gen_windowed_sine (data_out, ARRAY_LEN (data_out), 0.95);
  33. for(ch=1;ch<=8;ch++){
  34. float q=-.05;
  35. printf("\nTesting %d channel%s\n\n",ch,ch==1?"":"s");
  36. while(q<1.){
  37. for (k = 0 ; k < ARRAY_LEN (sample_rates); k ++) {
  38. char filename [64] ;
  39. snprintf (filename, sizeof (filename), "vorbis_%dch_q%.1f_%u.ogg", ch,q*10,sample_rates [k]);
  40. printf (" %-20s : ", filename);
  41. fflush (stdout);
  42. /* Set to know value. */
  43. set_data_in (data_in, ARRAY_LEN (data_in), 3.141);
  44. write_vorbis_data_or_die (filename, sample_rates [k], q, data_out, ARRAY_LEN (data_out),ch);
  45. read_vorbis_data_or_die (filename, sample_rates [k], data_in, ARRAY_LEN (data_in));
  46. if (check_output (data_in, ARRAY_LEN (data_in), (.15f - .1f*q)) != 0)
  47. errors ++ ;
  48. else {
  49. puts ("ok");
  50. remove (filename);
  51. }
  52. }
  53. q+=.1;
  54. }
  55. }
  56. if (errors)
  57. exit (1);
  58. return 0;
  59. }
  60. static int
  61. check_output (const float * data_in, unsigned len, float allowable)
  62. {
  63. float max_abs = 0.0 ;
  64. unsigned k ;
  65. for (k = 0 ; k < len ; k++) {
  66. float temp = fabs (data_in [k]);
  67. max_abs = MAX (max_abs, temp);
  68. }
  69. if (max_abs < 0.95-allowable) {
  70. printf ("Error : max_abs (%f) too small.\n", max_abs);
  71. return 1 ;
  72. } else if (max_abs > .95+allowable) {
  73. printf ("Error : max_abs (%f) too big.\n", max_abs);
  74. return 1 ;
  75. }
  76. return 0 ;
  77. }