id3: fix COMM frame handling
[sox.git] / src / sounder.c
blob678d99ea456da13c0b1cee14cec67b9d3f935a4c
1 /* libSoX Sounder format handler (c) 2008 robs@users.sourceforge.net
2 * See description in soundr3b.zip on the net.
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or (at
7 * your option) any later version.
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
12 * General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "sox_i.h"
21 static int start_read(sox_format_t * ft)
23 uint16_t type, rate;
25 if (lsx_readw(ft, &type) || lsx_readw(ft, &rate) || lsx_skipbytes(ft, (size_t) 4))
26 return SOX_EOF;
27 if (type) {
28 lsx_fail_errno(ft, SOX_EHDR, "invalid Sounder header");
29 return SOX_EOF;
31 return lsx_check_read_params(ft, 1, (sox_rate_t)rate, SOX_ENCODING_UNSIGNED, 8, (uint64_t)0, sox_true);
34 static int write_header(sox_format_t * ft)
36 return lsx_writew(ft, 0) /* sample type */
37 || lsx_writew(ft, min(65535, (unsigned)(ft->signal.rate + .5)))
38 || lsx_writew(ft, 10) /* speaker driver volume */
39 || lsx_writew(ft, 4)? /* speaker driver DC shift */
40 SOX_EOF : SOX_SUCCESS;
43 LSX_FORMAT_HANDLER(sounder)
45 static char const * const names[] = {"sndr", NULL};
46 static unsigned const write_encodings[] = {SOX_ENCODING_UNSIGNED, 8, 0, 0};
47 static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
48 "8-bit linear audio as used by Aaron Wallace's `Sounder' of 1991",
49 names, SOX_FILE_LIT_END | SOX_FILE_MONO,
50 start_read, lsx_rawread, NULL,
51 write_header, lsx_rawwrite, NULL,
52 lsx_rawseek, write_encodings, NULL, 0
54 return &handler;