formats: clarify setting of reverse_bytes
[sox.git] / src / compandt.h
blob75e0349fa314a298ddd7d612497151627c5bb5cf
1 /* libSoX Compander Transfer Function (c) 2007 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 <math.h>
20 typedef struct {
21 struct sox_compandt_segment {
22 double x, y; /* 1st point in segment */
23 double a, b; /* Quadratic coeffecients for rest of segment */
24 } * segments;
25 double in_min_lin;
26 double out_min_lin;
27 double outgain_dB; /* Post processor gain */
28 double curve_dB;
29 } sox_compandt_t;
31 sox_bool lsx_compandt_parse(sox_compandt_t * t, char * points, char * gain);
32 sox_bool lsx_compandt_show(sox_compandt_t * t, sox_plot_t plot);
33 void lsx_compandt_kill(sox_compandt_t * p);
35 /* Place in header to allow in-lining */
36 static double lsx_compandt(sox_compandt_t * t, double in_lin)
38 struct sox_compandt_segment * s;
39 double in_log, out_log;
41 if (in_lin <= t->in_min_lin)
42 return t->out_min_lin;
44 in_log = log(in_lin);
46 for (s = t->segments + 1; in_log > s[1].x; ++s);
48 in_log -= s->x;
49 out_log = s->y + in_log * (s->a * in_log + s->b);
51 return exp(out_log);