2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if
25 int af_from_dB(int n
, float* in
, float* out
, float k
, float mi
, float ma
)
36 out
[i
]=pow(10.0,clamp(in
[i
],mi
,ma
)/k
);
41 /* Convert from gain value to dB. Returns AF_OK if of and AF_ERROR if
43 int af_to_dB(int n
, float* in
, float* out
, float k
)
54 out
[i
]=k
*log10(in
[i
]);
59 /* Convert from ms to sample time */
60 int af_from_ms(int n
, float* in
, int* out
, int rate
, float mi
, float ma
)
68 out
[i
]=(int)((float)rate
* clamp(in
[i
],mi
,ma
)/1000.0);
73 /* Convert from sample time to ms */
74 int af_to_ms(int n
, int* in
, float* out
, int rate
)
78 if(!in
|| !out
|| !rate
)
82 out
[i
]=1000.0 * (float)in
[i
]/((float)rate
);
87 /* Helper function for testing the output format */
88 int af_test_output(struct af_instance_s
* af
, af_data_t
* out
)
90 if((af
->data
->format
!= out
->format
) ||
91 (af
->data
->bps
!= out
->bps
) ||
92 (af
->data
->rate
!= out
->rate
) ||
93 (af
->data
->nch
!= out
->nch
)){
94 memcpy(out
,af
->data
,sizeof(af_data_t
));
100 /* Soft clipping, the sound of a dream, thanks to Jon Wattes
101 post to Musicdsp.org */
102 float af_softclip(float a
)
106 else if (a
<= -M_PI
/2)