1 /* libSoX file format: Psion wve (c) 2008 robs@users.sourceforge.net
3 * See http://filext.com/file-extension/WVE
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation; either version 2.1 of the License, or (at
8 * your option) any later version.
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
13 * General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 static char const ID1
[18] = "ALawSoundFile**\0\017\020";
24 static char const ID2
[] = {0,0,0,1,0,0,0,0,0,0}; /* pad & repeat info: ignore */
26 static int start_read(sox_format_t
* ft
)
28 char buf
[sizeof(ID1
)];
31 if (lsx_readchars(ft
, buf
, sizeof(buf
)) || lsx_readdw(ft
, &num_samples
) ||
32 lsx_skipbytes(ft
, sizeof(ID2
)))
34 if (memcmp(ID1
, buf
, sizeof(buf
))) {
35 lsx_fail_errno(ft
, SOX_EHDR
, "wve: can't find Psion identifier");
38 return lsx_check_read_params(ft
, 1, 8000., SOX_ENCODING_ALAW
, 8, (uint64_t)num_samples
, sox_true
);
41 static int write_header(sox_format_t
* ft
)
43 uint64_t size64
= ft
->olength
? ft
->olength
:ft
->signal
.length
;
44 unsigned size
= size64
> UINT_MAX
? 0 : (unsigned)size64
;
45 return lsx_writechars(ft
, ID1
, sizeof(ID1
))
46 || lsx_writedw(ft
, size
)
47 || lsx_writechars(ft
, ID2
, sizeof(ID2
))? SOX_EOF
:SOX_SUCCESS
;
50 LSX_FORMAT_HANDLER(wve
)
52 static char const * const names
[] = {"wve", NULL
};
53 static sox_rate_t
const write_rates
[] = {8000, 0};
54 static unsigned const write_encodings
[] = {SOX_ENCODING_ALAW
, 8, 0, 0};
55 static sox_format_handler_t
const handler
= {SOX_LIB_VERSION_CODE
,
56 "Psion 3 audio format",
57 names
, SOX_FILE_BIG_END
| SOX_FILE_MONO
| SOX_FILE_REWIND
,
58 start_read
, lsx_rawread
, NULL
,
59 write_header
, lsx_rawwrite
, NULL
,
60 lsx_rawseek
, write_encodings
, write_rates
, 0