Mercurial > audlegacy
annotate audacious/softvolume.c @ 483:1cf5ce3ec0c0 trunk
[svn] Assembly file is now unused. Removing.
author | chainsaw |
---|---|
date | Sat, 21 Jan 2006 14:06:25 -0800 |
parents | 37882ab04091 |
children | 0a73d1faeb4e |
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 | |
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
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 { | |
124 gint i, v; | |
125 | |
126 for (i = 0; i < (length >> 2); ++i) { /* ie. length/4 */ | |
127 v = (gint) ((*sdata * c->volume_left) / 100); | |
128 *(sdata++) = (gint16) CLAMP(v, min, max); | |
129 | |
130 v = (gint) ((*sdata * c->volume_right) / 100); | |
131 *(sdata++) = (gint16) CLAMP(v, min, max); | |
132 } | |
133 } | |
134 | |
135 | |
136 /************************************************************************** | |
137 * | |
138 * effect_8bit | |
139 * | |
140 **************************************************************************/ | |
141 | |
153
37882ab04091
[svn] Do not use G_INLINE_FUNC. Reported by halcy0n@gentoo.org
nenolod
parents:
0
diff
changeset
|
142 void |
0 | 143 effect_8bit(gint max, gint min, guint length, gint8 * sdata, |
144 SoftVolumeConfig * c) | |
145 { | |
146 gint i, v; | |
147 | |
148 for (i = 0; i < (length >> 1); ++i) { /* ie. length/2 */ | |
149 v = (gint) ((*sdata * c->volume_left) / 100); | |
150 *(sdata++) = (gint8) CLAMP(v, min, max); | |
151 | |
152 v = (gint) ((*sdata * c->volume_right) / 100); | |
153 *(sdata++) = (gint8) CLAMP(v, min, max); | |
154 } | |
155 } | |
156 | |
157 | |
158 /************************************************************************** | |
159 * | |
160 * soft_volume_effect | |
161 * | |
162 **************************************************************************/ | |
163 | |
164 void | |
165 soft_volume_effect(SoftVolumeConfig * c, gpointer data, AFormat format, | |
166 gint length) | |
167 { | |
168 if (!c) | |
169 return; | |
170 | |
171 if (c->volume_right == -1) | |
172 c->volume_right = c->volume_left; | |
173 | |
174 switch (format) { | |
175 #if (G_BYTE_ORDER == G_BIG_ENDIAN) | |
176 case FMT_S16_LE: | |
177 case FMT_U16_LE: | |
178 break; | |
179 | |
180 case FMT_U16_NE: | |
181 case FMT_U16_BE: | |
182 effect_16bit(65535, 0, length, data, c); | |
183 break; | |
184 | |
185 case FMT_S16_BE: | |
186 case FMT_S16_NE: | |
187 effect_16bit(32767, -32768, length, data, c); | |
188 break; | |
189 #else | |
190 case FMT_S16_BE: | |
191 case FMT_U16_BE: | |
192 break; | |
193 | |
194 case FMT_U16_LE: | |
195 case FMT_U16_NE: | |
196 effect_16bit(65535, 0, length, data, c); | |
197 break; | |
198 | |
199 case FMT_S16_LE: | |
200 case FMT_S16_NE: | |
201 effect_16bit(32767, -32768, length, data, c); | |
202 break; | |
203 #endif | |
204 | |
205 case FMT_U8: | |
206 effect_8bit(255, 0, length, data, c); | |
207 break; | |
208 | |
209 case FMT_S8: | |
210 effect_8bit(127, -128, length, data, c); | |
211 break; | |
212 } | |
213 } |