2
** Copyright (C) 1999-2004 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__) ;
109
} /* headerless_test */
113
{ static short buffer [BUFFER_SIZE] ;
117
const char *filename = "headerless.wav" ;
119
print_test_name (__func__, "") ;
121
for (k = 0 ; k < BUFFER_SIZE ; k++)
124
filetype = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
126
sfinfo.samplerate = 32000 ;
127
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
128
sfinfo.channels = 1 ;
129
sfinfo.format = filetype ;
131
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
133
if ((k = sf_write_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
134
{ printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__, BUFFER_SIZE, k) ;
136
puts (sf_strerror (file)) ;
142
memset (buffer, 0, sizeof (buffer)) ;
144
/* Read as RAW but get the bit width and endian-ness correct. */
145
sfinfo.format = filetype = SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
147
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
149
if (sfinfo.format != filetype)
150
{ printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
154
if (sfinfo.frames < BUFFER_SIZE)
155
{ printf ("Line %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
159
if (sfinfo.channels != 1)
160
{ printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;
164
check_log_buffer_or_die (file, __LINE__) ;
166
if ((k = sf_read_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
167
{ printf ("Line %d: short read (%d).\n", __LINE__, k) ;
171
for (k = 0 ; k < BUFFER_SIZE - 22 ; k++)
172
if (buffer [k + 22] != k)
173
{ printf ("Line %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, k, buffer [k]) ;
182
** Do not edit or modify anything in this comment block.
183
** The arch-tag line is a file identity tag for the GNU Arch
184
** revision control system.
186
** arch-tag: 0820bc1a-c396-4e66-9997-096999b0bc40