Mercurial > audlegacy
annotate src/audacious/volumecontrol.c @ 4291:ca077e01ed3a
Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
author | Jussi Judin <jjudin+audacious@iki.fi> |
---|---|
date | Mon, 18 Feb 2008 20:44:40 -0600 |
parents | 3c673b6803c1 |
children | fec498c745f6 |
rev | line source |
---|---|
3545
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
1 /* |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
2 * Audacious |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
3 * Copyright (c) 2007 William Pitcock |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
4 * |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
5 * volumecontrol.c: High quality volume PCM padding flow. |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
6 * |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
9 * the Free Software Foundation; under version 3 of the License. |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
10 * |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
15 * |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
17 * along with this program. If not, see <http://www.gnu.org/licenses>. |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
18 * |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
19 * The Audacious team does not consider modular code linking to |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
20 * Audacious or using our public API to be a derived work. |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
21 */ |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
22 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
23 #include "output.h" |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
24 #include "iir.h" |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
25 #include "main.h" |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
26 #include "input.h" |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
27 #include "playback.h" |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
28 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
29 #include "playlist.h" |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
30 #include "configdb.h" |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
31 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
32 #include "effect.h" |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
33 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
34 #include "volumecontrol.h" |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
35 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
36 #include <math.h> |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
37 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
38 typedef struct { |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
39 gint left; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
40 gint right; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
41 } volumecontrol_req_t; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
42 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
43 static volumecontrol_req_t vc_state_ = { 100, 100 }; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
44 |
4272
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
45 #define GAIN -50.0 /* dB */ |
3545
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
46 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
47 void volumecontrol_pad_audio(gpointer data, gint length, AFormat fmt, |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
48 gint channels) |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
49 { |
4272
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
50 gint i, k, samples; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
51 float vol, lvol, rvol; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
52 float lgain, rgain; |
3545
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
53 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
54 if (vc_state_.left == 100 && vc_state_.right == 100) |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
55 return; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
56 |
4272
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
57 if (channels != 2 && (vc_state_.left == 100 || vc_state_.right == 100)) |
3545
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
58 return; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
59 |
4272
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
60 lgain = (float)(100 - vc_state_.left) * GAIN / 100.0; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
61 rgain = (float)(100 - vc_state_.right) * GAIN / 100.0; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
62 |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
63 lvol = pow(10.0, lgain / 20.0); |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
64 rvol = pow(10.0, rgain / 20.0); |
3545
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
65 vol = MAX(lvol, rvol); |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
66 |
4272
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
67 float *ptr = data; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
68 samples = length / sizeof(float); |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
69 for (k = 0; k < samples; k++) { |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
70 if (channels == 2) { |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
71 *ptr *= lvol; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
72 ptr++; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
73 *ptr *= rvol; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
74 ptr++; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
75 } else { /* for mono and other channels number */ |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
76 for (i = 0; i < channels; i++) { |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
77 *ptr *= vol; ptr++; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
78 } |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
79 } |
3545
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
80 } |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
81 } |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
82 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
83 void |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
84 volumecontrol_get_volume_state(gint *l, gint *r) |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
85 { |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
86 *l = vc_state_.left; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
87 *r = vc_state_.right; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
88 } |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
89 |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
90 void |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
91 volumecontrol_set_volume_state(gint l, gint r) |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
92 { |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
93 vc_state_.left = l; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
94 vc_state_.right = r; |
7a2b667bab4b
Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
95 } |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3545
diff
changeset
|
96 |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3545
diff
changeset
|
97 void |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3545
diff
changeset
|
98 volumecontrol_flow(FlowContext *context) |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3545
diff
changeset
|
99 { |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3545
diff
changeset
|
100 if (!cfg.software_volume_control) |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3545
diff
changeset
|
101 return; |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3545
diff
changeset
|
102 |
4272
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
103 if (context->fmt != FMT_FLOAT) { |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
104 g_warning("volumecontrol_flow(): unhandled format %d.", context->fmt); |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
105 context->error = TRUE; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
106 return; |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
107 } |
32bb5ea701ed
- software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3981
diff
changeset
|
108 |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3545
diff
changeset
|
109 volumecontrol_pad_audio(context->data, context->len, context->fmt, context->channels); |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3545
diff
changeset
|
110 } |