Mercurial > mplayer.hg
annotate libaf/af_tools.c @ 31854:c680009d6779
Add 'z' length modifier to %d printf format specifier for size_t argument.
stream/http.c:675: warning: format '%d' expects type 'int', but argument 4 has type 'size_t'
author | diego |
---|---|
date | Fri, 06 Aug 2010 22:21:53 +0000 |
parents | 0f1b5b68af32 |
children | 2b9bc3c2933d |
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> |
26342
327b7955381f
Use quotes instead of angular brackets for local includes.
diego
parents:
24890
diff
changeset
|
21 #include "af.h" |
8607 | 22 |
23 /* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if | |
24 fail */ | |
24890 | 25 int af_from_dB(int n, float* in, float* out, float k, float mi, float ma) |
8607 | 26 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
27 int i = 0; |
8607 | 28 // Sanity check |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
29 if(!in || !out) |
8607 | 30 return AF_ERROR; |
31 | |
32 for(i=0;i<n;i++){ | |
33 if(in[i]<=-200) | |
34 out[i]=0.0; | |
35 else | |
36 out[i]=pow(10.0,clamp(in[i],mi,ma)/k); | |
37 } | |
38 return AF_OK; | |
39 } | |
40 | |
41 /* Convert from gain value to dB. Returns AF_OK if of and AF_ERROR if | |
42 fail */ | |
24890 | 43 int af_to_dB(int n, float* in, float* out, float k) |
8607 | 44 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
45 int i = 0; |
8607 | 46 // Sanity check |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
47 if(!in || !out) |
8607 | 48 return AF_ERROR; |
49 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
50 for(i=0;i<n;i++){ |
8607 | 51 if(in[i] == 0.0) |
52 out[i]=-200.0; | |
53 else | |
54 out[i]=k*log10(in[i]); | |
55 } | |
56 return AF_OK; | |
57 } | |
58 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
59 /* Convert from ms to sample time */ |
24890 | 60 int af_from_ms(int n, float* in, int* out, int rate, float mi, float ma) |
8607 | 61 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
62 int i = 0; |
8607 | 63 // Sanity check |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
64 if(!in || !out) |
8607 | 65 return AF_ERROR; |
66 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
67 for(i=0;i<n;i++) |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
68 out[i]=(int)((float)rate * clamp(in[i],mi,ma)/1000.0); |
8607 | 69 |
70 return AF_OK; | |
71 } | |
72 | |
73 /* Convert from sample time to ms */ | |
24890 | 74 int af_to_ms(int n, int* in, float* out, int rate) |
8607 | 75 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
76 int i = 0; |
8607 | 77 // Sanity check |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
78 if(!in || !out || !rate) |
8607 | 79 return AF_ERROR; |
80 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
81 for(i=0;i<n;i++) |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
82 out[i]=1000.0 * (float)in[i]/((float)rate); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
83 |
8607 | 84 return AF_OK; |
85 } | |
86 | |
87 /* Helper function for testing the output format */ | |
24890 | 88 int af_test_output(struct af_instance_s* af, af_data_t* out) |
8607 | 89 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
90 if((af->data->format != out->format) || |
8607 | 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)); | |
95 return AF_FALSE; | |
96 } | |
97 return AF_OK; | |
98 } | |
14621 | 99 |
100 /* Soft clipping, the sound of a dream, thanks to Jon Wattes | |
101 post to Musicdsp.org */ | |
24890 | 102 float af_softclip(float a) |
14621 | 103 { |
104 if (a >= M_PI/2) | |
105 return 1.0; | |
106 else if (a <= -M_PI/2) | |
107 return -1.0; | |
108 else | |
109 return sin(a); | |
110 } |