Mercurial > mplayer.hg
annotate libaf/af_tools.c @ 18978:9f97ca988ea7
Consistent option and variable naming for x11libdir and xvmclibdir.
author | diego |
---|---|
date | Sun, 09 Jul 2006 16:38:02 +0000 |
parents | 0293cab15c03 |
children | a54a25221b79 |
rev | line source |
---|---|
8607 | 1 #include <math.h> |
8623
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8607
diff
changeset
|
2 #include <string.h> |
8607 | 3 #include <af.h> |
4 | |
5 /* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if | |
6 fail */ | |
7 inline int af_from_dB(int n, float* in, float* out, float k, float mi, float ma) | |
8 { | |
9 int i = 0; | |
10 // Sanity check | |
11 if(!in || !out) | |
12 return AF_ERROR; | |
13 | |
14 for(i=0;i<n;i++){ | |
15 if(in[i]<=-200) | |
16 out[i]=0.0; | |
17 else | |
18 out[i]=pow(10.0,clamp(in[i],mi,ma)/k); | |
19 } | |
20 return AF_OK; | |
21 } | |
22 | |
23 /* Convert from gain value to dB. Returns AF_OK if of and AF_ERROR if | |
24 fail */ | |
25 inline int af_to_dB(int n, float* in, float* out, float k) | |
26 { | |
27 int i = 0; | |
28 // Sanity check | |
29 if(!in || !out) | |
30 return AF_ERROR; | |
31 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
32 for(i=0;i<n;i++){ |
8607 | 33 if(in[i] == 0.0) |
34 out[i]=-200.0; | |
35 else | |
36 out[i]=k*log10(in[i]); | |
37 } | |
38 return AF_OK; | |
39 } | |
40 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
41 /* Convert from ms to sample time */ |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
42 inline int af_from_ms(int n, float* in, int* out, int rate, float mi, float ma) |
8607 | 43 { |
44 int i = 0; | |
45 // Sanity check | |
46 if(!in || !out) | |
47 return AF_ERROR; | |
48 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
49 for(i=0;i<n;i++) |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
50 out[i]=(int)((float)rate * clamp(in[i],mi,ma)/1000.0); |
8607 | 51 |
52 return AF_OK; | |
53 } | |
54 | |
55 /* Convert from sample time to ms */ | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
56 inline int af_to_ms(int n, int* in, float* out, int rate) |
8607 | 57 { |
58 int i = 0; | |
59 // Sanity check | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
60 if(!in || !out || !rate) |
8607 | 61 return AF_ERROR; |
62 | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
63 for(i=0;i<n;i++) |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
64 out[i]=1000.0 * (float)in[i]/((float)rate); |
8607 | 65 |
66 return AF_OK; | |
67 } | |
68 | |
69 /* Helper function for testing the output format */ | |
70 inline int af_test_output(struct af_instance_s* af, af_data_t* out) | |
71 { | |
72 if((af->data->format != out->format) || | |
73 (af->data->bps != out->bps) || | |
74 (af->data->rate != out->rate) || | |
75 (af->data->nch != out->nch)){ | |
76 memcpy(out,af->data,sizeof(af_data_t)); | |
77 return AF_FALSE; | |
78 } | |
79 return AF_OK; | |
80 } | |
14621 | 81 |
82 /* Soft clipping, the sound of a dream, thanks to Jon Wattes | |
83 post to Musicdsp.org */ | |
84 inline float af_softclip(float a) | |
85 { | |
86 if (a >= M_PI/2) | |
87 return 1.0; | |
88 else if (a <= -M_PI/2) | |
89 return -1.0; | |
90 else | |
91 return sin(a); | |
92 } |