2 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
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.
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.
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.
34 #define BUFFER_SIZE (2000)
36 static void old_test (void) ;
37 static void headerless_test (const char * filename
, int format
, int expected
) ;
44 headerless_test ("raw.vox", SF_FORMAT_VOX_ADPCM
, SF_FORMAT_RAW
| SF_FORMAT_VOX_ADPCM
) ;
45 headerless_test ("raw.gsm", SF_FORMAT_GSM610
, SF_FORMAT_RAW
| SF_FORMAT_GSM610
) ;
47 headerless_test ("raw.snd", SF_FORMAT_ULAW
, SF_FORMAT_RAW
| SF_FORMAT_ULAW
) ;
48 headerless_test ("raw.au" , SF_FORMAT_ULAW
, SF_FORMAT_RAW
| SF_FORMAT_ULAW
) ;
54 headerless_test (const char * filename
, int format
, int expected
)
55 { static short buffer
[BUFFER_SIZE
] ;
60 format
&= SF_FORMAT_SUBMASK
;
62 print_test_name (__func__
, filename
) ;
64 for (k
= 0 ; k
< BUFFER_SIZE
; k
++)
67 sfinfo
.samplerate
= 8000 ;
70 sfinfo
.format
= SF_FORMAT_RAW
| format
;
72 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
74 if ((k
= sf_write_short (file
, buffer
, BUFFER_SIZE
)) != BUFFER_SIZE
)
75 { printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__
, BUFFER_SIZE
, k
) ;
77 puts (sf_strerror (file
)) ;
83 memset (buffer
, 0, sizeof (buffer
)) ;
85 /* We should be able to detect these so clear sfinfo. */
86 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
88 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
90 if (sfinfo
.format
!= expected
)
91 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, expected
, sfinfo
.format
) ;
95 if (sfinfo
.frames
< BUFFER_SIZE
)
96 { printf ("Line %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__
, BUFFER_SIZE
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
100 if (sfinfo
.channels
!= 1)
101 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__
) ;
105 check_log_buffer_or_die (file
, __LINE__
) ;
111 } /* headerless_test */
115 { static short buffer
[BUFFER_SIZE
] ;
119 const char *filename
= "headerless.wav" ;
121 print_test_name (__func__
, "") ;
123 for (k
= 0 ; k
< BUFFER_SIZE
; k
++)
126 filetype
= SF_FORMAT_WAV
| SF_FORMAT_PCM_16
;
128 sfinfo
.samplerate
= 32000 ;
129 sfinfo
.frames
= 123456789 ; /* Wrong length. Library should correct this on sf_close. */
130 sfinfo
.channels
= 1 ;
131 sfinfo
.format
= filetype
;
133 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
135 if ((k
= sf_write_short (file
, buffer
, BUFFER_SIZE
)) != BUFFER_SIZE
)
136 { printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__
, BUFFER_SIZE
, k
) ;
138 puts (sf_strerror (file
)) ;
144 memset (buffer
, 0, sizeof (buffer
)) ;
146 /* Read as RAW but get the bit width and endian-ness correct. */
147 sfinfo
.format
= filetype
= SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_PCM_16
;
149 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
151 if (sfinfo
.format
!= filetype
)
152 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, filetype
, sfinfo
.format
) ;
156 if (sfinfo
.frames
< BUFFER_SIZE
)
157 { printf ("Line %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__
, BUFFER_SIZE
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
161 if (sfinfo
.channels
!= 1)
162 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__
) ;
166 check_log_buffer_or_die (file
, __LINE__
) ;
168 if ((k
= sf_read_short (file
, buffer
, BUFFER_SIZE
)) != BUFFER_SIZE
)
169 { printf ("Line %d: short read (%d).\n", __LINE__
, k
) ;
173 for (k
= 0 ; k
< BUFFER_SIZE
- 22 ; k
++)
174 if (buffer
[k
+ 22] != k
)
175 { printf ("Line %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__
, k
, k
, buffer
[k
]) ;