Mercurial > audlegacy
annotate src/audacious/output.c @ 4237:8f6956130372
initial Replay Gain support
author | Eugene Zagidullin <e.asphyx@gmail.com> |
---|---|
date | Sat, 02 Feb 2008 01:53:15 +0300 |
parents | 2d4b4f13d10d |
children | 75ea2083e744 |
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 | |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
145 static void apply_replaygain_info (ReplayGainInfo *rg_info); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
146 |
4234 | 147 static SAD_sample_format |
148 sadfmt_from_afmt(AFormat fmt) | |
149 { | |
150 int i; | |
151 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++) { | |
152 if (format_table[i].afmt == fmt) return format_table[i].sadfmt; | |
153 } | |
154 | |
155 return -1; | |
156 } | |
157 | |
2313 | 158 OutputPlugin * |
159 get_current_output_plugin(void) | |
160 { | |
161 return op_data.current_output_plugin; | |
162 } | |
163 | |
164 void | |
165 set_current_output_plugin(gint i) | |
166 { | |
167 gboolean playing; | |
168 OutputPlugin *op = get_current_output_plugin(); | |
169 | |
170 GList *node = g_list_nth(op_data.output_list, i); | |
171 if (!node) { | |
172 op_data.current_output_plugin = NULL; | |
173 return; | |
174 } | |
175 | |
176 op_data.current_output_plugin = node->data; | |
177 | |
178 playing = playback_get_playing(); | |
179 | |
180 if (playing == TRUE) | |
181 { | |
182 guint time, pos; | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
183 PlaylistEntry *entry; |
2313 | 184 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
185 /* don't stop yet, get the seek time and playlist position first */ |
2313 | 186 pos = playlist_get_position(playlist_get_active()); |
187 time = op->output_time(); | |
188 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
189 /* reset the audio system */ |
2313 | 190 mainwin_stop_pushed(); |
191 op->close_audio(); | |
192 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
193 g_usleep(300000); |
2313 | 194 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
195 /* wait for the playback thread to come online */ |
2313 | 196 while (playback_get_playing()) |
197 g_message("waiting for audio system shutdown..."); | |
198 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
199 /* wait for the playback thread to come online */ |
2313 | 200 playlist_set_position(playlist_get_active(), pos); |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
201 entry = playlist_get_entry_to_play(playlist_get_active()); |
2313 | 202 playback_play_file(entry); |
203 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
204 while (!playback_get_playing()) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
205 { |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
206 gtk_main_iteration(); |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
207 g_message("waiting for audio system startup..."); |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
208 } |
2313 | 209 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
210 /* and signal a reseek */ |
2313 | 211 if (playlist_get_current_length(playlist_get_active()) > -1 && |
212 time <= (playlist_get_current_length(playlist_get_active()))) | |
213 playback_seek(time / 1000); | |
214 } | |
215 } | |
216 | |
217 GList * | |
218 get_output_list(void) | |
219 { | |
220 return op_data.output_list; | |
221 } | |
222 | |
223 void | |
224 output_about(gint i) | |
225 { | |
226 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
227 if (out && out->about) | |
228 out->about(); | |
229 } | |
230 | |
231 void | |
232 output_configure(gint i) | |
233 { | |
234 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
235 if (out && out->configure) | |
236 out->configure(); | |
237 } | |
238 | |
239 void | |
240 output_get_volume(gint * l, gint * r) | |
241 { | |
242 *l = *r = -1; | |
243 | |
244 if (!op_data.current_output_plugin) | |
245 return; | |
246 | |
247 if (!op_data.current_output_plugin->get_volume) | |
248 return; | |
249 | |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
250 if (cfg.software_volume_control) |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
251 volumecontrol_get_volume_state(l, r); |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
252 else |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
253 op_data.current_output_plugin->get_volume(l, r); |
2313 | 254 } |
255 | |
256 void | |
257 output_set_volume(gint l, gint r) | |
258 { | |
259 if (!op_data.current_output_plugin) | |
260 return; | |
261 | |
262 if (!op_data.current_output_plugin->set_volume) | |
263 return; | |
264 | |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
265 if (cfg.software_volume_control) |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
266 volumecontrol_set_volume_state(l, r); |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
267 else |
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
268 op_data.current_output_plugin->set_volume(l, r); |
2313 | 269 } |
270 | |
271 void | |
272 output_set_eq(gboolean active, gfloat pre, gfloat * bands) | |
273 { | |
274 int i; | |
275 preamp[0] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
276 preamp[1] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
277 | |
278 for (i = 0; i < 10; ++i) | |
279 { | |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
280 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
|
281 set_gain(i, 1, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
2313 | 282 } |
283 } | |
284 | |
285 /* called by input plugin to peek at the output plugin's write progress */ | |
286 gint | |
287 get_written_time(void) | |
288 { | |
289 OutputPlugin *op = get_current_output_plugin(); | |
290 | |
291 return op->written_time(); | |
292 } | |
293 | |
294 /* called by input plugin to peek at the output plugin's output progress */ | |
295 gint | |
296 get_output_time(void) | |
297 { | |
298 OutputPlugin *op = get_current_output_plugin(); | |
299 | |
300 return op->output_time(); | |
301 } | |
302 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
303 #ifdef USE_SRC |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
304 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
305 static SRC_STATE *src_state; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
306 static SRC_DATA src_data; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
307 static int overSamplingFs = 96000; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
308 static int converter_type = SRC_SINC_BEST_QUALITY; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
309 static int srcError = 0; |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
310 |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
311 static float *srcIn = NULL, *srcOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
312 static short int *wOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
313 static int lengthOfSrcIn = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
314 static int lengthOfSrcOut = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
315 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
316 static void freeSRC() |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
317 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
318 if(src_state != NULL) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
319 src_state = src_delete(src_state); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
320 free(srcIn); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
321 free(srcOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
322 free(wOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
323 srcIn = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
324 srcOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
325 wOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
326 lengthOfSrcIn = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
327 lengthOfSrcOut = 0; |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
328 } |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
329 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
330 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
331 |
4234 | 332 static SAD_dither_t *sad_state = NULL; |
333 static SAD_dither_t *sad_state_to_float = NULL; | |
334 static SAD_dither_t *sad_state_from_float = NULL; | |
335 static void *sad_out_buf = NULL; | |
336 static int sad_out_buf_length = 0; | |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
337 static ReplayGainInfo replay_gain_info = { |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
338 .track_gain = 0.0, |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
339 .track_peak = 0.0, |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
340 .album_gain = 0.0, |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
341 .album_peak = 0.0, |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
342 }; |
4234 | 343 |
344 static void | |
345 freeSAD() | |
346 { | |
347 if (sad_state != NULL) {SAD_dither_free(sad_state); sad_state = NULL;} | |
348 if (sad_state_from_float != NULL) {SAD_dither_free(sad_state_from_float); sad_state_from_float = NULL;} | |
349 if (sad_state_to_float != NULL) {SAD_dither_free(sad_state_to_float); sad_state_to_float = NULL;} | |
350 if (sad_out_buf != NULL) {free(sad_out_buf); sad_out_buf = NULL; sad_out_buf_length = 0;} | |
351 } | |
352 | |
2313 | 353 gint |
354 output_open_audio(AFormat fmt, gint rate, gint nch) | |
355 { | |
356 gint ret; | |
357 OutputPlugin *op; | |
4234 | 358 AUDDBG("\n"); |
359 | |
360 AFormat output_fmt; | |
361 int bit_depth; | |
362 SAD_buffer_format input_sad_fmt; | |
363 SAD_buffer_format output_sad_fmt; | |
364 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
365 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
366 gboolean src_enabled; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
367 gint src_rate, src_type; |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
368 ConfigDb *db; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
369 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
370 db = cfg_db_open(); |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
371 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
372 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
|
373 src_enabled = FALSE; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
374 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
375 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
|
376 overSamplingFs = 48000; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
377 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
378 overSamplingFs = src_rate; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
379 |
2649
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
380 /* 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
|
381 if (rate == overSamplingFs) |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
382 src_enabled = FALSE; |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
383 |
3686
259b7d3e0976
sed s/bmp_cfg_db/cfg_db/.
William Pitcock <nenolod@atheme.org>
parents:
3681
diff
changeset
|
384 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
|
385 converter_type = SRC_SINC_BEST_QUALITY; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
386 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
387 converter_type = src_type; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
388 |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
389 freeSRC(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
390 |
4234 | 391 if(src_enabled) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
392 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
393 src_state = src_new(converter_type, nch, &srcError); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
394 if (src_state != NULL) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
395 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
396 src_data.src_ratio = (float)overSamplingFs/(float)rate; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
397 rate = overSamplingFs; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
398 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
399 else |
4234 | 400 { |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
401 fprintf(stderr, "src_new(): %s\n\n", src_strerror(srcError)); |
4234 | 402 src_enabled = FALSE; |
403 } | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
404 } |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
405 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
406 cfg_db_close(db); |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
407 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
408 |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
409 /*if (cfg_db_get_int(db, NULL, "output_bit_depth", &bit_depth) == FALSE) bit_depth = 16;*/ |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
410 bit_depth = cfg.output_bit_depth; |
4234 | 411 |
412 AUDDBG("bit depth: %d\n", bit_depth); | |
413 output_fmt = (bit_depth == 24) ? FMT_S24_NE : FMT_S16_NE; /* no reason to support other output formats --asphyx */ | |
414 | |
415 freeSAD(); | |
416 | |
417 #ifdef USE_SRC | |
418 if (src_enabled) { | |
419 AUDDBG("initializing dithering engine for 2 stage conversion\n"); | |
420 input_sad_fmt.sample_format = sadfmt_from_afmt(fmt); | |
421 if (input_sad_fmt.sample_format < 0) return -1; | |
422 input_sad_fmt.fracbits = 0; | |
423 input_sad_fmt.channels = nch; | |
424 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
425 input_sad_fmt.samplerate = 0; | |
426 | |
427 output_sad_fmt.sample_format = SAD_SAMPLE_FLOAT; | |
428 output_sad_fmt.fracbits = 0; | |
429 output_sad_fmt.channels = nch; | |
430 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
431 output_sad_fmt.samplerate = 0; | |
432 | |
433 sad_state_to_float = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); | |
434 if (sad_state_to_float == NULL) { | |
435 AUDDBG("ditherer init failed (decoder's native --> float)\n"); | |
436 return -1; | |
437 } | |
438 SAD_dither_set_dither (sad_state_to_float, FALSE); | |
439 | |
440 input_sad_fmt.sample_format = SAD_SAMPLE_FLOAT; | |
441 input_sad_fmt.fracbits = 0; | |
442 input_sad_fmt.channels = nch; | |
443 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
444 input_sad_fmt.samplerate = 0; | |
445 | |
446 output_sad_fmt.sample_format = sadfmt_from_afmt(output_fmt); | |
447 if (output_sad_fmt.sample_format < 0) return -1; | |
448 output_sad_fmt.fracbits = 0; | |
449 output_sad_fmt.channels = nch; | |
450 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
451 output_sad_fmt.samplerate = 0; | |
452 | |
453 sad_state_from_float = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); | |
454 if (sad_state_from_float == NULL) { | |
455 SAD_dither_free(sad_state_to_float); | |
456 AUDDBG("ditherer init failed (float --> output)\n"); | |
457 return -1; | |
458 } | |
459 SAD_dither_set_dither (sad_state_from_float, TRUE); | |
460 | |
461 fmt = output_fmt; | |
462 } else | |
463 #endif /* USE_SRC */ | |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
464 { /* needed for RG processing !*/ |
4234 | 465 AUDDBG("initializing dithering engine for direct conversion\n"); |
466 | |
467 input_sad_fmt.sample_format = sadfmt_from_afmt(fmt); | |
468 if (input_sad_fmt.sample_format < 0) return -1; | |
469 input_sad_fmt.fracbits = 0; | |
470 input_sad_fmt.channels = nch; | |
471 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
472 input_sad_fmt.samplerate = 0; /* resampling not implemented yet in libSAD */ | |
473 | |
474 output_sad_fmt.sample_format = sadfmt_from_afmt(output_fmt); | |
475 output_sad_fmt.fracbits = 0; | |
476 output_sad_fmt.channels = nch; | |
477 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; | |
478 output_sad_fmt.samplerate = 0; | |
479 | |
480 sad_state = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); | |
481 if (sad_state == NULL) { | |
482 AUDDBG("ditherer init failed\n"); | |
483 return -1; | |
484 } | |
485 SAD_dither_set_dither (sad_state, TRUE); | |
486 | |
487 fmt = output_fmt; | |
488 } | |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
489 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
490 if(replay_gain_info.album_peak != 0.0 || replay_gain_info.track_peak != 0.0) |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
491 apply_replaygain_info(&replay_gain_info); |
4234 | 492 |
2313 | 493 op = get_current_output_plugin(); |
494 | |
495 if (op == NULL) | |
496 return -1; | |
497 | |
498 /* Is our output port already open? */ | |
499 if ((op_state.rate != 0 && op_state.nch != 0) && | |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
500 (op_state.rate == rate && op_state.nch == nch && op_state.fmt == fmt)) |
2313 | 501 { |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
502 /* 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
|
503 AUDDBG("flushing output instead of reopening\n"); |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
504 op->flush(0); |
2313 | 505 return 1; |
506 } | |
507 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
|
508 op->close_audio(); |
2313 | 509 |
510 ret = op->open_audio(fmt, rate, nch); | |
511 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
512 if (ret == 1) /* Success? */ |
2313 | 513 { |
4234 | 514 AUDDBG("opened audio: fmt=%d, rate=%d, nch=%d\n", fmt, rate, nch); |
2313 | 515 op_state.fmt = fmt; |
516 op_state.rate = rate; | |
517 op_state.nch = nch; | |
518 } | |
519 | |
520 return ret; | |
521 } | |
522 | |
523 void | |
524 output_write_audio(gpointer ptr, gint length) | |
525 { | |
526 OutputPlugin *op = get_current_output_plugin(); | |
527 | |
528 /* Sanity check. */ | |
529 if (op == NULL) | |
530 return; | |
531 | |
532 op->write_audio(ptr, length); | |
533 } | |
534 | |
535 void | |
536 output_close_audio(void) | |
537 { | |
538 OutputPlugin *op = get_current_output_plugin(); | |
539 | |
4234 | 540 AUDDBG("\n"); |
541 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
542 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
543 freeSRC(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
544 #endif |
4234 | 545 freeSAD(); |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
546 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
547 AUDDBG("clearing RG settings\n"); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
548 replay_gain_info.track_gain = 0.0; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
549 replay_gain_info.track_peak = 0.0; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
550 replay_gain_info.album_gain = 0.0; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
551 replay_gain_info.album_peak = 0.0; |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
552 |
2313 | 553 /* Do not close if there are still songs to play and the user has |
554 * not requested a stop. --nenolod | |
555 */ | |
556 if (ip_data.stop == FALSE && | |
2673 | 557 (playlist_get_position_nolock(playlist_get_active()) < |
558 playlist_get_length(playlist_get_active()) - 1)) | |
2313 | 559 return; |
560 | |
561 /* Sanity check. */ | |
562 if (op == NULL) | |
563 return; | |
564 | |
565 op->close_audio(); | |
566 | |
567 /* Reset the op_state. */ | |
568 op_state.fmt = op_state.rate = op_state.nch = 0; | |
569 } | |
570 | |
571 void | |
572 output_flush(gint time) | |
573 { | |
574 OutputPlugin *op = get_current_output_plugin(); | |
575 | |
576 if (op == NULL) | |
577 return; | |
578 | |
579 op->flush(time); | |
580 } | |
581 | |
582 void | |
583 output_pause(gshort paused) | |
584 { | |
585 OutputPlugin *op = get_current_output_plugin(); | |
586 | |
587 if (op == NULL) | |
588 return; | |
589 | |
590 op->pause(paused); | |
591 } | |
592 | |
593 gint | |
594 output_buffer_free(void) | |
595 { | |
596 OutputPlugin *op = get_current_output_plugin(); | |
597 | |
598 if (op == NULL) | |
599 return 0; | |
600 | |
601 return op->buffer_free(); | |
602 } | |
603 | |
604 gint | |
605 output_buffer_playing(void) | |
606 { | |
607 OutputPlugin *op = get_current_output_plugin(); | |
608 | |
609 if (op == NULL) | |
610 return 0; | |
611 | |
612 return op->buffer_playing(); | |
613 } | |
614 | |
615 /* called by input plugin when data is ready */ | |
616 void | |
3709
a89a12aa4f2c
Add InputPlayback::pass_audio() which replaces produce_audio().
William Pitcock <nenolod@atheme.org>
parents:
3708
diff
changeset
|
617 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
|
618 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
|
619 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
|
620 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
|
621 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
|
622 int *going /* 0 when time to stop */ |
2313 | 623 ) |
624 { | |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
625 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
|
626 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
|
627 gint writeoffs; |
4234 | 628 |
629 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
|
630 gint time = playback->output->written_time(); |
2313 | 631 |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
632 if (postproc_flow == NULL) |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
633 { |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
634 postproc_flow = flow_new(); |
3560
154f21dcd61e
equalizer -> flow API
William Pitcock <nenolod@atheme.org>
parents:
3559
diff
changeset
|
635 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
|
636 flow_link_element(postproc_flow, effect_flow); |
3559 | 637 flow_link_element(postproc_flow, vis_flow); |
3553
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
638 flow_link_element(postproc_flow, volumecontrol_flow); |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
639 } |
a140fadd741d
software volumecontrol->flow manager API
William Pitcock <nenolod@atheme.org>
parents:
3549
diff
changeset
|
640 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
641 #ifdef USE_SRC |
4234 | 642 if(src_state != NULL) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
643 { |
4234 | 644 /*int lrLength = length / nch;*/ |
645 int lrLength = length / sample_size(fmt); | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
646 int overLrLength = (int)floor(lrLength*(src_data.src_ratio+1)); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
647 if(lengthOfSrcIn < lrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
648 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
649 lengthOfSrcIn = lrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
650 free(srcIn); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
651 srcIn = (float*)malloc(sizeof(float)*lrLength); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
652 } |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
653 if(lengthOfSrcOut < overLrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
654 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
655 lengthOfSrcOut = overLrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
656 free(srcOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
657 free(wOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
658 srcOut = (float*)malloc(sizeof(float)*overLrLength); |
4234 | 659 wOut = (short int*)malloc(sample_size(op_state.fmt) * overLrLength); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
660 } |
4234 | 661 /*src_short_to_float_array((short int*)ptr, srcIn, lrLength);*/ |
662 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
|
663 src_data.data_in = srcIn; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
664 src_data.data_out = srcOut; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
665 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
|
666 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
|
667 src_data.output_frames = overLrLength / nch; |
2542 | 668 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
|
669 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
670 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
|
671 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
672 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
673 { |
4234 | 674 /*src_float_to_short_array(srcOut, wOut, src_data.output_frames_gen*2);*/ |
675 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
|
676 ptr = wOut; |
4234 | 677 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
|
678 } |
4234 | 679 } else |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
680 #endif |
4234 | 681 if(sad_state != NULL) { |
682 int frames = length / nch / sample_size(fmt); | |
683 int len = frames * op_state.nch * sample_size(op_state.fmt); | |
684 if(sad_out_buf == NULL || sad_out_buf_length < len ) { | |
685 if(sad_out_buf != NULL) free (sad_out_buf); | |
686 sad_out_buf = malloc(len); | |
687 sad_out_buf_length = len; | |
688 } | |
689 SAD_dither_process_buffer(sad_state, ptr, sad_out_buf, frames); | |
690 ptr = sad_out_buf; | |
4235
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
691 length = len; |
4234 | 692 } |
693 | |
694 if (op_state.fmt == FMT_S16_NE || (op_state.fmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN) || | |
695 (op_state.fmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN)) { | |
696 length = flow_execute(postproc_flow, time, &ptr, length, op_state.fmt, op_state.rate, op_state.nch); | |
697 } else { | |
698 AUDDBG("postproc_flow can deal only with S16_NE streams\n"); /*FIXME*/ | |
699 } | |
3546
fd4cd1945b91
Connect volumecontrol flow to the work pipeline.
William Pitcock <nenolod@atheme.org>
parents:
3486
diff
changeset
|
700 |
2313 | 701 writeoffs = 0; |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
702 while (writeoffs < length) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
703 { |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
704 int writable = length - writeoffs; |
2313 | 705 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
706 if (writable > 2048) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
707 writable = 2048; |
2313 | 708 |
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
709 if (writable == 0) |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
710 return; |
2313 | 711 |
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
|
712 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
|
713 { |
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
|
714 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
|
715 |
418ac922ce87
Use a mutex/condvar/timed wait to allow tickless operation in the output loop.
William Pitcock <nenolod@atheme.org>
parents:
3686
diff
changeset
|
716 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
|
717 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
|
718 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
719 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
720 return; /* so finish */ |
2313 | 721 |
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
|
722 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
|
723 return; /* yes, so finish */ |
2313 | 724 |
3680
6615978ca88c
Instead of waiting 10ms, wait half the time of the period buffer.
William Pitcock <nenolod@atheme.org>
parents:
3560
diff
changeset
|
725 /* 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
|
726 #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
|
727 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
|
728 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
|
729 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
|
730 #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
|
731 /* 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
|
732 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
|
733 #endif |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
734 } |
2313 | 735 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
736 if (ip_data.stop) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
737 return; |
2313 | 738 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
739 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
740 return; /* so finish */ |
2313 | 741 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
742 /* do output */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
743 op->write_audio(((guint8 *) ptr) + writeoffs, writable); |
2313 | 744 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
745 writeoffs += writable; |
2313 | 746 } |
747 } | |
4235
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
748 |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
749 /* called by input plugin when RG info available --asphyx */ |
4235
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
750 void |
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
751 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
|
752 { |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
753 replay_gain_info = *rg_info; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
754 apply_replaygain_info(rg_info); |
4235
2d4b4f13d10d
set_replaygain_info added to PAPI
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4234
diff
changeset
|
755 } |
4237
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
756 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
757 static void |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
758 apply_replaygain_info (ReplayGainInfo *rg_info) |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
759 { |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
760 SAD_replaygain_mode mode; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
761 SAD_replaygain_info info; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
762 /*ConfigDb *db;*/ |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
763 gboolean rg_enabled; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
764 gboolean album_mode; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
765 SAD_dither_t *active_state; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
766 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
767 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
768 if(sad_state == NULL && sad_state_from_float == NULL) { |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
769 AUDDBG("SAD not initialized!\n"); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
770 return; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
771 } |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
772 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
773 rg_enabled = cfg.enable_replay_gain; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
774 album_mode = cfg.replay_gain_album; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
775 mode.clipping_prevention = cfg.enable_clipping_prevention; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
776 mode.hard_limit = cfg.enable_hard_limiter; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
777 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
778 if(!rg_enabled) return; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
779 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
780 mode.mode = album_mode ? SAD_RG_ALBUM : SAD_RG_TRACK; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
781 mode.preamp = 0.0; /*FIXME*/ |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
782 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
783 info.present = TRUE; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
784 info.track_gain = rg_info->track_gain; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
785 info.track_peak = rg_info->track_peak; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
786 info.album_gain = rg_info->album_gain; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
787 info.album_peak = rg_info->album_peak; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
788 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
789 AUDDBG("Applying Replay Gain settings:\n"); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
790 AUDDBG("* mode: %s\n", mode.mode == SAD_RG_ALBUM ? "album" : "track"); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
791 AUDDBG("* clipping prevention: %s\n", mode.clipping_prevention ? "yes" : "no"); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
792 AUDDBG("* hard limit: %s\n", mode.hard_limit ? "yes" : "no"); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
793 AUDDBG("* preamp: %+f dB\n", mode.preamp); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
794 AUDDBG("Replay Gain info for current track:\n"); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
795 AUDDBG("* track gain: %+f dB\n", info.track_gain); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
796 AUDDBG("* track peak: %f\n", info.track_peak); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
797 AUDDBG("* album gain: %+f dB\n", info.album_gain); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
798 AUDDBG("* album peak: %f\n", info.album_peak); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
799 |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
800 active_state = sad_state != NULL ? sad_state : sad_state_from_float; |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
801 SAD_dither_apply_replaygain(active_state, &info, &mode); |
8f6956130372
initial Replay Gain support
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4235
diff
changeset
|
802 } |