Mercurial > mplayer.hg
annotate libaf/af_tools.c @ 36417:9e68e53481e4
Display messages that can be confusing only with -v.
The VO initialization line will still say which format
was chosen, including what kind of hardware acceleration.
author | reimar |
---|---|
date | Sat, 16 Nov 2013 08:10:04 +0000 |
parents | 2b9bc3c2933d |
children |
rev | line source |
---|---|
28229
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
1 /* |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
2 * This file is part of MPlayer. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
3 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
7 * (at your option) any later version. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
8 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
12 * GNU General Public License for more details. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
13 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
17 */ |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26342
diff
changeset
|
18 |
8607 | 19 #include <math.h> |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
20 #include <string.h> |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
29263
diff
changeset
|
21 #include "libavutil/common.h" |
26342
327b7955381f
Use quotes instead of angular brackets for local includes.
diego
parents:
24890
diff
changeset
|
22 #include "af.h" |
8607 | 23 |
24 /* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if | |
25 fail */ | |
24890 | 26 int af_from_dB(int n, float* in, float* out, float k, float mi, float ma) |
8607 | 27 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
28 int i = 0; |
8607 | 29 // Sanity check |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
30 if(!in || !out) |
8607 | 31 return AF_ERROR; |
32 | |
33 for(i=0;i<n;i++){ | |
34 if(in[i]<=-200) | |
35 out[i]=0.0; | |
36 else | |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
29263
diff
changeset
|
37 out[i]=pow(10.0,av_clipf(in[i],mi,ma)/k); |
8607 | 38 } |
39 return AF_OK; | |
40 } | |
41 | |
42 /* Convert from gain value to dB. Returns AF_OK if of and AF_ERROR if | |
43 fail */ | |
24890 | 44 int af_to_dB(int n, float* in, float* out, float k) |
8607 | 45 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
46 int i = 0; |
8607 | 47 // Sanity check |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
48 if(!in || !out) |
8607 | 49 return AF_ERROR; |
50 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
51 for(i=0;i<n;i++){ |
8607 | 52 if(in[i] == 0.0) |
53 out[i]=-200.0; | |
54 else | |
55 out[i]=k*log10(in[i]); | |
56 } | |
57 return AF_OK; | |
58 } | |
59 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
60 /* Convert from ms to sample time */ |
24890 | 61 int af_from_ms(int n, float* in, int* out, int rate, float mi, float ma) |
8607 | 62 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
63 int i = 0; |
8607 | 64 // Sanity check |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
65 if(!in || !out) |
8607 | 66 return AF_ERROR; |
67 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
68 for(i=0;i<n;i++) |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
29263
diff
changeset
|
69 out[i]=(int)((float)rate * av_clipf(in[i],mi,ma)/1000.0); |
8607 | 70 |
71 return AF_OK; | |
72 } | |
73 | |
74 /* Convert from sample time to ms */ | |
24890 | 75 int af_to_ms(int n, int* in, float* out, int rate) |
8607 | 76 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
77 int i = 0; |
8607 | 78 // Sanity check |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
79 if(!in || !out || !rate) |
8607 | 80 return AF_ERROR; |
81 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
82 for(i=0;i<n;i++) |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
83 out[i]=1000.0 * (float)in[i]/((float)rate); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
84 |
8607 | 85 return AF_OK; |
86 } | |
87 | |
88 /* Helper function for testing the output format */ | |
24890 | 89 int af_test_output(struct af_instance_s* af, af_data_t* out) |
8607 | 90 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
91 if((af->data->format != out->format) || |
8607 | 92 (af->data->bps != out->bps) || |
93 (af->data->rate != out->rate) || | |
94 (af->data->nch != out->nch)){ | |
95 memcpy(out,af->data,sizeof(af_data_t)); | |
96 return AF_FALSE; | |
97 } | |
98 return AF_OK; | |
99 } | |
14621 | 100 |
101 /* Soft clipping, the sound of a dream, thanks to Jon Wattes | |
102 post to Musicdsp.org */ | |
24890 | 103 float af_softclip(float a) |
14621 | 104 { |
105 if (a >= M_PI/2) | |
106 return 1.0; | |
107 else if (a <= -M_PI/2) | |
108 return -1.0; | |
109 else | |
110 return sin(a); | |
111 } |