test.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. ********************************************************************/
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <math.h>
  17. #include "util.h"
  18. #include "write_read.h"
  19. #define DATA_LEN 2048
  20. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  21. static int check_output (const float * data_in, unsigned len, float allowable);
  22. int
  23. main(void){
  24. static float data_out [DATA_LEN] ;
  25. static float data_in [DATA_LEN] ;
  26. /* Do safest and most used sample rates first. */
  27. int sample_rates [] = { 44100, 48000, 32000, 22050, 16000, 96000 } ;
  28. unsigned k ;
  29. int errors = 0 ;
  30. int ch;
  31. gen_windowed_sine (data_out, ARRAY_LEN (data_out), 0.95);
  32. for(ch=1;ch<=8;ch++){
  33. float q=-.05;
  34. printf("\nTesting %d channel%s\n\n",ch,ch==1?"":"s");
  35. while(q<1.){
  36. for (k = 0 ; k < ARRAY_LEN (sample_rates); k ++) {
  37. char filename [64] ;
  38. snprintf (filename, sizeof (filename), "vorbis_%dch_q%.1f_%u.ogg", ch,q*10,sample_rates [k]);
  39. printf (" %-20s : ", filename);
  40. fflush (stdout);
  41. /* Set to know value. */
  42. set_data_in (data_in, ARRAY_LEN (data_in), 3.141);
  43. write_vorbis_data_or_die (filename, sample_rates [k], q, data_out, ARRAY_LEN (data_out),ch);
  44. read_vorbis_data_or_die (filename, sample_rates [k], data_in, ARRAY_LEN (data_in));
  45. if (check_output (data_in, ARRAY_LEN (data_in), (.15f - .1f*q)) != 0)
  46. errors ++ ;
  47. else {
  48. puts ("ok");
  49. remove (filename);
  50. }
  51. }
  52. q+=.1;
  53. }
  54. }
  55. if (errors)
  56. exit (1);
  57. return 0;
  58. }
  59. static int
  60. check_output (const float * data_in, unsigned len, float allowable)
  61. {
  62. float max_abs = 0.0 ;
  63. unsigned k ;
  64. for (k = 0 ; k < len ; k++) {
  65. float temp = fabs (data_in [k]);
  66. max_abs = MAX (max_abs, temp);
  67. }
  68. if (max_abs < 0.95-allowable) {
  69. printf ("Error : max_abs (%f) too small.\n", max_abs);
  70. return 1 ;
  71. } else if (max_abs > .95+allowable) {
  72. printf ("Error : max_abs (%f) too big.\n", max_abs);
  73. return 1 ;
  74. }
  75. return 0 ;
  76. }