Mercurial > audlegacy
annotate src/audacious/output.c @ 4234:b293ce14a01a
partially works...
author | Eugene Zagidullin <e.asphyx@gmail.com> |
---|---|
date | Thu, 31 Jan 2008 12:04:13 +0300 |
parents | 833e5faa5847 |
children | 2d4b4f13d10d |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
4234 | 2 * Copyright (C) 2005-2008 Audacious team |
2313 | 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 | |
4234 | 26 #define AUD_DEBUG |
27 | |
2313 | 28 #ifdef HAVE_CONFIG_H |
29 # include "config.h" | |
30 #endif | |
31 | |
32 #include "output.h" | |
33 #include "iir.h" | |
34 #include "main.h" | |
35 #include "input.h" | |
2328 | 36 #include "playback.h" |
2313 | 37 |
38 #include "playlist.h" | |
2717 | 39 #include "configdb.h" |
2542 | 40 |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
41 #include "flow.h" |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
42 |
2811
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
43 #include "effect.h" |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
44 #include "volumecontrol.h" |
3559 | 45 #include "visualization.h" |
2811
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
46 |
4234 | 47 #include "libSAD.h" |
48 | |
2542 | 49 #include <math.h> |
50 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
51 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
52 #include <samplerate.h> |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
53 #endif |
2313 | 54 |
55 OutputPluginData op_data = { | |
56 NULL, | |
57 NULL | |
58 }; | |
59 | |
60 OutputPluginState op_state = { | |
61 0, | |
62 0, | |
63 0 | |
64 }; | |
65 | |
66 OutputPlugin psuedo_output_plugin = { | |
3549 | 67 .description = "XMMS reverse compatibility output plugin", |
68 .get_volume = output_get_volume, | |
69 .set_volume = output_set_volume, | |
70 | |
71 .open_audio = output_open_audio, | |
72 .write_audio = output_write_audio, | |
73 .close_audio = output_close_audio, | |
2313 | 74 |
3549 | 75 .flush = output_flush, |
76 .pause = output_pause, | |
77 | |
78 .buffer_free = output_buffer_free, | |
79 .buffer_playing = output_buffer_playing, | |
80 .output_time = get_output_time, | |
81 .written_time = get_written_time, | |
2313 | 82 }; |
83 | |
4234 | 84 static const struct { |
85 AFormat afmt; | |
86 SAD_sample_format sadfmt; | |
87 } format_table[] = { | |
88 {FMT_U8, SAD_SAMPLE_U8}, | |
89 {FMT_S8, SAD_SAMPLE_S8}, | |
90 | |
91 {FMT_S16_LE, SAD_SAMPLE_S16_LE}, | |
92 {FMT_S16_BE, SAD_SAMPLE_S16_BE}, | |
93 {FMT_S16_NE, SAD_SAMPLE_S16}, | |
94 | |
95 {FMT_U16_LE, SAD_SAMPLE_U16_LE}, | |
96 {FMT_U16_BE, SAD_SAMPLE_U16_BE}, | |
97 {FMT_U16_NE, SAD_SAMPLE_U16}, | |
98 | |
99 {FMT_S24_LE, SAD_SAMPLE_S24_LE}, | |
100 {FMT_S24_BE, SAD_SAMPLE_S24_BE}, | |
101 {FMT_S24_NE, SAD_SAMPLE_S24}, | |
102 | |
103 {FMT_U24_LE, SAD_SAMPLE_U24_LE}, | |
104 {FMT_U24_BE, SAD_SAMPLE_U24_BE}, | |
105 {FMT_U24_NE, SAD_SAMPLE_U24}, | |
106 | |
107 {FMT_S32_LE, SAD_SAMPLE_S32_LE}, | |
108 {FMT_S32_BE, SAD_SAMPLE_S32_BE}, | |
109 {FMT_S32_NE, SAD_SAMPLE_S32}, | |
110 | |
111 {FMT_U32_LE, SAD_SAMPLE_U32_LE}, | |
112 {FMT_U32_BE, SAD_SAMPLE_U32_BE}, | |
113 {FMT_U32_NE, SAD_SAMPLE_U32}, | |
114 | |
115 {FMT_FLOAT, SAD_SAMPLE_FLOAT}, | |
116 }; | |
117 | |
118 static inline unsigned sample_size(AFormat fmt) { | |
119 switch(fmt) { | |
120 case FMT_S8: | |
121 case FMT_U8: return sizeof(gint8); | |
122 case FMT_S16_NE: | |
123 case FMT_S16_LE: | |
124 case FMT_S16_BE: | |
125 case FMT_U16_NE: | |
126 case FMT_U16_LE: | |
127 case FMT_U16_BE: return sizeof(gint16); | |
128 case FMT_S24_NE: | |
129 case FMT_S24_LE: | |
130 case FMT_S24_BE: | |
131 case FMT_U24_NE: | |
132 case FMT_U24_LE: | |
133 case FMT_U24_BE: | |
134 case FMT_S32_NE: | |
135 case FMT_S32_LE: | |
136 case FMT_S32_BE: | |
137 case FMT_U32_NE: | |
138 case FMT_U32_LE: | |
139 case FMT_U32_BE: return sizeof(gint32); | |
140 case FMT_FLOAT: return sizeof(float); | |
141 default: return 0; | |
142 } | |
143 } | |
144 | |
145 static SAD_sample_format | |
146 sadfmt_from_afmt(AFormat fmt) | |
147 { | |
148 int i; | |
149 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++) { | |
150 if (format_table[i].afmt == fmt) return format_table[i].sadfmt; | |
151 } | |
152 | |
153 return -1; | |
154 } | |
155 | |
2313 | 156 OutputPlugin * |
157 get_current_output_plugin(void) | |
158 { | |
159 return op_data.current_output_plugin; | |
160 } | |
161 | |
162 void | |
163 set_current_output_plugin(gint i) | |
164 { | |
165 gboolean playing; | |
166 OutputPlugin *op = get_current_output_plugin(); | |
167 | |
168 GList *node = g_list_nth(op_data.output_list, i); | |
169 if (!node) { | |
170 op_data.current_output_plugin = NULL; | |
171 return; | |
172 } | |
173 | |
174 op_data.current_output_plugin = node->data; | |
175 | |
176 playing = playback_get_playing(); | |
177 | |
178 if (playing == TRUE) | |
179 { | |
180 guint time, pos; | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
181 PlaylistEntry *entry; |
2313 | 182 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
183 /* don't stop yet, get the seek time and playlist position first */ |
2313 | 184 pos = playlist_get_position(playlist_get_active()); |
185 time = op->output_time(); | |
186 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
187 /* reset the audio system */ |
2313 | 188 mainwin_stop_pushed(); |
189 op->close_audio(); | |
190 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
191 g_usleep(300000); |
2313 | 192 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
193 /* wait for the playback thread to come online */ |
2313 | 194 while (playback_get_playing()) |
195 g_message("waiting for audio system shutdown..."); | |
196 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
197 /* wait for the playback thread to come online */ |
2313 | 198 playlist_set_position(playlist_get_active(), pos); |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
199 entry = playlist_get_entry_to_play(playlist_get_active()); |
2313 | 200 playback_play_file(entry); |
201 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
202 while (!playback_get_playing()) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
203 { |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
204 gtk_main_iteration(); |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
205 g_message("waiting for audio system startup..."); |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
206 } |
2313 | 207 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
208 /* and signal a reseek */ |
2313 | 209 if (playlist_get_current_length(playlist_get_active()) > -1 && |
210 time <= (playlist_get_current_length(playlist_get_active()))) | |
211 playback_seek(time / 1000); | |
212 } | |
213 } | |
214 | |
215 GList * | |
216 get_output_list(void) | |
217 { | |
218 return op_data.output_list; | |
219 } | |
220 | |
221 void | |
222 output_about(gint i) | |
223 { | |
224 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
225 if (out && out->about) | |
226 out->about(); | |
227 } | |
228 | |
229 void | |
230 output_configure(gint i) | |
231 { | |
232 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
233 if (out && out->configure) | |
234 out->configure(); | |
235 } | |
236 | |
237 void | |
238 output_get_volume(gint * l, gint * r) | |
239 { | |
240 *l = *r = -1; | |
241 | |
242 if (!op_data.current_output_plugin) | |
243 return; | |
244 | |
245 if (!op_data.current_output_plugin->get_volume) | |
246 return; | |
247 | |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
248 if (cfg.software_volume_control) |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
249 volumecontrol_get_volume_state(l, r); |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
250 else |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
251 op_data.current_output_plugin->get_volume(l, r); |
2313 | 252 } |
253 | |
254 void | |
255 output_set_volume(gint l, gint r) | |
256 { | |
257 if (!op_data.current_output_plugin) | |
258 return; | |
259 | |
260 if (!op_data.current_output_plugin->set_volume) | |
261 return; | |
262 | |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
263 if (cfg.software_volume_control) |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
264 volumecontrol_set_volume_state(l, r); |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
265 else |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
266 op_data.current_output_plugin->set_volume(l, r); |
2313 | 267 } |
268 | |
269 void | |
270 output_set_eq(gboolean active, gfloat pre, gfloat * bands) | |
271 { | |
272 int i; | |
273 preamp[0] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
274 preamp[1] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
275 | |
276 for (i = 0; i < 10; ++i) | |
277 { | |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
278 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
|
279 set_gain(i, 1, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
2313 | 280 } |
281 } | |
282 | |
283 /* called by input plugin to peek at the output plugin's write progress */ | |
284 gint | |
285 get_written_time(void) | |
286 { | |
287 OutputPlugin *op = get_current_output_plugin(); | |
288 | |
289 return op->written_time(); | |
290 } | |
291 | |
292 /* called by input plugin to peek at the output plugin's output progress */ | |
293 gint | |
294 get_output_time(void) | |
295 { | |
296 OutputPlugin *op = get_current_output_plugin(); | |
297 | |
298 return op->output_time(); | |
299 } | |
300 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
301 #ifdef USE_SRC |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
302 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
303 static SRC_STATE *src_state; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
304 static SRC_DATA src_data; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
305 static int overSamplingFs = 96000; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
306 static int converter_type = SRC_SINC_BEST_QUALITY; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
307 static int srcError = 0; |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
308 |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
309 static float *srcIn = NULL, *srcOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
310 static short int *wOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
311 static int lengthOfSrcIn = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
312 static int lengthOfSrcOut = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
313 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
314 static void freeSRC() |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
315 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
316 if(src_state != NULL) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
317 src_state = src_delete(src_state); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
318 free(srcIn); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
319 free(srcOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
320 free(wOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
321 srcIn = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
322 srcOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
323 wOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
324 lengthOfSrcIn = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
325 lengthOfSrcOut = 0; |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
326 } |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
327 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
328 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
329 |
4234 | 330 static SAD_dither_t *sad_state = NULL; |
331 static SAD_dither_t *sad_state_to_float = NULL; | |
332 static SAD_dither_t *sad_state_from_float = NULL; | |
333 static void *sad_out_buf = NULL; | |
334 static int sad_out_buf_length = 0; | |
335 | |
336 static void | |
337 freeSAD() | |
338 { | |
339 if (sad_state != NULL) {SAD_dither_free(sad_state); sad_state = NULL;} | |
340 if (sad_state_from_float != NULL) {SAD_dither_free(sad_state_from_float); sad_state_from_float = NULL;} | |
341 if (sad_state_to_float != NULL) {SAD_dither_free(sad_state_to_float); sad_state_to_float = NULL;} | |
342 if (sad_out_buf != NULL) {free(sad_out_buf); sad_out_buf = NULL; sad_out_buf_length = 0;} | |
343 } | |
344 | |
2313 | 345 gint |
346 output_open_audio(AFormat fmt, gint rate, gint nch) | |
347 { | |
348 gint ret; | |
349 OutputPlugin *op; | |
4234 | 350 ConfigDb *db; |
351 AUDDBG("\n"); | |
352 | |
353 AFormat output_fmt; | |
354 int bit_depth; | |
355 SAD_buffer_format input_sad_fmt; | |
356 SAD_buffer_format output_sad_fmt; | |
2313 | 357 |
4234 | 358 db = cfg_db_open(); |
359 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
360 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
361 gboolean src_enabled; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
362 gint src_rate, src_type; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
363 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
364 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
|
365 src_enabled = FALSE; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
366 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
367 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
|
368 overSamplingFs = 48000; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
369 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
370 overSamplingFs = src_rate; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
371 |
2649
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
372 /* 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
|
373 if (rate == overSamplingFs) |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
374 src_enabled = FALSE; |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
375 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
376 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
|
377 converter_type = SRC_SINC_BEST_QUALITY; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
378 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
379 converter_type = src_type; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
380 |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
381 freeSRC(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
382 |
4234 | 383 if(src_enabled) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
384 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
385 src_state = src_new(converter_type, nch, &srcError); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
386 if (src_state != NULL) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
387 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
388 src_data.src_ratio = (float)overSamplingFs/(float)rate; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
389 rate = overSamplingFs; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
390 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
391 else |
4234 | 392 { |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
393 fprintf(stderr, "src_new(): %s\n\n", src_strerror(srcError)); |
4234 | 394 src_enabled = FALSE; |
395 } | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
396 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
397 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
398 |
4234 | 399 if (cfg_db_get_int(db, NULL, "output_bit_depth", &bit_depth) == FALSE) bit_depth = 16; |
400 cfg_db_close(db); | |
401 | |
402 AUDDBG("bit depth: %d\n", bit_depth); | |
403 output_fmt = (bit_depth == 24) ? FMT_S24_NE : FMT_S16_NE; /* no reason to support other output formats --asphyx */ | |
404 | |
405 freeSAD(); | |
406 | |
407 #ifdef USE_SRC | |
408 if (src_enabled) { | |
409 AUDDBG("initializing dithering engine for 2 stage conversion\n"); | |
410 input_sad_fmt.sample_format = sadfmt_from_afmt(fmt); | |
411 if (input_sad_fmt.sample_format < 0) return -1; | |
412 input_sad_fmt.fracbits = 0; | |
413 input_sad_fmt.channels = nch; | |
414 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
415 input_sad_fmt.samplerate = 0; | |
416 | |
417 output_sad_fmt.sample_format = SAD_SAMPLE_FLOAT; | |
418 output_sad_fmt.fracbits = 0; | |
419 output_sad_fmt.channels = nch; | |
420 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
421 output_sad_fmt.samplerate = 0; | |
422 | |
423 sad_state_to_float = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); | |
424 if (sad_state_to_float == NULL) { | |
425 AUDDBG("ditherer init failed (decoder's native --> float)\n"); | |
426 return -1; | |
427 } | |
428 SAD_dither_set_dither (sad_state_to_float, FALSE); | |
429 | |
430 input_sad_fmt.sample_format = SAD_SAMPLE_FLOAT; | |
431 input_sad_fmt.fracbits = 0; | |
432 input_sad_fmt.channels = nch; | |
433 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
434 input_sad_fmt.samplerate = 0; | |
435 | |
436 output_sad_fmt.sample_format = sadfmt_from_afmt(output_fmt); | |
437 if (output_sad_fmt.sample_format < 0) return -1; | |
438 output_sad_fmt.fracbits = 0; | |
439 output_sad_fmt.channels = nch; | |
440 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
441 output_sad_fmt.samplerate = 0; | |
442 | |
443 sad_state_from_float = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); | |
444 if (sad_state_from_float == NULL) { | |
445 SAD_dither_free(sad_state_to_float); | |
446 AUDDBG("ditherer init failed (float --> output)\n"); | |
447 return -1; | |
448 } | |
449 SAD_dither_set_dither (sad_state_from_float, TRUE); | |
450 | |
451 fmt = output_fmt; | |
452 } else | |
453 #endif /* USE_SRC */ | |
454 if (output_fmt != fmt) { | |
455 AUDDBG("initializing dithering engine for direct conversion\n"); | |
456 | |
457 input_sad_fmt.sample_format = sadfmt_from_afmt(fmt); | |
458 if (input_sad_fmt.sample_format < 0) return -1; | |
459 input_sad_fmt.fracbits = 0; | |
460 input_sad_fmt.channels = nch; | |
461 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
462 input_sad_fmt.samplerate = 0; /* resampling not implemented yet in libSAD */ | |
463 | |
464 output_sad_fmt.sample_format = sadfmt_from_afmt(output_fmt); | |
465 output_sad_fmt.fracbits = 0; | |
466 output_sad_fmt.channels = nch; | |
467 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
468 output_sad_fmt.samplerate = 0; | |
469 | |
470 sad_state = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); | |
471 if (sad_state == NULL) { | |
472 AUDDBG("ditherer init failed\n"); | |
473 return -1; | |
474 } | |
475 SAD_dither_set_dither (sad_state, TRUE); | |
476 | |
477 fmt = output_fmt; | |
478 } | |
479 | |
2313 | 480 op = get_current_output_plugin(); |
481 | |
482 if (op == NULL) | |
483 return -1; | |
484 | |
485 /* Is our output port already open? */ | |
486 if ((op_state.rate != 0 && op_state.nch != 0) && | |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
487 (op_state.rate == rate && op_state.nch == nch && op_state.fmt == fmt)) |
2313 | 488 { |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
489 /* 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
|
490 op->flush(0); |
2313 | 491 return 1; |
492 } | |
493 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
|
494 op->close_audio(); |
2313 | 495 |
496 ret = op->open_audio(fmt, rate, nch); | |
497 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
498 if (ret == 1) /* Success? */ |
2313 | 499 { |
4234 | 500 AUDDBG("opened audio: fmt=%d, rate=%d, nch=%d\n", fmt, rate, nch); |
2313 | 501 op_state.fmt = fmt; |
502 op_state.rate = rate; | |
503 op_state.nch = nch; | |
504 } | |
505 | |
506 return ret; | |
507 } | |
508 | |
509 void | |
510 output_write_audio(gpointer ptr, gint length) | |
511 { | |
512 OutputPlugin *op = get_current_output_plugin(); | |
513 | |
514 /* Sanity check. */ | |
515 if (op == NULL) | |
516 return; | |
517 | |
518 op->write_audio(ptr, length); | |
519 } | |
520 | |
521 void | |
522 output_close_audio(void) | |
523 { | |
524 OutputPlugin *op = get_current_output_plugin(); | |
525 | |
4234 | 526 AUDDBG("\n"); |
527 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
528 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
529 freeSRC(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
530 #endif |
4234 | 531 freeSAD(); |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
532 |
2313 | 533 /* Do not close if there are still songs to play and the user has |
534 * not requested a stop. --nenolod | |
535 */ | |
536 if (ip_data.stop == FALSE && | |
2673 | 537 (playlist_get_position_nolock(playlist_get_active()) < |
538 playlist_get_length(playlist_get_active()) - 1)) | |
2313 | 539 return; |
540 | |
541 /* Sanity check. */ | |
542 if (op == NULL) | |
543 return; | |
544 | |
545 op->close_audio(); | |
546 | |
547 /* Reset the op_state. */ | |
548 op_state.fmt = op_state.rate = op_state.nch = 0; | |
549 } | |
550 | |
551 void | |
552 output_flush(gint time) | |
553 { | |
554 OutputPlugin *op = get_current_output_plugin(); | |
555 | |
556 if (op == NULL) | |
557 return; | |
558 | |
559 op->flush(time); | |
560 } | |
561 | |
562 void | |
563 output_pause(gshort paused) | |
564 { | |
565 OutputPlugin *op = get_current_output_plugin(); | |
566 | |
567 if (op == NULL) | |
568 return; | |
569 | |
570 op->pause(paused); | |
571 } | |
572 | |
573 gint | |
574 output_buffer_free(void) | |
575 { | |
576 OutputPlugin *op = get_current_output_plugin(); | |
577 | |
578 if (op == NULL) | |
579 return 0; | |
580 | |
581 return op->buffer_free(); | |
582 } | |
583 | |
584 gint | |
585 output_buffer_playing(void) | |
586 { | |
587 OutputPlugin *op = get_current_output_plugin(); | |
588 | |
589 if (op == NULL) | |
590 return 0; | |
591 | |
592 return op->buffer_playing(); | |
593 } | |
594 | |
595 /* called by input plugin when data is ready */ | |
596 void | |
3709
a89a12aa4f2c
Add InputPlayback::pass_audio() which replaces produce_audio().
William Pitcock <nenolod@atheme.org>
parents:
3708
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 int *going /* 0 when time to stop */ |
2313 | 603 ) |
604 { | |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
605 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
|
606 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
|
607 gint writeoffs; |
4234 | 608 |
609 if (length <= 0) return; | |
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
|
610 gint time = playback->output->written_time(); |
2313 | 611 |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
612 if (postproc_flow == NULL) |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
613 { |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
614 postproc_flow = flow_new(); |
3560
154f21dcd61e
equalizer -> flow API
William Pitcock <nenolod@atheme.org>
parents:
3559
diff
changeset
|
615 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
|
616 flow_link_element(postproc_flow, effect_flow); |
3559 | 617 flow_link_element(postproc_flow, vis_flow); |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
618 flow_link_element(postproc_flow, volumecontrol_flow); |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
619 } |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
620 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
621 #ifdef USE_SRC |
4234 | 622 if(src_state != NULL) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
623 { |
4234 | 624 /*int lrLength = length / nch;*/ |
625 int lrLength = length / sample_size(fmt); | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
626 int overLrLength = (int)floor(lrLength*(src_data.src_ratio+1)); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
627 if(lengthOfSrcIn < lrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
628 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
629 lengthOfSrcIn = lrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
630 free(srcIn); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
631 srcIn = (float*)malloc(sizeof(float)*lrLength); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
632 } |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
633 if(lengthOfSrcOut < overLrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
634 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
635 lengthOfSrcOut = overLrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
636 free(srcOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
637 free(wOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
638 srcOut = (float*)malloc(sizeof(float)*overLrLength); |
4234 | 639 wOut = (short int*)malloc(sample_size(op_state.fmt) * overLrLength); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
640 } |
4234 | 641 /*src_short_to_float_array((short int*)ptr, srcIn, lrLength);*/ |
642 SAD_dither_process_buffer(sad_state_to_float, ptr, srcIn, lrLength / nch); | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
643 src_data.data_in = srcIn; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
644 src_data.data_out = srcOut; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
645 src_data.end_of_input = 0; |
4186
833e5faa5847
Make sample rate conversion work with mono files. (Bugzilla #88)
William Pitcock <nenolod@atheme.org>
parents:
3984
diff
changeset
|
646 src_data.input_frames = lrLength / nch; |
833e5faa5847
Make sample rate conversion work with mono files. (Bugzilla #88)
William Pitcock <nenolod@atheme.org>
parents:
3984
diff
changeset
|
647 src_data.output_frames = overLrLength / nch; |
2542 | 648 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
|
649 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
650 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
|
651 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
652 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
653 { |
4234 | 654 /*src_float_to_short_array(srcOut, wOut, src_data.output_frames_gen*2);*/ |
655 SAD_dither_process_buffer(sad_state_from_float, srcOut, wOut, src_data.output_frames_gen); | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
656 ptr = wOut; |
4234 | 657 length = src_data.output_frames_gen * op_state.nch * sample_size(op_state.fmt); |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
658 } |
4234 | 659 } else |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
660 #endif |
4234 | 661 if(sad_state != NULL) { |
662 int frames = length / nch / sample_size(fmt); | |
663 int len = frames * op_state.nch * sample_size(op_state.fmt); | |
664 if(sad_out_buf == NULL || sad_out_buf_length < len ) { | |
665 if(sad_out_buf != NULL) free (sad_out_buf); | |
666 sad_out_buf = malloc(len); | |
667 sad_out_buf_length = len; | |
668 } | |
669 SAD_dither_process_buffer(sad_state, ptr, sad_out_buf, frames); | |
670 ptr = sad_out_buf; | |
671 } | |
672 | |
673 if (op_state.fmt == FMT_S16_NE || (op_state.fmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN) || | |
674 (op_state.fmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN)) { | |
675 length = flow_execute(postproc_flow, time, &ptr, length, op_state.fmt, op_state.rate, op_state.nch); | |
676 } else { | |
677 AUDDBG("postproc_flow can deal only with S16_NE streams\n"); /*FIXME*/ | |
678 } | |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
679 |
2313 | 680 writeoffs = 0; |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
681 while (writeoffs < length) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
682 { |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
683 int writable = length - writeoffs; |
2313 | 684 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
685 if (writable > 2048) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
686 writable = 2048; |
2313 | 687 |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
688 if (writable == 0) |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
689 return; |
2313 | 690 |
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
|
691 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
|
692 { |
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
|
693 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
|
694 |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
695 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
|
696 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
|
697 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
698 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
699 return; /* so finish */ |
2313 | 700 |
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
|
701 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
|
702 return; /* yes, so finish */ |
2313 | 703 |
3680
6615978ca88c
Instead of waiting 10ms, wait half the time of the period buffer.
William Pitcock <nenolod@atheme.org>
parents:
3560
diff
changeset
|
704 /* else sleep for retry */ |
3787
bce5ac1f368b
don't use semaphore/condvar messaging on Darwin because mach threads are high latency
William Pitcock <nenolod@atheme.org>
parents:
3709
diff
changeset
|
705 #ifndef GDK_WINDOWING_QUARTZ |
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
|
706 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
|
707 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
|
708 g_mutex_unlock(playback->pb_change_mutex); |
3787
bce5ac1f368b
don't use semaphore/condvar messaging on Darwin because mach threads are high latency
William Pitcock <nenolod@atheme.org>
parents:
3709
diff
changeset
|
709 #else |
bce5ac1f368b
don't use semaphore/condvar messaging on Darwin because mach threads are high latency
William Pitcock <nenolod@atheme.org>
parents:
3709
diff
changeset
|
710 /* Darwin threading sucks. */ |
bce5ac1f368b
don't use semaphore/condvar messaging on Darwin because mach threads are high latency
William Pitcock <nenolod@atheme.org>
parents:
3709
diff
changeset
|
711 g_usleep(10000); |
bce5ac1f368b
don't use semaphore/condvar messaging on Darwin because mach threads are high latency
William Pitcock <nenolod@atheme.org>
parents:
3709
diff
changeset
|
712 #endif |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
713 } |
2313 | 714 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
715 if (ip_data.stop) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
716 return; |
2313 | 717 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
718 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
719 return; /* so finish */ |
2313 | 720 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
721 /* do output */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
722 op->write_audio(((guint8 *) ptr) + writeoffs, writable); |
2313 | 723 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
724 writeoffs += writable; |
2313 | 725 } |
726 } |