2
0

stdout_test.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. ** Copyright (C) 2001-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
  3. **
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. **
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ** GNU General Public License for more details.
  13. **
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "sfconfig.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <math.h>
  23. #if HAVE_UNISTD_H
  24. #include <unistd.h>
  25. #endif
  26. #include <sndfile.h>
  27. #include "utils.h"
  28. static void stdout_test (int typemajor, int count) ;
  29. int
  30. main (int argc, char *argv [])
  31. { int do_all, test_count = 0 ;
  32. if (argc != 2)
  33. { fprintf (stderr, "This program cannot be run by itself. It needs\n") ;
  34. fprintf (stderr, "to be run from the stdio_test program.\n") ;
  35. exit (1) ;
  36. } ;
  37. do_all = ! strcmp (argv [1], "all") ;
  38. if (do_all || ! strcmp (argv [1], "raw"))
  39. { stdout_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ;
  40. test_count ++ ;
  41. } ;
  42. if (do_all || ! strcmp (argv [1], "wav"))
  43. { stdout_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ;
  44. test_count ++ ;
  45. } ;
  46. if (do_all || ! strcmp (argv [1], "aiff"))
  47. { stdout_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ;
  48. test_count ++ ;
  49. } ;
  50. if (do_all || ! strcmp (argv [1], "au"))
  51. { stdout_test (SF_FORMAT_AU, PIPE_TEST_LEN) ;
  52. test_count ++ ;
  53. } ;
  54. if (do_all || ! strcmp (argv [1], "paf"))
  55. { stdout_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ;
  56. test_count ++ ;
  57. } ;
  58. if (do_all || ! strcmp (argv [1], "svx"))
  59. { stdout_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ;
  60. test_count ++ ;
  61. } ;
  62. if (do_all || ! strcmp (argv [1], "nist"))
  63. { stdout_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ;
  64. test_count ++ ;
  65. } ;
  66. if (do_all || ! strcmp (argv [1], "ircam"))
  67. { stdout_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ;
  68. test_count ++ ;
  69. } ;
  70. if (do_all || ! strcmp (argv [1], "voc"))
  71. { stdout_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ;
  72. test_count ++ ;
  73. } ;
  74. if (do_all || ! strcmp (argv [1], "w64"))
  75. { stdout_test (SF_FORMAT_W64, PIPE_TEST_LEN) ;
  76. test_count ++ ;
  77. } ;
  78. if (do_all || ! strcmp (argv [1], "mat4"))
  79. { stdout_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ;
  80. test_count ++ ;
  81. } ;
  82. if (do_all || ! strcmp (argv [1], "mat5"))
  83. { stdout_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ;
  84. test_count ++ ;
  85. } ;
  86. if (do_all || ! strcmp (argv [1], "pvf"))
  87. { stdout_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ;
  88. test_count ++ ;
  89. } ;
  90. if (test_count == 0)
  91. { fprintf (stderr, "\n******************************************\n") ;
  92. fprintf (stderr, "* stdout_test : No '%s' test defined.\n", argv [1]) ;
  93. fprintf (stderr, "******************************************\n") ;
  94. return 1 ;
  95. } ;
  96. return 0 ;
  97. } /* main */
  98. static void
  99. stdout_test (int typemajor, int count)
  100. { static short data [PIPE_TEST_LEN] ;
  101. SNDFILE *file ;
  102. SF_INFO sfinfo ;
  103. int k, total, this_write ;
  104. sfinfo.samplerate = 44100 ;
  105. sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
  106. sfinfo.channels = 1 ;
  107. sfinfo.frames = 0 ;
  108. /* Create some random data. */
  109. for (k = 0 ; k < PIPE_TEST_LEN ; k++)
  110. data [k] = PIPE_INDEX (k) ;
  111. if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL)
  112. { fprintf (stderr, "sf_open_write failed with error : ") ;
  113. fprintf (stderr, "%s\n", sf_strerror (NULL)) ;
  114. exit (1) ;
  115. } ;
  116. total = 0 ;
  117. while (total < count)
  118. { this_write = (count - total > 1024) ? 1024 : count - total ;
  119. if ((k = sf_write_short (file, data + total, this_write)) != this_write)
  120. { fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ;
  121. exit (1) ;
  122. } ;
  123. total += k ;
  124. } ;
  125. sf_close (file) ;
  126. return ;
  127. } /* stdout_test */