1 /* libSoX effect: Contrast Enhancement    (c) 2008 robs@users.sourceforge.net
2  *
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.
7  *
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.
12  *
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
16  */
17 
18 #include "sox_i.h"
19 
20 typedef struct {double contrast;} priv_t;
21 
create(sox_effect_t * effp,int argc,char ** argv)22 static int create(sox_effect_t * effp, int argc, char * * argv)
23 {
24   priv_t * p = (priv_t *)effp->priv;
25   p->contrast = 75;
26   --argc, ++argv;
27   do {NUMERIC_PARAMETER(contrast, 0, 100)} while (0);
28   p->contrast /= 750; /* shift range to 0 to 0.1333, default 0.1 */
29   return argc? lsx_usage(effp) : SOX_SUCCESS;
30 }
31 
flow(sox_effect_t * effp,const sox_sample_t * ibuf,sox_sample_t * obuf,size_t * isamp,size_t * osamp)32 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
33     sox_sample_t * obuf, size_t * isamp, size_t * osamp)
34 {
35   priv_t * p = (priv_t *)effp->priv;
36   size_t len = *isamp = *osamp = min(*isamp, *osamp);
37   while (len--) {
38     double d = *ibuf++ * (-M_PI_2 / SOX_SAMPLE_MIN);
39     *obuf++ = sin(d + p->contrast * sin(d * 4)) * SOX_SAMPLE_MAX;
40   }
41   return SOX_SUCCESS;
42 }
43 
lsx_contrast_effect_fn(void)44 sox_effect_handler_t const * lsx_contrast_effect_fn(void)
45 {
46   static sox_effect_handler_t handler = {"contrast", "[enhancement (75)]",
47     0, create, NULL, flow, NULL, NULL, NULL, sizeof(priv_t)};
48   return &handler;
49 }
50