2
0

aiff_rw_test.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. ** Copyright (C) 2003-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 <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <unistd.h>
  22. #include <math.h>
  23. #include <inttypes.h>
  24. #include <sndfile.h>
  25. #include "utils.h"
  26. static unsigned char aifc_data [] =
  27. { 'F' , 'O' , 'R' , 'M' ,
  28. 0x00, 0x00, 0x01, 0xE8, /* FORM length */
  29. 'A' , 'I' , 'F' , 'C' ,
  30. 0x43, 0x4F, 0x4D, 0x4D, /* COMM */
  31. 0x00, 0x00, 0x00, 0x26, /* COMM length */
  32. 0x00, 0x01, 0x00, 0x00, 0x00, 0xAE, 0x00, 0x10, 0x40, 0x0D, 0xAC, 0x44,
  33. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x4F, 0x4E, 0x45, 0x0D, 'N' ,
  34. 'o' , 't' , ' ' , 'c' , 'o' , 'm' , 'p' , 'r' , 'e' , 's' , 's' , 'e' ,
  35. 'd' , 0x00,
  36. 'F' , 'V' , 'E' , 'R' , 0x00, 0x00, 0x00, 0x04, 0xA2, 0x80, 0x51, 0x40,
  37. /* A 'MARK' chunk. */
  38. 'M' , 'A' , 'R' , 'K' , 0x00, 0x00, 0x00, 0x36, 0x00, 0x05,
  39. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 'A' ,
  40. 0x00, 0x02, 0x00, 0x00, 0x11, 0x3A, 0x02, 'B' , 'C' , 0x00,
  41. 0x00, 0x03, 0x00, 0x00, 0x22, 0x74, 0x03, 'D' , 'E' , 'F',
  42. 0x00, 0x04, 0x00, 0x00, 0x33, 0xAE, 0x04, 'G' , 'H' , 'I', 'J' , 0x00,
  43. 0x00, 0x05, 0x00, 0x00, 0x44, 0xE8, 0x05, 'K' , 'L' , 'M', 'N' , 'O' ,
  44. 'S' , 'S' , 'N' , 'D' ,
  45. 0x00, 0x00, 0x01, 0x64, /* SSND length */
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0xFF, 0xE0, 0xFF, 0xDB, 0xFF, 0xD0, 0xFF, 0xD5, 0xFF, 0xD6, 0xFF, 0xD0,
  48. 0xFF, 0xBF, 0xFF, 0xBE, 0xFF, 0xB9, 0xFF, 0xC8, 0xFF, 0xBF, 0xFF, 0xD5,
  49. 0xFF, 0xC3, 0xFF, 0xBF, 0xFF, 0xB3, 0xFF, 0xBE, 0xFF, 0xB4, 0xFF, 0xAD,
  50. 0xFF, 0xAC, 0xFF, 0xAF, 0xFF, 0xB9, 0xFF, 0xB3, 0xFF, 0xA4, 0xFF, 0xA5,
  51. 0xFF, 0x93, 0xFF, 0x95, 0xFF, 0x97, 0xFF, 0x98, 0xFF, 0x99, 0xFF, 0x9E,
  52. 0xFF, 0x90, 0xFF, 0x80, 0xFF, 0x81, 0xFF, 0x7C, 0xFF, 0x80, 0xFF, 0x7C,
  53. 0xFF, 0x72, 0xFF, 0x72, 0xFF, 0x6C, 0xFF, 0x75, 0xFF, 0x6E, 0xFF, 0x6F,
  54. 0xFF, 0x66, 0x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0x73, 0xFF, 0x7B, 0xFF, 0xDE, 0xFF, 0xAD,
  69. 0x00, 0x4A, 0x00, 0x63, 0xEC, 0x8C, 0x03, 0xBB, 0x0E, 0xE4, 0x08, 0xF2,
  70. 0x00, 0x70, 0xE3, 0xD1, 0xE5, 0xE4, 0x01, 0x6E, 0x0A, 0x67, 0x1C, 0x74,
  71. 0xF8, 0x8E, 0x10, 0x7B, 0xEA, 0x3C, 0x09, 0x87, 0x1B, 0x24, 0xEF, 0x05,
  72. 0x17, 0x76, 0x0D, 0x5B, 0x02, 0x43, 0xF5, 0xEF, 0x0C, 0x1D, 0xF7, 0x61,
  73. 0x05, 0x95, 0x0B, 0xC2, 0xF1, 0x69, 0x1A, 0xA1, 0xEC, 0x75, 0xF4, 0x11,
  74. 0x13, 0x4F, 0x13, 0x71, 0xFA, 0x33, 0xEC, 0x32, 0xC8, 0xCF, 0x05, 0xB0,
  75. 0x0B, 0x61, 0x33, 0x19, 0xCE, 0x37, 0xEF, 0xD4, 0x21, 0x9D, 0xFA, 0xAE,
  76. } ;
  77. static void rw_test (const char *filename) ;
  78. int
  79. main (void)
  80. { const char *filename = "rw.aifc" ;
  81. print_test_name ("aiff_rw_test", filename) ;
  82. dump_data_to_file (filename, aifc_data, sizeof (aifc_data)) ;
  83. rw_test (filename) ;
  84. unlink (filename) ;
  85. puts ("ok") ;
  86. return 0 ;
  87. } /* main */
  88. /*==============================================================================
  89. */
  90. static void
  91. rw_test (const char *filename)
  92. { SNDFILE *file ;
  93. SF_INFO sfinfo_rd, sfinfo_rw ;
  94. memset (&sfinfo_rd, 0, sizeof (sfinfo_rd)) ;
  95. memset (&sfinfo_rw, 0, sizeof (sfinfo_rw)) ;
  96. /* Open the file in read only mode and fill in the SF_INFO struct. */
  97. if ((file = sf_open (filename, SFM_READ, &sfinfo_rd)) == NULL)
  98. { printf ("\n\nLine %d : sf_open SFM_READ failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
  99. exit (1) ;
  100. } ;
  101. check_log_buffer_or_die (file, __LINE__) ;
  102. sf_close (file) ;
  103. /* Now open read/write and close the file. */
  104. if ((file = sf_open (filename, SFM_RDWR, &sfinfo_rw)) == NULL)
  105. { printf ("\n\nLine %d : sf_open SFM_RDWR failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
  106. exit (1) ;
  107. } ;
  108. check_log_buffer_or_die (file, __LINE__) ;
  109. sf_close (file) ;
  110. /* Open again as read only again and fill in a new SF_INFO struct. */
  111. memset (&sfinfo_rw, 0, sizeof (sfinfo_rw)) ;
  112. if ((file = sf_open (filename, SFM_READ, &sfinfo_rw)) == NULL)
  113. { printf ("\n\nLine %d : sf_open SFM_RDWR failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
  114. exit (1) ;
  115. } ;
  116. check_log_buffer_or_die (file, __LINE__) ;
  117. sf_close (file) ;
  118. /* Now compare the two. */
  119. if (sfinfo_rd.format != sfinfo_rw.format)
  120. { printf ("\n\nLine %d : format mismatch (0x%08X != 0x%08X).\n\n", __LINE__,
  121. sfinfo_rd.format, sfinfo_rw.format) ;
  122. exit (1) ;
  123. } ;
  124. if (sfinfo_rd.channels != sfinfo_rw.channels)
  125. { printf ("\n\nLine %d : channel count mismatch (%d != %d).\n\n", __LINE__,
  126. sfinfo_rd.channels, sfinfo_rw.channels) ;
  127. exit (1) ;
  128. } ;
  129. if (sfinfo_rd.frames != sfinfo_rw.frames)
  130. { printf ("\n\nLine %d : frame count mismatch (rd %" PRId64 " != rw %" PRId64 ").\n\n", __LINE__,
  131. sfinfo_rd.frames, sfinfo_rw.frames) ;
  132. exit (1) ;
  133. } ;
  134. return ;
  135. } /* rw_test */