Mercurial > audlegacy
annotate src/audacious/output.c @ 4235:2d4b4f13d10d
set_replaygain_info added to PAPI
author | Eugene Zagidullin <e.asphyx@gmail.com> |
---|---|
date | Thu, 31 Jan 2008 14:15:12 +0300 |
parents | b293ce14a01a |
children | 8f6956130372 |
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. */ |
4235
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
490 AUDDBG("flushing output instead of reopening\n"); |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
491 op->flush(0); |
2313 | 492 return 1; |
493 } | |
494 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
|
495 op->close_audio(); |
2313 | 496 |
497 ret = op->open_audio(fmt, rate, nch); | |
498 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
499 if (ret == 1) /* Success? */ |
2313 | 500 { |
4234 | 501 AUDDBG("opened audio: fmt=%d, rate=%d, nch=%d\n", fmt, rate, nch); |
2313 | 502 op_state.fmt = fmt; |
503 op_state.rate = rate; | |
504 op_state.nch = nch; | |
505 } | |
506 | |
507 return ret; | |
508 } | |
509 | |
510 void | |
511 output_write_audio(gpointer ptr, gint length) | |
512 { | |
513 OutputPlugin *op = get_current_output_plugin(); | |
514 | |
515 /* Sanity check. */ | |
516 if (op == NULL) | |
517 return; | |
518 | |
519 op->write_audio(ptr, length); | |
520 } | |
521 | |
522 void | |
523 output_close_audio(void) | |
524 { | |
525 OutputPlugin *op = get_current_output_plugin(); | |
526 | |
4234 | 527 AUDDBG("\n"); |
528 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
529 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
530 freeSRC(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
531 #endif |
4234 | 532 freeSAD(); |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
533 |
2313 | 534 /* Do not close if there are still songs to play and the user has |
535 * not requested a stop. --nenolod | |
536 */ | |
537 if (ip_data.stop == FALSE && | |
2673 | 538 (playlist_get_position_nolock(playlist_get_active()) < |
539 playlist_get_length(playlist_get_active()) - 1)) | |
2313 | 540 return; |
541 | |
542 /* Sanity check. */ | |
543 if (op == NULL) | |
544 return; | |
545 | |
546 op->close_audio(); | |
547 | |
548 /* Reset the op_state. */ | |
549 op_state.fmt = op_state.rate = op_state.nch = 0; | |
550 } | |
551 | |
552 void | |
553 output_flush(gint time) | |
554 { | |
555 OutputPlugin *op = get_current_output_plugin(); | |
556 | |
557 if (op == NULL) | |
558 return; | |
559 | |
560 op->flush(time); | |
561 } | |
562 | |
563 void | |
564 output_pause(gshort paused) | |
565 { | |
566 OutputPlugin *op = get_current_output_plugin(); | |
567 | |
568 if (op == NULL) | |
569 return; | |
570 | |
571 op->pause(paused); | |
572 } | |
573 | |
574 gint | |
575 output_buffer_free(void) | |
576 { | |
577 OutputPlugin *op = get_current_output_plugin(); | |
578 | |
579 if (op == NULL) | |
580 return 0; | |
581 | |
582 return op->buffer_free(); | |
583 } | |
584 | |
585 gint | |
586 output_buffer_playing(void) | |
587 { | |
588 OutputPlugin *op = get_current_output_plugin(); | |
589 | |
590 if (op == NULL) | |
591 return 0; | |
592 | |
593 return op->buffer_playing(); | |
594 } | |
595 | |
596 /* called by input plugin when data is ready */ | |
597 void | |
3709
a89a12aa4f2c
Add InputPlayback::pass_audio() which replaces produce_audio().
William Pitcock <nenolod@atheme.org>
parents:
3708
diff
changeset
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 int *going /* 0 when time to stop */ |
2313 | 604 ) |
605 { | |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
606 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
|
607 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
|
608 gint writeoffs; |
4234 | 609 |
610 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
|
611 gint time = playback->output->written_time(); |
2313 | 612 |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
613 if (postproc_flow == NULL) |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
614 { |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
615 postproc_flow = flow_new(); |
3560
154f21dcd61e
equalizer -> flow API
William Pitcock <nenolod@atheme.org>
parents:
3559
diff
changeset
|
616 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
|
617 flow_link_element(postproc_flow, effect_flow); |
3559 | 618 flow_link_element(postproc_flow, vis_flow); |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
619 flow_link_element(postproc_flow, volumecontrol_flow); |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
620 } |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
621 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
622 #ifdef USE_SRC |
4234 | 623 if(src_state != NULL) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
624 { |
4234 | 625 /*int lrLength = length / nch;*/ |
626 int lrLength = length / sample_size(fmt); | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
627 int overLrLength = (int)floor(lrLength*(src_data.src_ratio+1)); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
628 if(lengthOfSrcIn < lrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
629 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
630 lengthOfSrcIn = lrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
631 free(srcIn); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
632 srcIn = (float*)malloc(sizeof(float)*lrLength); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
633 } |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
634 if(lengthOfSrcOut < overLrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
635 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
636 lengthOfSrcOut = overLrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
637 free(srcOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
638 free(wOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
639 srcOut = (float*)malloc(sizeof(float)*overLrLength); |
4234 | 640 wOut = (short int*)malloc(sample_size(op_state.fmt) * overLrLength); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
641 } |
4234 | 642 /*src_short_to_float_array((short int*)ptr, srcIn, lrLength);*/ |
643 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
|
644 src_data.data_in = srcIn; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
645 src_data.data_out = srcOut; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
646 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
|
647 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
|
648 src_data.output_frames = overLrLength / nch; |
2542 | 649 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
|
650 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
651 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
|
652 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
653 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
654 { |
4234 | 655 /*src_float_to_short_array(srcOut, wOut, src_data.output_frames_gen*2);*/ |
656 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
|
657 ptr = wOut; |
4234 | 658 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
|
659 } |
4234 | 660 } else |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
661 #endif |
4234 | 662 if(sad_state != NULL) { |
663 int frames = length / nch / sample_size(fmt); | |
664 int len = frames * op_state.nch * sample_size(op_state.fmt); | |
665 if(sad_out_buf == NULL || sad_out_buf_length < len ) { | |
666 if(sad_out_buf != NULL) free (sad_out_buf); | |
667 sad_out_buf = malloc(len); | |
668 sad_out_buf_length = len; | |
669 } | |
670 SAD_dither_process_buffer(sad_state, ptr, sad_out_buf, frames); | |
671 ptr = sad_out_buf; | |
4235
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
672 length = len; |
4234 | 673 } |
674 | |
675 if (op_state.fmt == FMT_S16_NE || (op_state.fmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN) || | |
676 (op_state.fmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN)) { | |
677 length = flow_execute(postproc_flow, time, &ptr, length, op_state.fmt, op_state.rate, op_state.nch); | |
678 } else { | |
679 AUDDBG("postproc_flow can deal only with S16_NE streams\n"); /*FIXME*/ | |
680 } | |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
681 |
2313 | 682 writeoffs = 0; |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
683 while (writeoffs < length) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
684 { |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
685 int writable = length - writeoffs; |
2313 | 686 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
687 if (writable > 2048) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
688 writable = 2048; |
2313 | 689 |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
690 if (writable == 0) |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
691 return; |
2313 | 692 |
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
|
693 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
|
694 { |
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
|
695 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
|
696 |
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 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
|
698 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
|
699 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
700 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
701 return; /* so finish */ |
2313 | 702 |
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
|
703 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
|
704 return; /* yes, so finish */ |
2313 | 705 |
3680
6615978ca88c
Instead of waiting 10ms, wait half the time of the period buffer.
William Pitcock <nenolod@atheme.org>
parents:
3560
diff
changeset
|
706 /* 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
|
707 #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
|
708 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
|
709 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
|
710 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
|
711 #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
|
712 /* 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
|
713 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
|
714 #endif |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
715 } |
2313 | 716 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
717 if (ip_data.stop) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
718 return; |
2313 | 719 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
720 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
721 return; /* so finish */ |
2313 | 722 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
723 /* do output */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
724 op->write_audio(((guint8 *) ptr) + writeoffs, writable); |
2313 | 725 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
726 writeoffs += writable; |
2313 | 727 } |
728 } | |
4235
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
729 |
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
730 /* called by input plugin when RG info available */ |
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
731 void |
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
732 output_set_replaygain_info (InputPlayback *pb, ReplayGainInfo *rg_info) |
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
733 { |
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
734 /*stub*/ |
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
735 } |