largefile_test.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. ** Copyright (C) 2006-2011 Erik de Castro Lopo <[email protected]>
  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. #if HAVE_UNISTD_H
  23. #include <unistd.h>
  24. #else
  25. #include "sf_unistd.h"
  26. #endif
  27. #include <sndfile.h>
  28. #include "utils.h"
  29. #define BUFFER_LEN (1024 * 1024)
  30. #define BUFFER_COUNT (768)
  31. static void largefile_test (int filetype, const char * filename) ;
  32. int
  33. main (void)
  34. {
  35. largefile_test (SF_FORMAT_WAV, "largefile.wav") ;
  36. largefile_test (SF_FORMAT_AIFF, "largefile.aiff") ;
  37. return 0 ;
  38. } /* main */
  39. static void
  40. largefile_test (int filetype, const char * filename)
  41. { static float data [BUFFER_LEN] ;
  42. SNDFILE *file ;
  43. SF_INFO sfinfo ;
  44. int k ;
  45. print_test_name ("largefile_test", filename) ;
  46. sfinfo.samplerate = 44100 ;
  47. sfinfo.channels = 2 ;
  48. sfinfo.frames = 0 ;
  49. sfinfo.format = (filetype | SF_FORMAT_PCM_32) ;
  50. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  51. for (k = 0 ; k < BUFFER_COUNT ; k++)
  52. test_write_float_or_die (file, k, data, BUFFER_LEN, __LINE__) ;
  53. sf_close (file) ;
  54. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  55. if ((sfinfo.frames * sfinfo.channels) / BUFFER_LEN != BUFFER_COUNT)
  56. { printf ("\n\nLine %d : bad frame count.\n", __LINE__) ;
  57. exit (1) ;
  58. } ;
  59. sf_close (file) ;
  60. unlink (filename) ;
  61. puts ("ok") ;
  62. return ;
  63. } /* largefile_test */