1 /* libSoX effect: Skeleton effect used as sample for creating new effects.
3 * Copyright 1999-2008 Chris Bagwell And SoX Contributors
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
22 /* Private data for effect */
28 * Process command-line options but don't do other
29 * initialization now: effp->in_signal & effp->out_signal are not
32 static int getopts(sox_effect_t
* effp
, int argc
, char UNUSED
**argv
)
34 priv_t
* UNUSED p
= (priv_t
*)effp
->priv
;
37 return lsx_usage(effp
);
39 p
->localdata
= atoi(argv
[1]);
41 return p
->localdata
> 0 ? SOX_SUCCESS
: SOX_EOF
;
46 * Do all initializations.
48 static int start(sox_effect_t
* effp
)
50 if (effp
->out_signal
.channels
== 1) {
51 lsx_fail("Can't run on mono data.");
59 * Process up to *isamp samples from ibuf and produce up to *osamp samples
60 * in obuf. Write back the actual numbers of samples to *isamp and *osamp.
61 * Return SOX_SUCCESS or, if error occurs, SOX_EOF.
63 static int flow(sox_effect_t
* effp
, const sox_sample_t
*ibuf
, sox_sample_t
*obuf
,
64 size_t *isamp
, size_t *osamp
)
66 priv_t
* UNUSED p
= (priv_t
*)effp
->priv
;
69 switch (effp
->out_signal
.channels
) {
71 /* Length to process will be buffer length / 2 since we
72 * work with two samples at a time.
74 len
= min(*isamp
, *osamp
) / 2;
75 for (done
= 0; done
< len
; done
++)
79 /* Advance buffer by 2 samples */
94 * Drain out remaining samples if the effect generates any.
96 static int drain(sox_effect_t UNUSED
* effp
, sox_sample_t UNUSED
*obuf
, size_t *osamp
)
99 /* Return SOX_EOF when drain
100 * will not output any more samples.
101 * *osamp == 0 also indicates that.
107 * Do anything required when you stop reading samples.
109 static int stop(sox_effect_t UNUSED
* effp
)
115 * Do anything required when you kill an effect.
116 * (free allocated memory, etc.)
118 static int lsx_kill(sox_effect_t UNUSED
* effp
)
124 * Function returning effect descriptor. This should be the only
125 * externally visible object.
127 const sox_effect_handler_t
*lsx_skel_effect_fn(void);
128 const sox_effect_handler_t
*lsx_skel_effect_fn(void)
132 * If no specific processing is needed for any of
133 * the 6 functions, then the function above can be deleted
134 * and NULL used in place of the its name below.
136 static sox_effect_handler_t sox_skel_effect
= {
137 "skel", "[OPTION]", SOX_EFF_MCHAN
,
138 getopts
, start
, flow
, drain
, stop
, lsx_kill
, sizeof(priv_t
)
140 return &sox_skel_effect
;