Mercurial > audlegacy
annotate src/audacious/output.c @ 3753:22d71f986b86
export AudDRCT API.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sun, 14 Oct 2007 17:47:13 -0500 |
parents | a89a12aa4f2c |
children | bce5ac1f368b |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious team | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2813
diff
changeset
|
12 * the Free Software Foundation; under version 3 of the License. |
2313 | 13 * |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2813
diff
changeset
|
20 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
21 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
22 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
23 * Audacious or using our public API to be a derived work. |
2313 | 24 */ |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 # include "config.h" | |
28 #endif | |
29 | |
30 #include "output.h" | |
31 #include "iir.h" | |
32 #include "main.h" | |
33 #include "input.h" | |
2328 | 34 #include "playback.h" |
2313 | 35 |
36 #include "playlist.h" | |
2717 | 37 #include "configdb.h" |
2542 | 38 |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
39 #include "flow.h" |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
40 |
2811
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
41 #include "effect.h" |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
42 #include "volumecontrol.h" |
3559 | 43 #include "visualization.h" |
2811
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
44 |
2542 | 45 #include <math.h> |
46 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
47 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
48 #include <samplerate.h> |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
49 #endif |
2313 | 50 |
51 OutputPluginData op_data = { | |
52 NULL, | |
53 NULL | |
54 }; | |
55 | |
56 OutputPluginState op_state = { | |
57 0, | |
58 0, | |
59 0 | |
60 }; | |
61 | |
62 OutputPlugin psuedo_output_plugin = { | |
3549 | 63 .description = "XMMS reverse compatibility output plugin", |
64 .get_volume = output_get_volume, | |
65 .set_volume = output_set_volume, | |
66 | |
67 .open_audio = output_open_audio, | |
68 .write_audio = output_write_audio, | |
69 .close_audio = output_close_audio, | |
2313 | 70 |
3549 | 71 .flush = output_flush, |
72 .pause = output_pause, | |
73 | |
74 .buffer_free = output_buffer_free, | |
75 .buffer_playing = output_buffer_playing, | |
76 .output_time = get_output_time, | |
77 .written_time = get_written_time, | |
2313 | 78 }; |
79 | |
80 OutputPlugin * | |
81 get_current_output_plugin(void) | |
82 { | |
83 return op_data.current_output_plugin; | |
84 } | |
85 | |
86 void | |
87 set_current_output_plugin(gint i) | |
88 { | |
89 gboolean playing; | |
90 OutputPlugin *op = get_current_output_plugin(); | |
91 | |
92 GList *node = g_list_nth(op_data.output_list, i); | |
93 if (!node) { | |
94 op_data.current_output_plugin = NULL; | |
95 return; | |
96 } | |
97 | |
98 op_data.current_output_plugin = node->data; | |
99 | |
100 playing = playback_get_playing(); | |
101 | |
102 if (playing == TRUE) | |
103 { | |
104 guint time, pos; | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
105 PlaylistEntry *entry; |
2313 | 106 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
107 /* don't stop yet, get the seek time and playlist position first */ |
2313 | 108 pos = playlist_get_position(playlist_get_active()); |
109 time = op->output_time(); | |
110 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
111 /* reset the audio system */ |
2313 | 112 mainwin_stop_pushed(); |
113 op->close_audio(); | |
114 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
115 g_usleep(300000); |
2313 | 116 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
117 /* wait for the playback thread to come online */ |
2313 | 118 while (playback_get_playing()) |
119 g_message("waiting for audio system shutdown..."); | |
120 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
121 /* wait for the playback thread to come online */ |
2313 | 122 playlist_set_position(playlist_get_active(), pos); |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
123 entry = playlist_get_entry_to_play(playlist_get_active()); |
2313 | 124 playback_play_file(entry); |
125 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
126 while (!playback_get_playing()) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
127 { |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
128 gtk_main_iteration(); |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
129 g_message("waiting for audio system startup..."); |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
130 } |
2313 | 131 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
132 /* and signal a reseek */ |
2313 | 133 if (playlist_get_current_length(playlist_get_active()) > -1 && |
134 time <= (playlist_get_current_length(playlist_get_active()))) | |
135 playback_seek(time / 1000); | |
136 } | |
137 } | |
138 | |
139 GList * | |
140 get_output_list(void) | |
141 { | |
142 return op_data.output_list; | |
143 } | |
144 | |
145 void | |
146 output_about(gint i) | |
147 { | |
148 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
149 if (out && out->about) | |
150 out->about(); | |
151 } | |
152 | |
153 void | |
154 output_configure(gint i) | |
155 { | |
156 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
157 if (out && out->configure) | |
158 out->configure(); | |
159 } | |
160 | |
161 void | |
162 output_get_volume(gint * l, gint * r) | |
163 { | |
164 *l = *r = -1; | |
165 | |
166 if (!op_data.current_output_plugin) | |
167 return; | |
168 | |
169 if (!op_data.current_output_plugin->get_volume) | |
170 return; | |
171 | |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
172 if (cfg.software_volume_control) |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
173 volumecontrol_get_volume_state(l, r); |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
174 else |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
175 op_data.current_output_plugin->get_volume(l, r); |
2313 | 176 } |
177 | |
178 void | |
179 output_set_volume(gint l, gint r) | |
180 { | |
181 if (!op_data.current_output_plugin) | |
182 return; | |
183 | |
184 if (!op_data.current_output_plugin->set_volume) | |
185 return; | |
186 | |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
187 if (cfg.software_volume_control) |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
188 volumecontrol_set_volume_state(l, r); |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
189 else |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
190 op_data.current_output_plugin->set_volume(l, r); |
2313 | 191 } |
192 | |
193 void | |
194 output_set_eq(gboolean active, gfloat pre, gfloat * bands) | |
195 { | |
196 int i; | |
197 preamp[0] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
198 preamp[1] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
199 | |
200 for (i = 0; i < 10; ++i) | |
201 { | |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
202 set_gain(i, 0, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
203 set_gain(i, 1, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
2313 | 204 } |
205 } | |
206 | |
207 /* called by input plugin to peek at the output plugin's write progress */ | |
208 gint | |
209 get_written_time(void) | |
210 { | |
211 OutputPlugin *op = get_current_output_plugin(); | |
212 | |
213 return op->written_time(); | |
214 } | |
215 | |
216 /* called by input plugin to peek at the output plugin's output progress */ | |
217 gint | |
218 get_output_time(void) | |
219 { | |
220 OutputPlugin *op = get_current_output_plugin(); | |
221 | |
222 return op->output_time(); | |
223 } | |
224 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
225 #ifdef USE_SRC |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
226 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
227 static SRC_STATE *src_state; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
228 static SRC_DATA src_data; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
229 static int overSamplingFs = 96000; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
230 static int converter_type = SRC_SINC_BEST_QUALITY; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
231 static int srcError = 0; |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
232 |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
233 static float *srcIn = NULL, *srcOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
234 static short int *wOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
235 static int lengthOfSrcIn = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
236 static int lengthOfSrcOut = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
237 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
238 static void freeSRC() |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
239 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
240 if(src_state != NULL) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
241 src_state = src_delete(src_state); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
242 free(srcIn); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
243 free(srcOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
244 free(wOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
245 srcIn = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
246 srcOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
247 wOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
248 lengthOfSrcIn = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
249 lengthOfSrcOut = 0; |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
250 } |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
251 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
252 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
253 |
2313 | 254 gint |
255 output_open_audio(AFormat fmt, gint rate, gint nch) | |
256 { | |
257 gint ret; | |
258 OutputPlugin *op; | |
259 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
260 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
261 ConfigDb *db; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
262 gboolean src_enabled; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
263 gint src_rate, src_type; |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
264 db = cfg_db_open(); |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
265 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
266 if (cfg_db_get_bool(db, NULL, "enable_src", &src_enabled) == FALSE) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
267 src_enabled = FALSE; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
268 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
269 if (cfg_db_get_int(db, NULL, "src_rate", &src_rate) == FALSE) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
270 overSamplingFs = 48000; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
271 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
272 overSamplingFs = src_rate; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
273 |
2649
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
274 /* don't resample if sampling rates are the same --nenolod */ |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
275 if (rate == overSamplingFs) |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
276 src_enabled = FALSE; |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
277 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
278 if (cfg_db_get_int(db, NULL, "src_type", &src_type) == FALSE) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
279 converter_type = SRC_SINC_BEST_QUALITY; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
280 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
281 converter_type = src_type; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
282 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
283 cfg_db_close(db); |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
284 |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
285 freeSRC(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
286 |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
287 if(src_enabled&& |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
288 (fmt == FMT_S16_NE||(fmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN)|| |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
289 (fmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN))) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
290 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
291 src_state = src_new(converter_type, nch, &srcError); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
292 if (src_state != NULL) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
293 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
294 src_data.src_ratio = (float)overSamplingFs/(float)rate; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
295 rate = overSamplingFs; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
296 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
297 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
298 fprintf(stderr, "src_new(): %s\n\n", src_strerror(srcError)); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
299 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
300 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
301 |
2313 | 302 op = get_current_output_plugin(); |
303 | |
304 if (op == NULL) | |
305 return -1; | |
306 | |
307 /* Is our output port already open? */ | |
308 if ((op_state.rate != 0 && op_state.nch != 0) && | |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
309 (op_state.rate == rate && op_state.nch == nch && op_state.fmt == fmt)) |
2313 | 310 { |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
311 /* Yes, and it's the correct sampling rate. Reset the counter and go. */ |
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
312 op->flush(0); |
2313 | 313 return 1; |
314 } | |
315 else if (op_state.rate != 0 && op_state.nch != 0) | |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
316 op->close_audio(); |
2313 | 317 |
318 ret = op->open_audio(fmt, rate, nch); | |
319 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
320 if (ret == 1) /* Success? */ |
2313 | 321 { |
322 op_state.fmt = fmt; | |
323 op_state.rate = rate; | |
324 op_state.nch = nch; | |
325 } | |
326 | |
327 return ret; | |
328 } | |
329 | |
330 void | |
331 output_write_audio(gpointer ptr, gint length) | |
332 { | |
333 OutputPlugin *op = get_current_output_plugin(); | |
334 | |
335 /* Sanity check. */ | |
336 if (op == NULL) | |
337 return; | |
338 | |
339 op->write_audio(ptr, length); | |
340 } | |
341 | |
342 void | |
343 output_close_audio(void) | |
344 { | |
345 OutputPlugin *op = get_current_output_plugin(); | |
346 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
347 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
348 freeSRC(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
349 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
350 |
2313 | 351 /* Do not close if there are still songs to play and the user has |
352 * not requested a stop. --nenolod | |
353 */ | |
354 if (ip_data.stop == FALSE && | |
2673 | 355 (playlist_get_position_nolock(playlist_get_active()) < |
356 playlist_get_length(playlist_get_active()) - 1)) | |
2313 | 357 return; |
358 | |
359 /* Sanity check. */ | |
360 if (op == NULL) | |
361 return; | |
362 | |
363 op->close_audio(); | |
364 | |
365 /* Reset the op_state. */ | |
366 op_state.fmt = op_state.rate = op_state.nch = 0; | |
367 } | |
368 | |
369 void | |
370 output_flush(gint time) | |
371 { | |
372 OutputPlugin *op = get_current_output_plugin(); | |
373 | |
374 if (op == NULL) | |
375 return; | |
376 | |
377 op->flush(time); | |
378 } | |
379 | |
380 void | |
381 output_pause(gshort paused) | |
382 { | |
383 OutputPlugin *op = get_current_output_plugin(); | |
384 | |
385 if (op == NULL) | |
386 return; | |
387 | |
388 op->pause(paused); | |
389 } | |
390 | |
391 gint | |
392 output_buffer_free(void) | |
393 { | |
394 OutputPlugin *op = get_current_output_plugin(); | |
395 | |
396 if (op == NULL) | |
397 return 0; | |
398 | |
399 return op->buffer_free(); | |
400 } | |
401 | |
402 gint | |
403 output_buffer_playing(void) | |
404 { | |
405 OutputPlugin *op = get_current_output_plugin(); | |
406 | |
407 if (op == NULL) | |
408 return 0; | |
409 | |
410 return op->buffer_playing(); | |
411 } | |
412 | |
413 /* called by input plugin when data is ready */ | |
414 void | |
3709
a89a12aa4f2c
Add InputPlayback::pass_audio() which replaces produce_audio().
William Pitcock <nenolod@atheme.org>
parents:
3708
diff
changeset
|
415 output_pass_audio(InputPlayback *playback, |
3696
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
416 AFormat fmt, /* output format */ |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
417 gint nch, /* channels */ |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
418 gint length, /* length of sample */ |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
419 gpointer ptr, /* data */ |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
420 int *going /* 0 when time to stop */ |
2313 | 421 ) |
422 { | |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
423 static Flow *postproc_flow = NULL; |
3696
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
424 OutputPlugin *op = playback->output; |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
425 gint writeoffs; |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
426 gint time = playback->output->written_time(); |
2313 | 427 |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
428 if (postproc_flow == NULL) |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
429 { |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
430 postproc_flow = flow_new(); |
3560
154f21dcd61e
equalizer -> flow API
William Pitcock <nenolod@atheme.org>
parents:
3559
diff
changeset
|
431 flow_link_element(postproc_flow, iir_flow); |
3555
a73951b8cd9f
effect processing -> flow manager API / attached to postproc_flow.
William Pitcock <nenolod@atheme.org>
parents:
3553
diff
changeset
|
432 flow_link_element(postproc_flow, effect_flow); |
3559 | 433 flow_link_element(postproc_flow, vis_flow); |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
434 flow_link_element(postproc_flow, volumecontrol_flow); |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
435 } |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
436 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
437 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
438 if(src_state != NULL&&length > 0) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
439 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
440 int lrLength = length/2; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
441 int overLrLength = (int)floor(lrLength*(src_data.src_ratio+1)); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
442 if(lengthOfSrcIn < lrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
443 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
444 lengthOfSrcIn = lrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
445 free(srcIn); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
446 srcIn = (float*)malloc(sizeof(float)*lrLength); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
447 } |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
448 if(lengthOfSrcOut < overLrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
449 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
450 lengthOfSrcOut = overLrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
451 free(srcOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
452 free(wOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
453 srcOut = (float*)malloc(sizeof(float)*overLrLength); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
454 wOut = (short int*)malloc(sizeof(short int)*overLrLength); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
455 } |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
456 src_short_to_float_array((short int*)ptr, srcIn, lrLength); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
457 src_data.data_in = srcIn; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
458 src_data.data_out = srcOut; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
459 src_data.end_of_input = 0; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
460 src_data.input_frames = lrLength/2; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
461 src_data.output_frames = overLrLength/2; |
2542 | 462 if ((srcError = src_process(src_state, &src_data)) > 0) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
463 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
464 fprintf(stderr, "src_process(): %s\n", src_strerror(srcError)); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
465 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
466 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
467 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
468 src_float_to_short_array(srcOut, wOut, src_data.output_frames_gen*2); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
469 ptr = wOut; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
470 length = src_data.output_frames_gen*4; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
471 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
472 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
473 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
474 |
3708
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3696
diff
changeset
|
475 length = flow_execute(postproc_flow, time, &ptr, length, op_state.fmt, op_state.rate, op_state.nch); |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
476 |
2313 | 477 writeoffs = 0; |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
478 while (writeoffs < length) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
479 { |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
480 int writable = length - writeoffs; |
2313 | 481 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
482 if (writable > 2048) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
483 writable = 2048; |
2313 | 484 |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
485 if (writable == 0) |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
486 return; |
2313 | 487 |
3486
96baf555b449
Get rid of "XMMS Multiple Effect Plugin support" hack. Effects processing is handled in produce_audio() now days.
William Pitcock <nenolod@atheme.org>
parents:
3437
diff
changeset
|
488 while (op->buffer_free() < writable) /* wait output buf */ |
96baf555b449
Get rid of "XMMS Multiple Effect Plugin support" hack. Effects processing is handled in produce_audio() now days.
William Pitcock <nenolod@atheme.org>
parents:
3437
diff
changeset
|
489 { |
3696
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
490 GTimeVal pb_abs_time; |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
491 |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
492 g_get_current_time(&pb_abs_time); |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
493 g_time_val_add(&pb_abs_time, (cfg.output_buffer_size / 2) * 1000); |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
494 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
495 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
496 return; /* so finish */ |
2313 | 497 |
3486
96baf555b449
Get rid of "XMMS Multiple Effect Plugin support" hack. Effects processing is handled in produce_audio() now days.
William Pitcock <nenolod@atheme.org>
parents:
3437
diff
changeset
|
498 if (ip_data.stop) /* has a stop been requested? */ |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
499 return; /* yes, so finish */ |
2313 | 500 |
3680
6615978ca88c
Instead of waiting 10ms, wait half the time of the period buffer.
William Pitcock <nenolod@atheme.org>
parents:
3560
diff
changeset
|
501 /* else sleep for retry */ |
3696
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
502 g_mutex_lock(playback->pb_change_mutex); |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
503 g_cond_timed_wait(playback->pb_change_cond, playback->pb_change_mutex, &pb_abs_time); |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
504 g_mutex_unlock(playback->pb_change_mutex); |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
505 } |
2313 | 506 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
507 if (ip_data.stop) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
508 return; |
2313 | 509 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
510 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
511 return; /* so finish */ |
2313 | 512 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
513 /* do output */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
514 op->write_audio(((guint8 *) ptr) + writeoffs, writable); |
2313 | 515 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
516 writeoffs += writable; |
2313 | 517 } |
518 } |