2 ** Copyright (C) 1999-2003 Erik de Castro Lopo <erikd@zip.com.au>
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.
30 #define BUFFER_SIZE (100)
34 { static short buffer
[BUFFER_SIZE
] ;
38 char *filename
= "headerless.wav" ;
40 printf (" header-less test : ") ;
43 for (k
= 0 ; k
< BUFFER_SIZE
; k
++)
46 filetype
= SF_FORMAT_WAV
| SF_FORMAT_PCM_16
;
48 sfinfo
.samplerate
= 32000 ;
49 sfinfo
.frames
= 123456789 ; /* Wrong length. Library should correct this on sf_close. */
51 sfinfo
.format
= filetype
;
53 if (! (file
= sf_open (filename
, SFM_WRITE
, &sfinfo
)))
54 { printf ("Line %d: sf_open_write failed with error : ", __LINE__
) ;
56 puts (sf_strerror (NULL
)) ;
60 if ((k
= sf_write_short (file
, buffer
, BUFFER_SIZE
)) != BUFFER_SIZE
)
61 { printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__
, BUFFER_SIZE
, k
) ;
63 puts (sf_strerror (file
)) ;
69 memset (buffer
, 0, sizeof (buffer
)) ;
71 /* Read as RAW but get the bit width and endian-ness correct. */
72 sfinfo
.format
= filetype
= SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_PCM_16
;
74 if (! (file
= sf_open (filename
, SFM_READ
, &sfinfo
)))
75 { printf ("Line %d: sf_open_read failed with error : ", __LINE__
) ;
77 puts (sf_strerror (NULL
)) ;
81 if (sfinfo
.format
!= filetype
)
82 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, filetype
, sfinfo
.format
) ;
86 if (sfinfo
.frames
< BUFFER_SIZE
)
87 { printf ("Line %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__
, BUFFER_SIZE
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
91 if (sfinfo
.channels
!= 1)
92 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__
) ;
96 check_log_buffer_or_die (file
) ;
98 if ((k
= sf_read_short (file
, buffer
, BUFFER_SIZE
)) != BUFFER_SIZE
)
99 { printf ("Line %d: short read (%d).\n", __LINE__
, k
) ;
103 for (k
= 0 ; k
< BUFFER_SIZE
- 22 ; k
++)
104 if (buffer
[k
+ 22] != k
)
105 { printf ("Line %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__
, k
, k
, buffer
[k
]) ;