Mercurial > audlegacy
annotate audacious/softvolume.c @ 1753:01df1ea5feae trunk
[svn] Mute while seeking for playback resume, tighten the loop. We want a responsive GUI ASAP.
author | chainsaw |
---|---|
date | Thu, 21 Sep 2006 13:24:48 -0700 |
parents | 705d4c089fce |
children |
rev | line source |
---|---|
0 | 1 /* XMMS - Software volume managment. |
2 * Copyright (C) 2001-2003 Matthieu Sozeau | |
3 * Original implementation from a patch by Tomas Simonaitis <haden@homelan.lt> | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; either version 2 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
1459 | 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 18 */ |
19 | |
20 #include <libaudacious/configdb.h> | |
21 #include "softvolume.h" | |
22 | |
23 | |
24 /************************************************************************** | |
25 * | |
26 * soft_volume_load | |
27 * | |
28 * TODO: make argument order consistent with soft_volume_save() | |
29 * | |
30 **************************************************************************/ | |
31 | |
32 void | |
33 soft_volume_load(const gchar * section, SoftVolumeConfig * c) | |
34 { | |
35 ConfigDb *db; | |
36 | |
37 g_return_if_fail(c != NULL); | |
38 | |
39 c->enabled = FALSE; | |
40 c->volume_left = 0; | |
41 c->volume_right = 0; | |
42 | |
43 db = bmp_cfg_db_open(); | |
44 | |
45 bmp_cfg_db_get_bool(db, section, "softvolume_enable", &c->enabled); | |
46 bmp_cfg_db_get_int(db, section, "softvolume_left", &c->volume_left); | |
47 bmp_cfg_db_get_int(db, section, "softvolume_right", &c->volume_right); | |
48 | |
49 bmp_cfg_db_close(db); | |
50 } | |
51 | |
52 | |
53 /************************************************************************** | |
54 * | |
55 * soft_volume_save | |
56 * | |
57 * TODO: make argument order consistent with soft_volume_load() | |
58 * | |
59 **************************************************************************/ | |
60 | |
61 void | |
62 soft_volume_save(SoftVolumeConfig * c, const gchar * section) | |
63 { | |
64 ConfigDb *db; | |
65 | |
66 g_return_if_fail(c != NULL); | |
67 | |
68 db = bmp_cfg_db_open(); | |
69 | |
70 bmp_cfg_db_set_bool(db, section, "softvolume_enable", c->enabled); | |
71 bmp_cfg_db_set_int(db, section, "softvolume_left", c->volume_left); | |
72 bmp_cfg_db_set_int(db, section, "softvolume_right", c->volume_right); | |
73 | |
74 bmp_cfg_db_close(db); | |
75 } | |
76 | |
77 | |
78 | |
79 /************************************************************************** | |
80 * | |
81 * soft_volume_get | |
82 * | |
83 **************************************************************************/ | |
84 | |
85 void | |
86 soft_volume_get(SoftVolumeConfig * c, gint * l, gint * r) | |
87 { | |
88 if (c == NULL) | |
89 return; | |
90 | |
91 *l = c->volume_left; | |
92 *r = c->volume_right; | |
93 } | |
94 | |
95 | |
96 | |
97 /************************************************************************** | |
98 * | |
99 * soft_volume_set | |
100 * | |
101 **************************************************************************/ | |
102 | |
103 void | |
104 soft_volume_set(SoftVolumeConfig * c, gint l, gint r) | |
105 { | |
106 if (c == NULL) | |
107 return; | |
108 | |
109 c->volume_left = l; | |
110 c->volume_right = r; | |
111 } | |
112 | |
113 | |
114 /************************************************************************** | |
115 * | |
116 * effect_16bit | |
117 * | |
118 **************************************************************************/ | |
119 | |
153
37882ab04091
[svn] Do not use G_INLINE_FUNC. Reported by halcy0n@gentoo.org
nenolod
parents:
0
diff
changeset
|
120 void |
0 | 121 effect_16bit(gint max, gint min, guint length, gint16 * sdata, |
122 SoftVolumeConfig * c) | |
123 { | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
153
diff
changeset
|
124 guint i; |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
153
diff
changeset
|
125 gint v; |
0 | 126 |
127 for (i = 0; i < (length >> 2); ++i) { /* ie. length/4 */ | |
128 v = (gint) ((*sdata * c->volume_left) / 100); | |
129 *(sdata++) = (gint16) CLAMP(v, min, max); | |
130 | |
131 v = (gint) ((*sdata * c->volume_right) / 100); | |
132 *(sdata++) = (gint16) CLAMP(v, min, max); | |
133 } | |
134 } | |
135 | |
136 | |
137 /************************************************************************** | |
138 * | |
139 * effect_8bit | |
140 * | |
141 **************************************************************************/ | |
142 | |
153
37882ab04091
[svn] Do not use G_INLINE_FUNC. Reported by halcy0n@gentoo.org
nenolod
parents:
0
diff
changeset
|
143 void |
0 | 144 effect_8bit(gint max, gint min, guint length, gint8 * sdata, |
145 SoftVolumeConfig * c) | |
146 { | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
153
diff
changeset
|
147 guint i; |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
153
diff
changeset
|
148 gint v; |
0 | 149 |
150 for (i = 0; i < (length >> 1); ++i) { /* ie. length/2 */ | |
151 v = (gint) ((*sdata * c->volume_left) / 100); | |
152 *(sdata++) = (gint8) CLAMP(v, min, max); | |
153 | |
154 v = (gint) ((*sdata * c->volume_right) / 100); | |
155 *(sdata++) = (gint8) CLAMP(v, min, max); | |
156 } | |
157 } | |
158 | |
159 | |
160 /************************************************************************** | |
161 * | |
162 * soft_volume_effect | |
163 * | |
164 **************************************************************************/ | |
165 | |
166 void | |
167 soft_volume_effect(SoftVolumeConfig * c, gpointer data, AFormat format, | |
168 gint length) | |
169 { | |
170 if (!c) | |
171 return; | |
172 | |
173 if (c->volume_right == -1) | |
174 c->volume_right = c->volume_left; | |
175 | |
176 switch (format) { | |
177 #if (G_BYTE_ORDER == G_BIG_ENDIAN) | |
178 case FMT_S16_LE: | |
179 case FMT_U16_LE: | |
180 break; | |
181 | |
182 case FMT_U16_NE: | |
183 case FMT_U16_BE: | |
184 effect_16bit(65535, 0, length, data, c); | |
185 break; | |
186 | |
187 case FMT_S16_BE: | |
188 case FMT_S16_NE: | |
189 effect_16bit(32767, -32768, length, data, c); | |
190 break; | |
191 #else | |
192 case FMT_S16_BE: | |
193 case FMT_U16_BE: | |
194 break; | |
195 | |
196 case FMT_U16_LE: | |
197 case FMT_U16_NE: | |
198 effect_16bit(65535, 0, length, data, c); | |
199 break; | |
200 | |
201 case FMT_S16_LE: | |
202 case FMT_S16_NE: | |
203 effect_16bit(32767, -32768, length, data, c); | |
204 break; | |
205 #endif | |
206 | |
207 case FMT_U8: | |
208 effect_8bit(255, 0, length, data, c); | |
209 break; | |
210 | |
211 case FMT_S8: | |
212 effect_8bit(127, -128, length, data, c); | |
213 break; | |
214 } | |
215 } |