annotate src/audacious/volumecontrol.c @ 4769:3ba4537c53b5

don't save legacy ui config options
author Tomasz Mon <desowin@gmail.com>
date Wed, 27 Aug 2008 14:36:37 +0200
parents fec498c745f6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 "main.h"
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 #include "input.h"
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26 #include "playback.h"
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28 #include "playlist.h"
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
29 #include "configdb.h"
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
30
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
31 #include "effect.h"
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
32
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
33 #include "volumecontrol.h"
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
35 #include <math.h>
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37 typedef struct {
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38 gint left;
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
39 gint right;
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
40 } volumecontrol_req_t;
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
41
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42 static volumecontrol_req_t vc_state_ = { 100, 100 };
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43
4272
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
44 #define GAIN -50.0 /* dB */
3545
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
46 void volumecontrol_pad_audio(gpointer data, gint length, AFormat fmt,
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47 gint channels)
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
48 {
4272
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
49 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
50 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
51 float lgain, rgain;
3545
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
53 if (vc_state_.left == 100 && vc_state_.right == 100)
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
54 return;
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55
4272
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
56 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
57 return;
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58
4272
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
59 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
60 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
61
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
62 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
63 rvol = pow(10.0, rgain / 20.0);
3545
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
64 vol = MAX(lvol, rvol);
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
65
4272
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
66 float *ptr = data;
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
67 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
68 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
69 if (channels == 2) {
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
70 *ptr *= lvol;
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
71 ptr++;
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
72 *ptr *= rvol;
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
73 ptr++;
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
74 } 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
75 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
76 *ptr *= vol; ptr++;
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
77 }
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
78 }
3545
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
79 }
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 void
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83 volumecontrol_get_volume_state(gint *l, gint *r)
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
84 {
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85 *l = vc_state_.left;
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86 *r = vc_state_.right;
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
87 }
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 void
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
90 volumecontrol_set_volume_state(gint l, gint r)
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
91 {
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 vc_state_.left = l;
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93 vc_state_.right = r;
7a2b667bab4b Add volumecontrol flow implementation.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94 }
3553
a140fadd741d software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents: 3545
diff changeset
95
a140fadd741d software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents: 3545
diff changeset
96 void
a140fadd741d software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents: 3545
diff changeset
97 volumecontrol_flow(FlowContext *context)
a140fadd741d software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents: 3545
diff changeset
98 {
a140fadd741d software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents: 3545
diff changeset
99 if (!cfg.software_volume_control)
a140fadd741d software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents: 3545
diff changeset
100 return;
a140fadd741d software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents: 3545
diff changeset
101
4272
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
102 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
103 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
104 context->error = TRUE;
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
105 return;
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
106 }
32bb5ea701ed - software volume switched to floating point and placed _after_ resampling
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3981
diff changeset
107
3553
a140fadd741d software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents: 3545
diff changeset
108 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
109 }