id3: fix COMM frame handling
[sox.git] / src / input.c
blobcaaefab5f0f09812f5db7b3d57f895913d8e18d7
1 /* libSoX effect: Input audio from a file (c) 2008 robs@users.sourceforge.net
3 * This library is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation; either version 2.1 of the License, or (at
6 * your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
11 * General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "sox_i.h"
20 typedef struct {sox_format_t * file;} priv_t;
22 static int getopts(sox_effect_t * effp, int argc, char * * argv)
24 priv_t * p = (priv_t *)effp->priv;
25 if (argc != 2 || !(p->file = (sox_format_t *)argv[1]) || p->file->mode != 'r')
26 return SOX_EOF;
27 return SOX_SUCCESS;
30 static int drain(
31 sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
33 priv_t * p = (priv_t *)effp->priv;
35 /* ensure that *osamp is a multiple of the number of channels. */
36 *osamp -= *osamp % effp->out_signal.channels;
38 /* Read up to *osamp samples into obuf; store the actual number read
39 * back to *osamp */
40 *osamp = sox_read(p->file, obuf, *osamp);
42 /* sox_read may return a number that is less than was requested; only if
43 * 0 samples is returned does it indicate that end-of-file has been reached
44 * or an error has occurred */
45 if (!*osamp && p->file->sox_errno)
46 lsx_fail("%s: %s", p->file->filename, p->file->sox_errstr);
47 return *osamp? SOX_SUCCESS : SOX_EOF;
50 sox_effect_handler_t const * lsx_input_effect_fn(void)
52 static sox_effect_handler_t handler = {
53 "input", NULL, SOX_EFF_MCHAN | SOX_EFF_LENGTH | SOX_EFF_INTERNAL,
54 getopts, NULL, NULL, drain, NULL, NULL, sizeof(priv_t)
56 return &handler;