Mercurial > audlegacy
annotate audacious/output.c @ 791:093965283548 trunk
[svn] - finish up here
author | nenolod |
---|---|
date | Fri, 03 Mar 2006 20:43:06 -0800 |
parents | 0a73d1faeb4e |
children | d51a251b542c |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 #include "output.h" | |
27 #include "iir.h" | |
28 #include "main.h" | |
29 #include "input.h" | |
30 | |
31 #include "playlist.h" | |
32 #include "libaudacious/util.h" | |
33 | |
34 OutputPluginData op_data = { | |
35 NULL, | |
36 NULL | |
37 }; | |
38 | |
39 OutputPlugin * | |
40 get_current_output_plugin(void) | |
41 { | |
42 return op_data.current_output_plugin; | |
43 } | |
44 | |
45 void | |
46 set_current_output_plugin(gint i) | |
47 { | |
48 #if 0 | |
49 gint time; | |
50 gint pos; | |
51 gboolean playing; | |
52 #endif | |
53 | |
54 GList *node = g_list_nth(op_data.output_list, i); | |
55 if (!node) { | |
56 op_data.current_output_plugin = NULL; | |
57 return; | |
58 } | |
59 | |
60 op_data.current_output_plugin = node->data; | |
61 | |
62 | |
63 #if 0 | |
64 playing = bmp_playback_get_playing(); | |
65 if (playing) { | |
66 | |
67 /* FIXME: we do all on our own here */ | |
68 | |
69 guint min = 0, sec = 0, params, time, pos; | |
70 gchar timestr[10]; | |
71 | |
72 bmp_playback_pause(); | |
73 pos = get_playlist_position(); | |
74 time = bmp_playback_get_time() / 1000; | |
75 g_snprintf(timestr, sizeof(timestr), "%u:%2.2u", | |
76 time / 60, time % 60); | |
77 | |
78 params = sscanf(timestr, "%u:%u", &min, &sec); | |
79 if (params == 2) | |
80 time = (min * 60) + sec; | |
81 else if (params == 1) | |
82 time = min; | |
83 else | |
84 return; | |
85 | |
86 bmp_playback_stop(); | |
87 playlist_set_position(pos); | |
88 bmp_playback_play_file(playlist_get_filename(pos)); | |
89 | |
90 while (!bmp_playback_get_playing()) | |
91 g_message("waiting..."); | |
92 | |
93 if (playlist_get_current_length() > -1 && | |
94 time <= (playlist_get_current_length() / 1000)) { | |
95 /* Some time for things to cool down and heat up */ | |
96 g_usleep(1000000); | |
97 bmp_playback_seek(time); | |
98 } | |
99 } | |
100 #endif | |
101 } | |
102 | |
103 GList * | |
104 get_output_list(void) | |
105 { | |
106 return op_data.output_list; | |
107 } | |
108 | |
109 void | |
110 output_about(gint i) | |
111 { | |
112 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
113 if (out && out->about) | |
114 out->about(); | |
115 } | |
116 | |
117 void | |
118 output_configure(gint i) | |
119 { | |
120 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
121 if (out && out->configure) | |
122 out->configure(); | |
123 } | |
124 | |
125 void | |
126 output_get_volume(gint * l, gint * r) | |
127 { | |
128 *l = *r = -1; | |
129 | |
130 if (!op_data.current_output_plugin) | |
131 return; | |
132 | |
133 if (!op_data.current_output_plugin->get_volume) | |
134 return; | |
135 | |
136 op_data.current_output_plugin->get_volume(l, r); | |
137 } | |
138 | |
139 void | |
140 output_set_volume(gint l, gint r) | |
141 { | |
142 if (!op_data.current_output_plugin) | |
143 return; | |
144 | |
145 if (!op_data.current_output_plugin->set_volume) | |
146 return; | |
147 | |
148 op_data.current_output_plugin->set_volume(l, r); | |
149 } | |
150 | |
151 void | |
152 output_set_eq(gboolean active, gfloat pre, gfloat * bands) | |
153 { | |
154 int i; | |
430
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
155 preamp[0] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
156 preamp[1] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
157 |
0 | 158 for (i = 0; i < 10; ++i) |
430
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
159 { |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
160 set_gain(i, 0, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
161 set_gain(i, 1, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
162 } |
0 | 163 } |
164 | |
165 /* this should be in BYTES, NOT gint16s */ | |
166 static void | |
167 byteswap(size_t size, | |
168 gint16 * buf) | |
169 { | |
170 gint16 *it; | |
171 size &= ~1; /* must be multiple of 2 */ | |
172 for (it = buf; it < buf + size / 2; ++it) | |
173 *(guint16 *) it = GUINT16_SWAP_LE_BE(*(guint16 *) it); | |
174 } | |
175 | |
176 /* called by input plugin when data is ready */ | |
177 void | |
178 produce_audio(gint time, /* position */ | |
179 AFormat fmt, /* output format */ | |
180 gint nch, /* channels */ | |
181 gint length, /* length of sample */ | |
182 gpointer ptr, /* data */ | |
183 int *going /* 0 when time to stop */ | |
184 ) | |
185 { | |
186 static int init = 0; | |
187 int swapped = 0; | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
519
diff
changeset
|
188 guint myorder = G_BYTE_ORDER == G_LITTLE_ENDIAN ? FMT_S16_LE : FMT_S16_BE; |
0 | 189 int caneq = (fmt == FMT_S16_NE || fmt == myorder); |
518 | 190 OutputPlugin *op = get_current_output_plugin(); |
0 | 191 |
192 if (!caneq && cfg.equalizer_active) { /* wrong byte order */ | |
193 byteswap(length, ptr); /* so convert */ | |
194 ++swapped; | |
195 ++caneq; | |
196 } /* can eq now, mark swapd */ | |
197 else if (caneq && !cfg.equalizer_active) /* right order but no eq */ | |
198 caneq = 0; /* so don't eq */ | |
199 | |
200 if (caneq) { /* if eq enab */ | |
201 if (!init) { /* if first run */ | |
202 init_iir(); /* then init eq */ | |
203 ++init; | |
204 } | |
205 | |
430
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
206 iir(&ptr, length, nch); |
0 | 207 |
208 if (swapped) /* if was swapped */ | |
209 byteswap(length, ptr); /* swap back for output */ | |
210 } | |
211 | |
518 | 212 /* do vis plugin(s) */ |
519
88e9a6a8336f
[svn] whoever wrote output_to_audio() was a crackhead.
nenolod
parents:
518
diff
changeset
|
213 input_add_vis_pcm(time, fmt, nch, length, ptr); |
0 | 214 |
518 | 215 while (op->buffer_free() < length) { /* wait output buf */ |
216 if (going && !*going) /* thread stopped? */ | |
217 return; /* so finish */ | |
218 | |
219 g_usleep(10000); /* else sleep for retry */ | |
220 } | |
221 | |
519
88e9a6a8336f
[svn] whoever wrote output_to_audio() was a crackhead.
nenolod
parents:
518
diff
changeset
|
222 op->write_audio(ptr, length); /* do output */ |
0 | 223 } |