1 /* libSoX effect: Output audio to 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
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
!= 'w')
30 static int flow(sox_effect_t
*effp
, sox_sample_t
const * ibuf
,
31 sox_sample_t
* obuf
, size_t * isamp
, size_t * osamp
)
33 priv_t
* p
= (priv_t
*)effp
->priv
;
34 /* Write out *isamp samples */
35 size_t len
= sox_write(p
->file
, ibuf
, *isamp
);
37 /* len is the number of samples that were actually written out; if this is
38 * different to *isamp, then something has gone wrong--most often, it's
39 * out of disc space */
41 lsx_fail("%s: %s", p
->file
->filename
, p
->file
->sox_errstr
);
45 /* Outputting is the last `effect' in the effect chain so always passes
46 * 0 samples on to the next effect (as there isn't one!) */
47 (void)obuf
, *osamp
= 0;
48 return SOX_SUCCESS
; /* All samples output successfully */
51 sox_effect_handler_t
const * lsx_output_effect_fn(void)
53 static sox_effect_handler_t handler
= {
54 "output", NULL
, SOX_EFF_MCHAN
| SOX_EFF_INTERNAL
,
55 getopts
, NULL
, flow
, NULL
, NULL
, NULL
, sizeof(priv_t
)