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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d6f40a06867b Changes includes:
anders
parents:
diff changeset
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
d6f40a06867b Changes includes:
anders
parents:
diff changeset
23
d6f40a06867b Changes includes:
anders
parents:
diff changeset
24 /* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if
d6f40a06867b Changes includes:
anders
parents:
diff changeset
25 fail */
24890
a54a25221b79 Remove some pointless 'inline' qualifiers
uau
parents: 14621
diff changeset
26 int af_from_dB(int n, float* in, float* out, float k, float mi, float ma)
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
27 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
28 int i = 0;
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
29 // Sanity check
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
30 if(!in || !out)
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
31 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
32
d6f40a06867b Changes includes:
anders
parents:
diff changeset
33 for(i=0;i<n;i++){
d6f40a06867b Changes includes:
anders
parents:
diff changeset
34 if(in[i]<=-200)
d6f40a06867b Changes includes:
anders
parents:
diff changeset
35 out[i]=0.0;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
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
d6f40a06867b Changes includes:
anders
parents:
diff changeset
38 }
d6f40a06867b Changes includes:
anders
parents:
diff changeset
39 return AF_OK;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
40 }
d6f40a06867b Changes includes:
anders
parents:
diff changeset
41
d6f40a06867b Changes includes:
anders
parents:
diff changeset
42 /* Convert from gain value to dB. Returns AF_OK if of and AF_ERROR if
d6f40a06867b Changes includes:
anders
parents:
diff changeset
43 fail */
24890
a54a25221b79 Remove some pointless 'inline' qualifiers
uau
parents: 14621
diff changeset
44 int af_to_dB(int n, float* in, float* out, float k)
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
45 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
46 int i = 0;
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
47 // Sanity check
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
48 if(!in || !out)
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
49 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
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
d6f40a06867b Changes includes:
anders
parents:
diff changeset
52 if(in[i] == 0.0)
d6f40a06867b Changes includes:
anders
parents:
diff changeset
53 out[i]=-200.0;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
54 else
d6f40a06867b Changes includes:
anders
parents:
diff changeset
55 out[i]=k*log10(in[i]);
d6f40a06867b Changes includes:
anders
parents:
diff changeset
56 }
d6f40a06867b Changes includes:
anders
parents:
diff changeset
57 return AF_OK;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
58 }
d6f40a06867b Changes includes:
anders
parents:
diff changeset
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
a54a25221b79 Remove some pointless 'inline' qualifiers
uau
parents: 14621
diff changeset
61 int af_from_ms(int n, float* in, int* out, int rate, float mi, float ma)
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
62 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
63 int i = 0;
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
64 // Sanity check
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
65 if(!in || !out)
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
66 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
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
d6f40a06867b Changes includes:
anders
parents:
diff changeset
70
d6f40a06867b Changes includes:
anders
parents:
diff changeset
71 return AF_OK;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
72 }
d6f40a06867b Changes includes:
anders
parents:
diff changeset
73
d6f40a06867b Changes includes:
anders
parents:
diff changeset
74 /* Convert from sample time to ms */
24890
a54a25221b79 Remove some pointless 'inline' qualifiers
uau
parents: 14621
diff changeset
75 int af_to_ms(int n, int* in, float* out, int rate)
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
76 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
77 int i = 0;
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
78 // Sanity check
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
79 if(!in || !out || !rate)
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
80 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
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
d6f40a06867b Changes includes:
anders
parents:
diff changeset
85 return AF_OK;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
86 }
d6f40a06867b Changes includes:
anders
parents:
diff changeset
87
d6f40a06867b Changes includes:
anders
parents:
diff changeset
88 /* Helper function for testing the output format */
24890
a54a25221b79 Remove some pointless 'inline' qualifiers
uau
parents: 14621
diff changeset
89 int af_test_output(struct af_instance_s* af, af_data_t* out)
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
90 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
91 if((af->data->format != out->format) ||
8607
d6f40a06867b Changes includes:
anders
parents:
diff changeset
92 (af->data->bps != out->bps) ||
d6f40a06867b Changes includes:
anders
parents:
diff changeset
93 (af->data->rate != out->rate) ||
d6f40a06867b Changes includes:
anders
parents:
diff changeset
94 (af->data->nch != out->nch)){
d6f40a06867b Changes includes:
anders
parents:
diff changeset
95 memcpy(out,af->data,sizeof(af_data_t));
d6f40a06867b Changes includes:
anders
parents:
diff changeset
96 return AF_FALSE;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
97 }
d6f40a06867b Changes includes:
anders
parents:
diff changeset
98 return AF_OK;
d6f40a06867b Changes includes:
anders
parents:
diff changeset
99 }
14621
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
100
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
101 /* Soft clipping, the sound of a dream, thanks to Jon Wattes
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
102 post to Musicdsp.org */
24890
a54a25221b79 Remove some pointless 'inline' qualifiers
uau
parents: 14621
diff changeset
103 float af_softclip(float a)
14621
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
104 {
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
105 if (a >= M_PI/2)
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
106 return 1.0;
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
107 else if (a <= -M_PI/2)
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
108 return -1.0;
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
109 else
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
110 return sin(a);
0293cab15c03 af_softclip
alex
parents: 8674
diff changeset
111 }