annotate src/crossfade/crossfade.c @ 3118:07701f0ae8e5

Add type hint to CD Audio preferences window.
author John Lindgren <john.lindgren@tds.net>
date Mon, 04 May 2009 16:57:36 -0400
parents d58963762734
children 354e90c81253
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3059
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1 /*
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2 * XMMS Crossfade Plugin
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
3 * Copyright (C) 2000-2007 Peter Eisenlohr <peter@eisenlohr.org>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
4 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
5 * based on the original OSS Output Plugin
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
6 * Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
7 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
11 * (at your option) any later version.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
12 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
16 * GNU General Public License for more details.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
17 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
21 * USA.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
22 */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
23 /* indent -i8 -ts8 -hnl -bli0 -l128 -npcs -cli8 */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
24
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 #ifdef HAVE_CONFIG_H
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26 # include "config.h"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
29 #include "crossfade.h"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
30 #include "cfgutil.h"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
31 #include "format.h"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
32 #include "convert.h"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
33
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34 #include "configure.h"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
35
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36 #include "interface-2.0.h"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37 #include "support-2.0.h"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
39 #ifdef HAVE_LIBFFTW
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
40 # include "fft.h"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
41 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43 #include <stdio.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
44 #include <string.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45 #include <stdlib.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
46 #include <ctype.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
48 #ifdef HAVE_DLFCN_H
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
49 # include <dlfcn.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
50 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
51 #include <unistd.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52 #include <signal.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
53 #include <sys/time.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
54 #include <sys/types.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55 #include <sys/ioctl.h>
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
56
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
57 #undef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
59 /* output plugin callback prototypes */
3065
a0ba6102131d crossfade-ng: remove more cruft, kill some warnings.
William Pitcock <nenolod@atheme.org>
parents: 3064
diff changeset
60 static OutputPluginInitStatus xfade_init();
3059
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
61 static void xfade_cleanup(); /* audacious and patched only */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
62 static void xfade_set_volume(int l, int r);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
63 static void xfade_get_volume(int *l, int *r);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
64 static gint xfade_open_audio(AFormat fmt, int rate, int nch);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
65 static void xfade_write_audio(void *ptr, int length);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
66 static void xfade_close_audio();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
67 static void xfade_flush(int time);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
68 static void xfade_pause(short paused);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
69 static gint xfade_buffer_free();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
70 static gint xfade_buffer_playing();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
71 static gint xfade_written_time();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
72 static gint xfade_output_time();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
73
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
74 /* output plugin callback table (extended, needs patched player) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
75 static struct
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
76 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
77 OutputPlugin xfade_op;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
78 void (*cleanup) (void);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
79 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
80 xfade_op_private =
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
81 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
82 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83 .description = "Crossfade Plugin",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
84 .init = xfade_init,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85 .cleanup = xfade_cleanup,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86 .get_volume = xfade_get_volume,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
87 .set_volume = xfade_set_volume,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
88 .open_audio = xfade_open_audio,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
89 .write_audio = xfade_write_audio,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
90 .close_audio = xfade_close_audio,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
91 .flush = xfade_flush,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 .pause = xfade_pause,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93 .buffer_free = xfade_buffer_free,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94 .buffer_playing = xfade_buffer_playing,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
95 .output_time = xfade_output_time,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
96 .written_time = xfade_written_time,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
97 .about = xfade_about,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
98 .configure = xfade_configure,
3077
d58963762734 crossfade-ng: probe_priority = 0
William Pitcock <nenolod@atheme.org>
parents: 3073
diff changeset
99 .probe_priority = 0,
3059
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
100 },
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
101 NULL
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
102 };
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
103
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
104 static OutputPlugin *xfade_op = &xfade_op_private.xfade_op;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
105
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
106 static OutputPlugin *xfade_oplist[] = { &xfade_op_private.xfade_op, NULL };
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
107 DECLARE_PLUGIN(crossfade, NULL, NULL, NULL, xfade_oplist, NULL, NULL, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
108
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
109 /* internal prototypes */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
110 static void load_symbols();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
111 static gint open_output();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
112 static void buffer_reset(buffer_t *buf, config_t *cfg);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
113 static void *buffer_thread_f(void *arg);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
114 static void sync_output();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
115
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
116 /* special XMMS symbols (dynamically looked up, see xfade_init) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117 static gboolean *xmms_playlist_get_info_going = NULL; /* XMMS */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
118 static gboolean *xmms_is_quitting = NULL; /* XMMS */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
119 static gboolean *input_stopped_for_restart = NULL; /* XMMS */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
120
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
121 /* This function has been stolen from libxmms/util.c. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
122 void xfade_usleep(gint usec)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
123 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
124 #if defined(HAVE_G_USLEEP)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
125 g_usleep(usec);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
126 #elif defined(HAVE_NANOSLEEP)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
127 struct timespec req;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
128
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
129 req.tv_sec = usec / 1000000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
130 usec -= req.tv_sec * 1000000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
131 req.tv_nsec = usec * 1000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
132
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
133 nanosleep(&req, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
134 #else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135 struct timeval tv;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
136
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
137 tv.tv_sec = usec / 1000000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
138 usec -= tv.tv_sec * 1000000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
139 tv.tv_usec = usec;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
140 select(0, NULL, NULL, NULL, &tv);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
141 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
142 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
143
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
144
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
145 /* local variables */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
146 static gboolean realtime;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
147 static gboolean is_http;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
148
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
149 static gint64 streampos; /* position within current song (input bps) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
150 static gboolean playing;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
151 gboolean opened; /* TRUE between open_audio() and close_audio() */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
152 static gboolean paused; /* TRUE: no playback (but still filling buffer) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
153 static gboolean stopped; /* TRUE: stop buffer thread ASAP */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
154 static gboolean eop; /* TRUE: wait until buffer is empty then sync() */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
155
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
156 #ifdef HAVE_OSS /* avoid 'defined but not used' compiler warning */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
157 static plugin_config_t default_op_config = DEFAULT_OP_CONFIG;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
158 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
159 static plugin_config_t the_op_config = DEFAULT_OP_CONFIG;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
160 OutputPlugin *the_op = NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
161 gint the_rate = 44100;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
162
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
163 static gboolean input_playing = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
164
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
165 gboolean output_opened = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
166 gboolean output_restart = FALSE; /* used by XMMS 'songchange' patch */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
167 static gint output_flush_time = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
168 gint output_offset = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
169 static gint64 output_written = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
170 gint64 output_streampos = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
171
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
172 static gchar zero_4k[4096];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
173
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
174 /*
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
175 * Available fade configs:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
176 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
177 * fc_start: First song, only in_len and in_level are used
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
178 * fc_xfade: Automatic crossfade at end of song
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
179 * fc_album: Like xfade but for consecutive songs of the same album
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
180 * fc_manual: Manual crossfade (triggered by Next or Prev)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
181 * fc_stop: Last song, only out_len and out_level are used
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
182 * fc_eop: Last song, only out_len and out_level are used
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
183 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
184 * NOTE: As of version 0.2 of xmms-crossfade,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
185 * only xfade and manual are implemented.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
186 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
187 * With version 0.2.3, fc_album has been added.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
188 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
189 * With 0.2.4, all configs are implemented:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
190 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
191 * Available parameters:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
192 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
193 * | start | xfade | manual | album | stop | eop
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
194 * ------------+-------+-------+--------+-------+------+------
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
195 * in_len | yes | yes | yes | no | no | no
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
196 * in_volume | yes | yes | yes | no | no | no
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
197 * offset | no | yes | yes | no | +yes | +yes
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
198 * out_len | no | yes | yes | no | yes | yes
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
199 * out_volume | no | yes | yes | no | yes | yes
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
200 * flush (*) | no | no | yes | no | yes | no
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
201 * ------------+-------+-------+--------+-------+------+------
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
202 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
203 * Parameters marked with (*) are not configureable by the user
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
204 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
205 * The offset parameters for 'stop' and 'eop' is used to store the
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
206 * length of the additional silence to be added. It may be >= 0 only.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
207 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
208 */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
209
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
210 static struct timeval last_close;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
211 static struct timeval last_write;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
212
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
213 static gchar *last_filename = NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
214
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
215 static format_t in_format;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
216 static format_t out_format;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
217
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
218 static buffer_t the_buffer;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
219 buffer_t *buffer = &the_buffer;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
220
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
221 static THREAD buffer_thread;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
222 MUTEX buffer_mutex = MUTEX_INITIALIZER;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
223
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
224 static convert_context_t convert_context;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
225 #ifdef HAVE_LIBFFTW
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
226 static fft_context_t fft_context;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
227 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
228
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
229 static config_t the_config;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
230 config_t *config = &the_config;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
231 config_t config_default = CONFIG_DEFAULT;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
232
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
233 static fade_config_t *fade_config = NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
234
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
235
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
236 /* this is the entry point for XMMS */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
237 OutputPlugin *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
238 get_oplugin_info()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
239 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
240 return xfade_op;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
241 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
242
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
243 OutputPlugin *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
244 get_crossfade_oplugin_info()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
245 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
246 return xfade_op;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
247 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
248
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
249 static gboolean
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
250 open_output_f(gpointer data)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
251 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
252 DEBUG(("[crossfade] open_output_f: pid=%d\n", getpid()));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
253 open_output();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
254 return FALSE; /* FALSE = 'do not call me again' */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
255 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
256
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
257 void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
258 xfade_realize_config() /* also called by xfade_init() */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
259 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
260 /* 0.3.0: keep device opened */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
261 if (config->output_keep_opened && !output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
262 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
263 DEBUG(("[crossfade] realize_config: keeping output opened...\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
264
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
265 /* 0.3.1: HACK: this will make sure that we start playing silence after startup */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
266 gettimeofday(&last_close, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
267
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
268 /* 0.3.1: HACK: Somehow, if we open output here at XMMS startup, there
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
269 will be leftover filedescriptors later when closing output again.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
270 Opening output in a timeout function seems to work around this... */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
271 DEBUG(("[crossfade] realize_config: adding timeout (pid=%d)\n", (int) getpid()));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
272 g_timeout_add(0, open_output_f, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
273 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
274 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
275
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
276 static gint
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
277 output_list_f(gconstpointer a, gconstpointer b)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
278 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
279 OutputPlugin *op = (OutputPlugin *) a;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
280 gchar *name = (gchar *) b;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
281
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
282 return strcmp(g_basename(op->filename), name);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
283 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
284
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
285 static OutputPlugin *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
286 find_output()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
287 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
288 GList *list, *element;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
289 OutputPlugin *op = NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
290
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
291 /* find output plugin */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
292 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
293 if (config->op_name && (list = xfplayer_get_output_list()))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
294 if ((element = g_list_find_custom(list, config->op_name, output_list_f)))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
295 op = element->data;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
296
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
297 if (op == xfade_op)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
298 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
299 DEBUG(("[crossfade] find_output: can't use myself as output plugin!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
300 op = NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
301 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
302 else if (!op)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
303 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
304 DEBUG(("[crossfade] find_output: could not find output plugin \"%s\"\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
305 config->op_name ? config->op_name : "#NULL#"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
306 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
307 else /* ok, we have a plugin. last, get its compatibility options */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
308 xfade_load_plugin_config(config->op_config_string, config->op_name, &the_op_config);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
309 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
310
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
311 return op;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
312 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
313
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
314 static gint
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
315 open_output()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
316 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
317 /* sanity check */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
318 if (output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
319 DEBUG(("[crossfade] open_output: WARNING: output_opened=TRUE!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
320
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
321 /* reset output_* */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
322 output_opened = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
323 output_flush_time = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
324 output_offset = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
325 output_written = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
326 output_streampos = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
327
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
328 /* get output plugin (this will also init the_op_config) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
329 if (!(the_op = find_output()))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
330 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
331 DEBUG(("[crossfade] open_output: could not find any output!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
332 return -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
333 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
334
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
335 /* print output plugin info */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
336 DEBUG(("[crossfade] open_output: using \"%s\" for output", the_op->description ? the_op->description : "#NULL#"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
337
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
338 if (realtime)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
339 DEBUG((" (RT)"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
340
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
341 if (the_op_config.throttle_enable)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
342 DEBUG((realtime ? " (throttled (disabled with RT))" : " (throttled)"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
343
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
344 if (the_op_config.max_write_enable)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
345 DEBUG((" (max_write=%d)", the_op_config.max_write_len));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
346
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
347 DEBUG(("\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
348
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
349 /* setup sample rate (note that OUTPUT_RATE is #defined as the_rate) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
350 the_rate = config->output_rate;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
351
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
352 /* setup out_format. use host byte order for easy math */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
353 setup_format(FMT_S16_NE, OUTPUT_RATE, OUTPUT_NCH, &out_format);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
354
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
355 /* open plugin */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
356 if (!the_op->open_audio(out_format.fmt, out_format.rate, out_format.nch))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
357 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
358 DEBUG(("[crossfade] open_output: open_audio() failed!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
359 the_op = NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
360 return -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
361 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
362
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
363 /* clear buffer struct */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
364 memset(buffer, 0, sizeof(*buffer));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
365
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
366 /* calculate buffer size */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
367 buffer->mix_size = MS2B(xfade_mix_size_ms(config)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
368 buffer->sync_size = MS2B(config->sync_size_ms) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
369 buffer->preload_size = MS2B(config->preload_size_ms) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
370
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
371 buffer->size = (buffer->mix_size + /* mixing area */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
372 buffer->sync_size + /* additional sync */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
373 buffer->preload_size); /* preload */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
374
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
375 DEBUG(("[crossfade] open_output: buffer: size=%d (%d+%d+%d=%d ms) (%d Hz)\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
376 buffer->size,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
377 B2MS(buffer->mix_size),
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
378 B2MS(buffer->preload_size),
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
379 B2MS(buffer->sync_size),
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
380 B2MS(buffer->size),
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
381 the_rate));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
382
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
383 /* allocate buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
384 if (!(buffer->data = g_malloc0(buffer->size)))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
385 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
386 DEBUG(("[crossfade] open_output: error allocating buffer!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
387 the_op->close_audio();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
388 the_op = NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
389 return -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
390 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
391
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
392 /* reset buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
393 buffer_reset(buffer, config);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
394
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
395 /* make sure stopped is TRUE -- otherwise the buffer thread would
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
396 * stop again immediatelly after it has been started. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
397 stopped = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
398
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
399 /* create and run buffer thread */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
400 if (THREAD_CREATE(buffer_thread, buffer_thread_f))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
401 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
402 PERROR("[crossfade] open_output: thread_create()");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
403 g_free(buffer->data);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
404 the_op->close_audio();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
405 the_op = NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
406 return -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
407 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
408 SCHED_YIELD;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
409
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
410 /* done */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
411 output_opened = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
412 return 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
413 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
414
3065
a0ba6102131d crossfade-ng: remove more cruft, kill some warnings.
William Pitcock <nenolod@atheme.org>
parents: 3064
diff changeset
415 static OutputPluginInitStatus
3059
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
416 xfade_init()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
417 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
418 /* load config */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
419 memset(config, 0, sizeof(*config));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
420 *config = config_default;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
421 xfade_load_config();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
422
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
423 /* set default strings if there is no existing config */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
424 if (!config->oss_alt_audio_device) config->oss_alt_audio_device = g_strdup(DEFAULT_OSS_ALT_AUDIO_DEVICE);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
425 if (!config->oss_alt_mixer_device) config->oss_alt_mixer_device = g_strdup(DEFAULT_OSS_ALT_MIXER_DEVICE);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
426 if (!config->op_config_string) config->op_config_string = g_strdup(DEFAULT_OP_CONFIG_STRING);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
427 if (!config->op_name) config->op_name = g_strdup(DEFAULT_OP_NAME);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
428
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
429 /* check for realtime priority, it needs some special attention */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
430 realtime = xfplayer_check_realtime_priority();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
431
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
432 /* init contexts */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
433 convert_init(&convert_context);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
434 #ifdef HAVE_LIBFFTW
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
435 fft_init(&fft_context);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
436 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
437
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
438 /* reset */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
439 stopped = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
440
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
441 /* find current output plugin early so that volume control works
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
442 * even if playback has not started yet. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
443 if (!(the_op = find_output()))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
444 DEBUG(("[crossfade] init: could not find any output!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
445
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
446 /* load any dynamic linked symbols */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
447 load_symbols();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
448
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
449 /* realize config -- will also setup the pre-mixing effect plugin */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
450 xfade_realize_config();
3065
a0ba6102131d crossfade-ng: remove more cruft, kill some warnings.
William Pitcock <nenolod@atheme.org>
parents: 3064
diff changeset
451
a0ba6102131d crossfade-ng: remove more cruft, kill some warnings.
William Pitcock <nenolod@atheme.org>
parents: 3064
diff changeset
452 return OUTPUT_PLUGIN_INIT_NO_DEVICES;
3059
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
453 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
454
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
455 static void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
456 load_symbols()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
457 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
458 #ifdef HAVE_DLFCN_H
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
459 void *handle;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
460 char *error;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
461 gchar **xmms_cfg;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
462 gchar * (*get_gentitle_format)();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
463
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
464 /* open ourselves (that is, the XMMS binary) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
465 handle = dlopen(NULL, RTLD_NOW);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
466 if (!handle)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
467 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
468 DEBUG(("[crossfade] init: dlopen(NULL) failed!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
469 return;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
470 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
471
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
472 /* check for XMMS patches */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
473 DEBUG(("[crossfade] load_symbols: input_stopped_for_restart:"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
474 input_stopped_for_restart = dlsym(handle, "input_stopped_for_restart");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
475 DEBUG((!(error = dlerror())? " found\n" : " missing\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
476
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
477 DEBUG(("[crossfade] load_symbols: is_quitting:"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
478 xmms_is_quitting = dlsym(handle, "is_quitting");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
479 DEBUG((!(error = dlerror())? " found\n" : " missing\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
480
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
481 DEBUG(("[crossfade] load_symbols: playlist_get_fadeinfo:"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
482 playlist_get_fadeinfo = dlsym(handle, "playlist_get_fadeinfo");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
483 DEBUG((!(error = dlerror())? " found\n" : " missing\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
484
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
485 /* check for some XMMS functions */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
486 xmms_playlist_get_info_going = dlsym(handle, "playlist_get_info_going");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
487 xmms_input_get_song_info = dlsym(handle, "input_get_song_info");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
488
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
489 /* HACK: direct access to XMMS' config 'gentitle_format' */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
490 xmms_cfg = dlsym(handle, "cfg");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
491 get_gentitle_format = dlsym(handle, "xmms_get_gentitle_format");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
492 if (xmms_cfg && get_gentitle_format)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
493 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
494 gchar *format = get_gentitle_format();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
495
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
496 int i = 128;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
497 gchar **p = (gchar **)xmms_cfg;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
498 for (i = 128; i > 0 && *p != format; i--, p++);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
499 if (*p == format)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
500 xmms_gentitle_format = p;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
501 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
502
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
503 dlclose(handle);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
504 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
505 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
506
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
507 void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
508 xfade_get_volume(int *l, int *r)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
509 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
510 if (config->mixer_software)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
511 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
512 *l = config->mixer_reverse
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
513 ? config->mixer_vol_right
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
514 : config->mixer_vol_left;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
515 *r = config->mixer_reverse
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
516 ? config->mixer_vol_left
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
517 : config->mixer_vol_right;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
518 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
519 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
520 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
521 if (the_op && the_op->get_volume)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
522 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
523 if (config->mixer_reverse)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
524 the_op->get_volume(r, l);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
525 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
526 the_op->get_volume(l, r);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
527 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
528 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
529
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
530 /* DEBUG(("[crossfade] xfade_get_volume: l=%d r=%d\n", *l, *r)); */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
531 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
532
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
533 void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
534 xfade_set_volume(int l, int r)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
535 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
536 /* DEBUG(("[crossfade] xfade_set_volume: l=%d r=%d\n", l, r)); */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
537
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
538 if (!config->enable_mixer)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
539 return;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
540
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
541 if (the_op && the_op->set_volume)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
542 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
543 if (config->mixer_reverse)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
544 the_op->set_volume(r, l);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
545 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
546 the_op->set_volume(l, r);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
547 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
548 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
549
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
550 /*** buffer stuff ***********************************************************/
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
551
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
552 static void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
553 buffer_mfg_reset(buffer_t *buf, config_t *cfg)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
554 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
555 buf->mix = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
556 buf->fade = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
557 buf->gap = (cfg->gap_lead_enable ? MS2B(cfg->gap_lead_len_ms) & -4 : 0);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
558 buf->gap_len = buf->gap;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
559 buf->gap_level = cfg->gap_lead_level;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
560 buf->gap_killed = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
561 buf->skip = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
562 buf->skip_len = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
563 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
564
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
565 static void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
566 buffer_reset(buffer_t *buf, config_t *cfg)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
567 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
568 buffer_mfg_reset(buf, cfg);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
569
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
570 buf->rd_index = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
571 buf->used = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
572 buf->preload = buf->preload_size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
573
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
574 buf->silence = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
575 buf->silence_len = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
576 buf->reopen = -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
577 buf->pause = -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
578 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
579
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
580 /****************************************************************************/
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
581
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
582 static void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
583 xfade_apply_fade_config(fade_config_t *fc)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
584 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
585 gint out_skip, in_skip;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
586 gint avail, out_len, in_len, offset, preload;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
587 gint index, length, fade, n;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
588 gfloat out_scale, in_scale;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
589 gboolean out_skip_clipped = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
590 gboolean out_len_clipped = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
591 gboolean offset_clipped = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
592
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
593 /* Overwrites mix and fade; may add silence */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
594
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
595 /*
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
596 * Example 1: offset < 0 --> mix streams together
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
597 * Example 2: offset > 0 --> insert pause between streams
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
598 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
599 * |----- out_len -----| * |out_len|
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
600 * | | * | |
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
601 * ~~~~~-_ /T~~~~~~~T~~ * ~~~~~\ | /T~~
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
602 * ~-_ / | | * \ | / |
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
603 * ~-_/ | | * \ | / |
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
604 * /~-_| | * \ | / |
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
605 * / T-_ | * \ | / |
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
606 * / | ~-_ | * \ | / |
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
607 * _________/______|_____~-|__ * ___________\__________/______|__
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
608 * |in_len| | * | |in_len|
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
609 * |<-- offset ---| * |offset-->|
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
610 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
611 * a) avail: max(0, used - preload)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
612 * b) out_len: 0 .. avail
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
613 * c) in_len: 0 .. #
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
614 * d) offset: -avail .. buffer->mix_size - out_size
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
615 * e) skip: min(used, preload)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
616 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
617 */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
618
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
619 out_scale = 1.0f - (gfloat) xfade_cfg_fadeout_volume(fc) / 100.0f;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
620 in_scale = 1.0f - (gfloat) xfade_cfg_fadein_volume (fc) / 100.0f;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
621
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
622 /* rules (see above) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
623 /* a: leave preload untouched */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
624 avail = buffer->used - buffer->preload_size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
625 if (avail < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
626 avail = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
627
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
628 /* skip end of song */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
629 out_skip = MS2B(xfade_cfg_out_skip(fc)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
630 if (out_skip > avail)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
631 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
632 DEBUG(("[crossfade] apply_fade_config: WARNING: clipping out_skip (%d -> %d)!\n", B2MS(out_skip), B2MS(avail)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
633 out_skip = avail;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
634 out_skip_clipped = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
635 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
636
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
637 if (out_skip > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
638 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
639 buffer->used -= out_skip;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
640 avail -= out_skip;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
641 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
642
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
643 /* b: fadeout */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
644 out_len = MS2B(xfade_cfg_fadeout_len(fc)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
645 if (out_len > avail)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
646 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
647 DEBUG(("[crossfade] apply_fade_config: WARNING: clipping out_len (%d -> %d)!\n", B2MS(out_len), B2MS(avail)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
648 out_len = avail;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
649 out_len_clipped = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
650 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
651 else if (out_len < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
652 out_len = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
653
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
654 /* skip beginning of song */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
655 in_skip = MS2B(xfade_cfg_in_skip(fc)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
656 if (in_skip < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
657 in_skip = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
658
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
659 /* c: fadein */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
660 in_len = MS2B(xfade_cfg_fadein_len(fc)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
661 if (in_len < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
662 in_len = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
663
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
664 /* d: offset (mixing point) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
665 offset = MS2B(xfade_cfg_offset(fc)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
666 if (offset < -avail)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
667 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
668 DEBUG(("[crossfade] apply_fade_config: WARNING: clipping offset (%d -> %d)!\n", B2MS(offset), -B2MS(avail)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
669 offset = -avail;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
670 offset_clipped = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
671 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
672 if (offset > (buffer->mix_size - out_len))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
673 offset = buffer->mix_size - out_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
674
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
675 /* e */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
676 preload = buffer->preload_size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
677 if (preload > buffer->used)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
678 preload = buffer->used;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
679
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
680 /* cut off rest of stream (decreases latency on manual songchange) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
681 if (fc->flush)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
682 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
683 gint cutoff = avail - MAX(out_len, -offset); /* MAX() -> glib.h */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
684 if (cutoff > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
685 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
686 DEBUG(("[crossfade] apply_fade_config: %d ms flushed\n", B2MS(cutoff)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
687 buffer->used -= cutoff;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
688 avail -= cutoff;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
689 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
690
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
691 /* make sure there is no pending silence */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
692 buffer->silence = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
693 buffer->silence_len = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
694 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
695
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
696 /* begin modifying buffer at index */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
697 index = (buffer->rd_index + buffer->used - out_len) % buffer->size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
698
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
699 /* fade out (modifies buffer directly) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
700 fade = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
701 length = out_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
702 while (length > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
703 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
704 gint16 *p = buffer->data + index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
705 gint blen = buffer->size - index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
706 if (blen > length) blen = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
707
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
708 for (n = blen / 4; n > 0; n--)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
709 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
710 gfloat factor = 1.0f - (((gfloat) fade / out_len) * out_scale);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
711 *p = (gfloat)*p * factor; p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
712 *p = (gfloat)*p * factor; p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
713 fade += 4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
714 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
715
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
716 index = (index + blen) % buffer->size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
717 length -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
718 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
719
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
720 /* Initialize fadein. Note that the actual fading / mixing will be done
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
721 * on-the-fly when audio data is received by xfade_write_audio() */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
722
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
723 /* start skipping */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
724 if (in_skip > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
725 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
726 buffer->skip = in_skip;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
727 buffer->skip_len = in_skip;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
728 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
729 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
730 buffer->skip = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
731
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
732 /* start fading in */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
733 if (in_len > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
734 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
735 buffer->fade = in_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
736 buffer->fade_len = in_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
737 buffer->fade_scale = in_scale;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
738 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
739 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
740 buffer->fade = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
741
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
742 /* start mixing */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
743 if (offset < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
744 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
745 length = -offset;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
746 buffer->mix = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
747 buffer->used -= length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
748 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
749 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
750 buffer->mix = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
751
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
752 /* start silence if applicable (will be applied in buffer_thread_f) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
753 if (offset > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
754 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
755 if ((buffer->silence > 0) || (buffer->silence_len > 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
756 DEBUG(("[crossfade] apply_config: WARNING: silence in progress (%d/%d ms)\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
757 B2MS(buffer->silence), B2MS(buffer->silence_len)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
758
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
759 buffer->silence = buffer->used;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
760 buffer->silence_len = offset;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
761 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
762
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
763 /* done */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
764 if (in_skip || out_skip)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
765 DEBUG(("[crossfade] apply_fade_config: out_skip=%d in_skip=%d\n", B2MS(out_skip), B2MS(in_skip)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
766 DEBUG(("[crossfade] apply_fade_config: avail=%d out=%d in=%d offset=%d preload=%d\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
767 B2MS(avail), B2MS(out_len), B2MS(in_len), B2MS(offset), B2MS(preload)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
768 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
769
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
770 static gint
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
771 extract_track(const gchar *name)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
772 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
773 #if 1
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
774 /* skip non-digits at beginning */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
775 while (*name && !isdigit(*name))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
776 name++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
777
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
778 return atoi(name);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
779 #else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
780 /* Remove all but numbers.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
781 * Will not work if a filename has number in the title, like "track-03-U2.mp3"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
782 * Ideally, should look into id3 track entry and fallback to filename
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
783 * */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
784 gchar temp[8];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
785 int t = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
786
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
787 memset(temp, 0, sizeof(temp));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
788 while (*name != '\0' && t < sizeof(temp))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
789 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
790 if (strcmp(name, "mp3") == 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
791 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
792
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
793 if (isdigit(*name))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
794 temp[t++] = *name;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
795
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
796 name++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
797 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
798 return atoi(temp);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
799 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
800 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
801
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
802 static gint
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
803 album_match(gchar *old, gchar *new)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
804 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
805 gchar *old_dir, *new_dir;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
806 gboolean same_dir;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
807 gint old_track = 0, new_track = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
808
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
809 if (!old || !new)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
810 return 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
811
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
812 old_dir = g_dirname(old);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
813 new_dir = g_dirname(new);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
814 same_dir = !strcmp(old_dir, new_dir);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
815 g_free(old_dir);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
816 g_free(new_dir);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
817
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
818 if (!same_dir)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
819 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
820 DEBUG(("[crossfade] album_match: no match (different dirs)\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
821 return 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
822 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
823
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
824 old_track = extract_track(g_basename(old));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
825 new_track = extract_track(g_basename(new));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
826
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
827 if (new_track <= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
828 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
829 DEBUG(("[crossfade] album_match: can't parse track number:\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
830 DEBUG(("[crossfade] album_match: ... \"%s\"\n", g_basename(new)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
831 return 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
832 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
833
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
834 if ((old_track < 0) || (old_track + 1 != new_track))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
835 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
836 DEBUG(("[crossfade] album_match: no match (same dir, but non-successive (%d, %d))\n", old_track, new_track));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
837 return 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
838 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
839
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
840 DEBUG(("[crossfade] album_match: match detected (same dir, successive tracks (%d, %d))\n", old_track, new_track));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
841
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
842 return old_track;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
843 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
844
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
845 static gint
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
846 xfade_open_audio(AFormat fmt, int rate, int nch)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
847 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
848 gint pos;
3064
43a336a7791b crossfade-ng: Remove remaining TIMING_COMMENTS cruft.
William Pitcock <nenolod@atheme.org>
parents: 3059
diff changeset
849 gchar *file, *title;
3059
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
850
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
851 struct timeval tv;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
852 glong dt;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
853
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
854 DEBUG(("[crossfade]\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
855 DEBUG(("[crossfade] open_audio: pid=%d\n", (int) getpid()));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
856
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
857 /* sanity... don't do anything about it */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
858 if (opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
859 DEBUG(("[crossfade] open_audio: WARNING: already opened!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
860
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
861 /* get filename */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
862 pos = xfplaylist_get_position ();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
863 file = xfplaylist_get_filename (pos);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
864 title = xfplaylist_get_songtitle(pos);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
865
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
866 if (!file)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
867 file = g_strdup(title);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
868
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
869 DEBUG(("[crossfade] open_audio: bname=\"%s\"\n", g_basename(file)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
870 DEBUG(("[crossfade] open_audio: title=\"%s\"\n", title));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
871
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
872 #if 0
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
873 /* HACK: try to get comment and track number from xmms by sneaking in a custom title format */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
874 if (xmms_gentitle_format)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
875 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
876 gchar *old_gentitle_format = *xmms_gentitle_format;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
877
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
878 gchar *temp_title = NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
879 gint temp_length = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
880
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
881 xmms_input_get_song_info(file, &temp_title, &temp_length);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
882 DEBUG(("[crossfade] open_audio: TITLE: %s\n", temp_title));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
883 g_free(temp_title);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
884
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
885 *xmms_gentitle_format = "%n/%c";
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
886
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
887 xmms_input_get_song_info(file, &temp_title, &temp_length);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
888 DEBUG(("[crossfade] open_audio: TRACK/COMMENT: %s\n", temp_title));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
889 g_free(temp_title);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
890
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
891 *xmms_gentitle_format = old_gentitle_format;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
892 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
893 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
894
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
895 /* is this an automatic crossfade? */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
896 if (last_filename && (fade_config == &config->fc[FADE_CONFIG_XFADE]))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
897 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
898 /* check if next song is the same as the current one */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
899 if (config->no_xfade_if_same_file && !strcmp(last_filename, file))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
900 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
901 DEBUG(("[crossfade] open_audio: same file, disabling crossfade\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
902 fade_config = &config->fc[FADE_CONFIG_ALBUM];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
903 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
904
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
905 /* check if next song is the next song from the same album */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
906 else if (config->album_detection && album_match(last_filename, file))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
907 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
908 gboolean use_fc_album = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
909
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
910 if (xfade_cfg_gap_trail_enable(config))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
911 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
912 DEBUG(("[crossfade] album_match: "
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
913 "trailing gap: length=%d/%d ms\n", B2MS(buffer->gap_killed), B2MS(buffer->gap_len)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
914
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
915 if (buffer->gap_killed < buffer->gap_len)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
916 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
917 DEBUG(("[crossfade] album_match: "
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
918 "trailing gap: -> no silence, probably pre-faded\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
919 use_fc_album = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
920 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
921 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
922 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
923 DEBUG(("[crossfade] album_match: " "trailing gap: -> silence, sticking to XFADE\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
924 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
925 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
926 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
927 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
928 DEBUG(("[crossfade] album_match: " "trailing gap killer disabled\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
929 use_fc_album = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
930 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
931
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
932 if (use_fc_album)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
933 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
934 DEBUG(("[crossfade] album_match: " "-> using FADE_CONFIG_ALBUM\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
935 fade_config = &config->fc[FADE_CONFIG_ALBUM];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
936 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
937 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
938 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
939 g_free(last_filename);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
940 last_filename = g_strdup(file);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
941
3072
8f56795e348d crossfade-ng: correctly workaround possible buffer starvation issues with streams
William Pitcock <nenolod@atheme.org>
parents: 3066
diff changeset
942 /* check for streaming */
8f56795e348d crossfade-ng: correctly workaround possible buffer starvation issues with streams
William Pitcock <nenolod@atheme.org>
parents: 3066
diff changeset
943 if (aud_vfs_is_remote(file))
3059
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
944 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
945 DEBUG(("[crossfade] open_audio: HTTP underrun workaround enabled.\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
946 is_http = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
947 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
948 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
949 is_http = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
950
3072
8f56795e348d crossfade-ng: correctly workaround possible buffer starvation issues with streams
William Pitcock <nenolod@atheme.org>
parents: 3066
diff changeset
951 g_free(file); file = NULL;
8f56795e348d crossfade-ng: correctly workaround possible buffer starvation issues with streams
William Pitcock <nenolod@atheme.org>
parents: 3066
diff changeset
952 g_free(title); title = NULL;
8f56795e348d crossfade-ng: correctly workaround possible buffer starvation issues with streams
William Pitcock <nenolod@atheme.org>
parents: 3066
diff changeset
953
3059
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
954 /* lock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
955 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
956
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
957 /* reset writer timeout */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
958 gettimeofday(&last_write, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
959
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
960 /* calculate time since last close() (don't care about overflows at 24h) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
961 if (output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
962 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
963 gettimeofday(&tv, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
964 dt = (tv.tv_sec - last_close.tv_sec) * 1000 + (tv.tv_usec - last_close.tv_usec) / 1000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
965 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
966 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
967 dt = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
968
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
969 DEBUG(("[crossfade] open_audio: fmt=%s rate=%d nch=%d dt=%ld ms\n", format_name(fmt), rate, nch, dt));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
970
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
971 /* check format */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
972 if (setup_format(fmt, rate, nch, &in_format) < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
973 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
974 DEBUG(("[crossfade] open_audio: format not supported!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
975 return 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
976 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
977
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
978 /* (re)open the device if necessary */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
979 if (!output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
980 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
981 if (open_output())
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
982 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
983 DEBUG(("[crossfade] open_audio: error opening/configuring output!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
984 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
985 return 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
986 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
987 fade_config = &config->fc[FADE_CONFIG_START];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
988 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
989
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
990 /* reset */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
991 streampos = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
992 playing = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
993 opened = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
994 paused = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
995
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
996 /* reset mix/fade/gap */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
997 buffer_mfg_reset(buffer, config);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
998
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
999 /* enable gap killer / zero crossing only for automatic/album songchange */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1000 switch (fade_config->config)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1001 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1002 case FADE_CONFIG_XFADE:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1003 case FADE_CONFIG_ALBUM:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1004 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1005
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1006 default:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1007 buffer->gap = GAP_SKIPPING_DONE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1008 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1009
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1010 /* restart realtime throttling */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1011 output_written = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1012
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1013 /* start mixing */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1014 switch (fade_config ? fade_config->type : -1)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1015 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1016 case FADE_TYPE_FLUSH:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1017 DEBUG(("[crossfade] open_audio: FLUSH:\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1018
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1019 /* flush output plugin */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1020 the_op->flush(0);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1021 output_streampos = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1022
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1023 /* flush buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1024 buffer_reset(buffer, config);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1025
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1026 /* apply fade config (pause/fadein after flush) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1027 xfade_apply_fade_config(fade_config);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1028
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1029 /* also repopen device (if configured so in the plugin compat. options) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1030 if (the_op_config.force_reopen)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1031 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1032 buffer->reopen = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1033 buffer->reopen_sync = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1034 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1035 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1036
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1037 case FADE_TYPE_REOPEN:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1038 DEBUG(("[crossfade] open_audio: REOPEN:\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1039
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1040 /* flush buffer if applicable */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1041 if (fade_config->flush)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1042 buffer_reset(buffer, config);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1043
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1044 if (buffer->reopen >= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1045 DEBUG(("[crossfade] open_audio: REOPEN: WARNING: reopen in progress (%d ms)\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1046 B2MS(buffer->reopen)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1047
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1048 /* start reopen countdown (will be executed in buffer_thread_f) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1049 buffer->reopen = buffer->used; /* may be 0 */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1050 buffer->reopen_sync = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1051 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1052
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1053 case FADE_TYPE_NONE:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1054 case FADE_TYPE_PAUSE:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1055 case FADE_TYPE_SIMPLE_XF:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1056 case FADE_TYPE_ADVANCED_XF:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1057 case FADE_TYPE_FADEIN:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1058 case FADE_TYPE_FADEOUT:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1059 DEBUG(("[crossfade] open_audio: XFADE:\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1060
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1061 /* apply fade config (do fadeout, init mix/fade/gap, add silence) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1062 xfade_apply_fade_config(fade_config);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1063
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1064 /* set reopen countdown. after buffer_thread_f has written
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1065 * buffer->reopen bytes, it will close/reopen the output plugin. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1066 if (the_op_config.force_reopen && !(fade_config->config == FADE_CONFIG_START))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1067 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1068 if (buffer->reopen >= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1069 DEBUG(("[crossfade] open_audio: XFADE: WARNING: reopen in progress (%d ms)\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1070 B2MS(buffer->reopen)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1071 buffer->reopen = buffer->used;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1072 buffer->reopen_sync = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1073 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1074 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1075 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1076
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1077 /* calculate offset of the output plugin */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1078 output_offset = the_op->written_time() + B2MS(buffer->used) + B2MS(buffer->silence_len);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1079
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1080 /* unlock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1081 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1082
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1083 /* done */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1084 return 1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1085 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1086
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1087 void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1088 xfade_write_audio(void *ptr, int length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1089 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1090 gint free;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1091 gint ofs = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1092 format_t format;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1093
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1094 #ifdef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1095 DEBUG(("[crossfade] write_audio: ptr=0x%08lx, length=%d\n", (long) ptr, length));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1096 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1097
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1098 /* sanity */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1099 if (length <= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1100 return;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1101
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1102 if (length & 3)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1103 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1104 DEBUG(("[crossfade] write_audio: truncating %d bytes!\n", length & 3));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1105 length &= -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1106 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1107
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1108 /* update input accumulator (using input format size) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1109 streampos += length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1110
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1111 /* convert sample format (signed-16bit-ne 44100hz stereo) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1112 format_copy(&format, &in_format);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1113 length = convert_flow(&convert_context, (gpointer *) &ptr, length, &format);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1114
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1115 /* lock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1116 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1117
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1118 /* check if device has been closed, reopen if necessary */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1119 if (!output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1120 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1121 if (open_output())
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1122 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1123 DEBUG(("[crossfade] write_audio: reopening failed!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1124 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1125 return;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1126 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1127 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1128
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1129 /* reset timeout */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1130 gettimeofday(&last_write, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1131
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1132 /* calculate free buffer space, check for overflow (should never happen :) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1133 free = buffer->size - buffer->used;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1134 if (length > free)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1135 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1136 DEBUG(("[crossfade] write_audio: %d bytes truncated!\n", length - free));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1137 length = free;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1138 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1139
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1140 /* skip beginning of song */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1141 if ((length > 0) && (buffer->skip > 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1142 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1143 gint blen = MIN(length, buffer->skip);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1144
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1145 buffer->skip -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1146 length -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1147 ptr += blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1148 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1149
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1150 /* kill leading gap */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1151 if ((length > 0) && (buffer->gap > 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1152 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1153 gint blen = MIN(length, buffer->gap);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1154 gint16 *p = ptr;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1155 gint index = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1156
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1157 gint16 left, right;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1158 while (index < blen)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1159 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1160 left = *p++, right = *p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1161 if (ABS(left) >= buffer->gap_level) break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1162 if (ABS(right) >= buffer->gap_level) break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1163 index += 4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1164 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1165
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1166 buffer->gap -= index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1167 length -= index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1168 ptr += index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1169
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1170 if ((index < blen) || (buffer->gap <= 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1171 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1172 buffer->gap_killed = buffer->gap_len - buffer->gap;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1173 buffer->gap = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1174
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1175 DEBUG(("[crossfade] write_audio: leading gap size: %d/%d ms\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1176 B2MS(buffer->gap_killed), B2MS(buffer->gap_len)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1177
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1178 /* fix streampos */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1179 streampos -= (gint64) buffer->gap_killed * in_format.bps / out_format.bps;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1180 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1181 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1182
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1183 /* start skipping to next crossing (if enabled) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1184 if (buffer->gap == 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1185 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1186 if (config->gap_crossing)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1187 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1188 buffer->gap = GAP_SKIPPING_POSITIVE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1189 buffer->gap_skipped = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1190 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1191 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1192 buffer->gap = GAP_SKIPPING_DONE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1193 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1194
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1195 /* skip until next zero crossing (pos -> neg) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1196 if ((length > 0) && (buffer->gap == GAP_SKIPPING_POSITIVE))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1197 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1198 gint16 *p = ptr;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1199 gint index = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1200
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1201 gint16 left;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1202 while (index < length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1203 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1204 left = *p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1205 p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1206 if (left < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1207 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1208 index += 4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1209 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1210
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1211 buffer->gap_skipped += index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1212 length -= index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1213 ptr += index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1214
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1215 if (index < length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1216 buffer->gap = GAP_SKIPPING_NEGATIVE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1217 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1218
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1219 /* skip until next zero crossing (neg -> pos) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1220 if ((length > 0) && (buffer->gap == GAP_SKIPPING_NEGATIVE))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1221 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1222 gint16 *p = ptr;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1223 gint index = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1224
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1225 gint16 left;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1226 while (index < length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1227 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1228 left = *p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1229 p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1230 if (left >= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1231 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1232 index += 4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1233 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1234
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1235 buffer->gap_skipped += index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1236 length -= index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1237 ptr += index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1238
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1239 if (index < length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1240 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1241 DEBUG(("[crossfade] write_audio: %d samples to next crossing\n", buffer->gap_skipped));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1242 buffer->gap = GAP_SKIPPING_DONE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1243 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1244 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1245
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1246 /* update preload. the buffer thread will not write any
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1247 * data to the device before preload is decreased below 1. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1248 if ((length > 0) && (buffer->preload > 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1249 buffer->preload -= length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1250
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1251 /* fadein -- FIXME: is modifying the input/effect buffer safe? */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1252 if ((length > 0) && (buffer->fade > 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1253 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1254 gint16 *p = ptr;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1255 gint blen = MIN(length, buffer->fade);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1256 gint n;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1257
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1258 for (n = blen / 4; n > 0; n--)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1259 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1260 gfloat factor = 1.0f - (((gfloat) buffer->fade / buffer->fade_len) * buffer->fade_scale);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1261 *p = (gfloat)*p * factor; p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1262 *p = (gfloat)*p * factor; p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1263 buffer->fade -= 4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1264 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1265 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1266
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1267 /* mix */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1268 while ((length > 0) && (buffer->mix > 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1269 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1270 gint wr_index = (buffer->rd_index + buffer->used) % buffer->size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1271 gint blen = buffer->size - wr_index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1272 gint16 *p1 = buffer->data + wr_index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1273 gint16 *p2 = ptr + ofs;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1274 gint n;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1275
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1276 if (blen > length) blen = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1277 if (blen > buffer->mix) blen = buffer->mix;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1278
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1279 for (n = blen / 2; n > 0; n--)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1280 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1281 gint out = (gint)*p1 + *p2++; /* add */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1282 if (out > 32767) /* clamp */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1283 *p1++ = 32767;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1284 else if (out < -32768)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1285 *p1++ = -32768;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1286 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1287 *p1++ = out;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1288 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1289
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1290 buffer->used += blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1291 buffer->mix -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1292 length -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1293 ofs += blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1294 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1295
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1296 /* normal write */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1297 while (length > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1298 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1299 gint wr_index = (buffer->rd_index + buffer->used) % buffer->size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1300 gint blen = buffer->size - wr_index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1301
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1302 if (blen > length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1303 blen = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1304
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1305 memcpy(buffer->data + wr_index, ptr + ofs, blen);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1306
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1307 buffer->used += blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1308 length -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1309 ofs += blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1310 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1311
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1312 /* unlock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1313 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1314 #ifdef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1315 DEBUG(("[crossfade] write_audio: done.\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1316 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1317 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1318
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1319 /* sync_output: wait for output plugin to finish playback */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1320 /* is only called from within buffer_thread_f */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1321 static void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1322 sync_output()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1323 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1324 glong dt, total;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1325 gint opt, opt_last;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1326 struct timeval tv, tv_start, tv_last_change;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1327 gboolean was_closed = !opened;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1328
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1329 if (!the_op->buffer_playing || !the_op->buffer_playing())
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1330 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1331 DEBUG(("[crossfade] sync_output: nothing to do\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1332 return;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1333 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1334
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1335 DEBUG(("[crossfade] sync_output: waiting for plugin...\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1336
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1337 dt = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1338 opt_last = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1339 gettimeofday(&tv_start, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1340 gettimeofday(&tv_last_change, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1341
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1342 while ((dt < SYNC_OUTPUT_TIMEOUT)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1343 && !stopped && output_opened && !(was_closed && opened) && the_op && the_op->buffer_playing())
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1344 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1345
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1346 /* use output_time() to check if the output plugin is still active */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1347 if (the_op->output_time)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1348 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1349 opt = the_op->output_time();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1350 if (opt != opt_last)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1351 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1352 /* output_time has changed */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1353 opt_last = opt;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1354 gettimeofday(&tv_last_change, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1355 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1356 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1357 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1358 /* calculate time since last change of the_op->output_time() */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1359 gettimeofday(&tv, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1360 dt = (tv.tv_sec - tv_last_change.tv_sec) * 1000 + (tv.tv_usec - tv_last_change.tv_usec) / 1000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1361 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1362 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1363
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1364 /* yield */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1365 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1366 xfade_usleep(10000);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1367 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1368 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1369
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1370 /* calculate total time we spent in here */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1371 gettimeofday(&tv, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1372 total = (tv.tv_sec - tv_start.tv_sec) * 1000 + (tv.tv_usec - tv_start.tv_usec) / 1000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1373
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1374 /* print some debug info */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1375 /* *INDENT-OFF* */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1376 if (stopped)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1377 DEBUG(("[crossfade] sync_output: ... stopped\n"))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1378 else if (was_closed && opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1379 DEBUG(("[crossfade] sync_output: ... reopened\n"))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1380 else if (dt >= SYNC_OUTPUT_TIMEOUT)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1381 DEBUG(("[crossfade] sync_output: ... TIMEOUT! (%ld ms)\n", total))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1382 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1383 DEBUG(("[crossfade] sync_output: ... done (%ld ms)\n", total));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1384 /* *INDENT-ON* */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1385 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1386
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1387 void *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1388 buffer_thread_f(void *arg)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1389 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1390 gpointer data;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1391 gint sync;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1392 gint op_free;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1393 gint length_bak, length, blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1394 glong timeout, dt;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1395 gboolean stopping;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1396
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1397 struct timeval tv;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1398 struct timeval mark;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1399
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1400 DEBUG(("[crossfade] buffer_thread_f: thread started (pid=%d)\n", (int) getpid()));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1401
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1402 /* lock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1403 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1404
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1405 while (!stopped)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1406 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1407 /* yield */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1408 #ifdef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1409 DEBUG(("[crossfade] buffer_thread_f: yielding...\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1410 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1411 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1412 xfade_usleep(10000);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1413 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1414
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1415 /* --------------------------------------------------------------------- */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1416
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1417 stopping = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1418
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1419 /* V0.3.0: New timeout detection */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1420 if (!opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1421 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1422 gboolean current = xfplayer_input_playing();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1423
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1424 /* also see fini() */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1425 if (last_close.tv_sec || last_close.tv_usec)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1426 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1427 gettimeofday(&tv, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1428 timeout = (tv.tv_sec - last_close.tv_sec) * 1000
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1429 + (tv.tv_usec - last_close.tv_usec) / 1000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1430 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1431 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1432 timeout = -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1433
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1434 if (current != input_playing)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1435 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1436 input_playing = current;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1437
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1438 if (current)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1439 DEBUG(("[crossfade] buffer_thread_f: input restarted after %ld ms\n", timeout))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1440 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1441 DEBUG(("[crossfade] buffer_thread_f: input stopped after + %ld ms\n", timeout));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1442 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1443
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1444 /* 0.3.0: HACK: output_keep_opened: play silence during prebuffering */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1445 if (input_playing && config->output_keep_opened && (buffer->used == 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1446 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1447 buffer->silence = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1448 buffer->silence_len = MS2B(100);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1449 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1450
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1451 /* 0.3.9: Check for timeout only if we have not been stopped for restart */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1452 /* 0.3.11: When using the songchange hack, depend on it's output_restart
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1453 * flag. Without the hack, use the configuration's dialog songchange
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1454 * timeout setting instead of a fixed timeout value. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1455 if (input_stopped_for_restart && !output_restart)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1456 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1457 if (playing)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1458 DEBUG(("[crossfade] buffer_thread_f: timeout:"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1459 " stopping after %ld ms (songchange patch)\n", timeout));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1460 stopping = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1461 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1462 else if (((timeout < 0) || (timeout >= config->songchange_timeout && !output_restart)) && !input_playing)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1463 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1464 if (playing)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1465 DEBUG(("[crossfade] buffer_thread_f: timeout:"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1466 " input did not restart after %ld ms\n", timeout));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1467 stopping = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1468 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1469 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1470
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1471 /* V0.2.4: Moved the timeout checks in front of the buffer_free() check
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1472 * below. Before, buffer_thread_f could (theoretically) loop
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1473 * endlessly if buffer_free() returned 0 all the time. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1474
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1475 /* calculate time since last write to the buffer (ignore overflows) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1476 gettimeofday(&tv, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1477 timeout = (tv.tv_sec - last_write.tv_sec) * 1000
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1478 + (tv.tv_usec - last_write.tv_usec) / 1000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1479
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1480 /* check for timeout/eop (note this is the only way out of this loop) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1481 if (stopping)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1482 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1483 if (playing)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1484 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1485 DEBUG(("[crossfade] buffer_thread_f: timeout: manual stop\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1486
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1487 /* if CONFIG_STOP is of TYPE_NONE, immediatelly close the device... */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1488 if ((config->fc[FADE_CONFIG_STOP].type == FADE_TYPE_NONE) && !config->output_keep_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1489 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1490
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1491 /* special handling for pause */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1492 if (paused)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1493 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1494 DEBUG(("[crossfade] buffer_thread_f: timeout: paused, closing now...\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1495 paused = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1496 if (config->output_keep_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1497 the_op->pause(0);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1498 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1499 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1500 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1501 else if (buffer->pause >= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1502 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1503 DEBUG(("[crossfade] buffer_thread_f: timeout: cancelling pause countdown\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1504 buffer->pause = -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1505 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1506
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1507 /* ...otherwise, do the fadeout first */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1508 xfade_apply_fade_config(&config->fc[FADE_CONFIG_STOP]);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1509
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1510 /* force CONFIG_START in case the user restarts playback during fadeout */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1511 fade_config = &config->fc[FADE_CONFIG_START];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1512 playing = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1513 eop = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1514 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1515 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1516 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1517 if (!eop)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1518 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1519 DEBUG(("[crossfade] buffer_thread_f: timeout: end of playback\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1520
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1521 /* 0.3.3: undo trailing gap killer at end of playlist */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1522 if (buffer->gap_killed)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1523 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1524 buffer->used += buffer->gap_killed;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1525 DEBUG(("[crossfade] buffer_thread_f: timeout:"
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1526 " undoing trailing gap (%d ms)\n", B2MS(buffer->gap_killed)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1527 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1528
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1529 /* do the fadeout if applicable */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1530 if (config->fc[FADE_CONFIG_EOP].type != FADE_TYPE_NONE)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1531 xfade_apply_fade_config(&config->fc[FADE_CONFIG_EOP]);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1532
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1533 fade_config = &config->fc[FADE_CONFIG_START]; /* see above */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1534 eop = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1535 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1536
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1537 if (buffer->used == 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1538 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1539 if (config->output_keep_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1540 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1541 /* 0.3.0: play silence while keeping the output opened */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1542 buffer->silence = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1543 buffer->silence_len = MS2B(100);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1544 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1545 else if (buffer->silence_len <= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1546 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1547 sync_output();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1548 if (opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1549 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1550 DEBUG(("[crossfade] buffer_thread_f: timeout, eop: device has been reopened\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1551 DEBUG(("[crossfade] buffer_thread_f: timeout, eop: -> continuing playback\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1552 eop = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1553 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1554 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1555 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1556 DEBUG(("[crossfade] buffer_thread_f: timeout, eop: closing output...\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1557 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1558 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1559 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1560 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1561 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1562 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1563 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1564 eop = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1565
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1566 /* --------------------------------------------------------------------- */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1567
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1568 /* get free space in device output buffer
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1569 * NOTE: disk_writer always returns <big int> here */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1570 op_free = the_op->buffer_free() & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1571
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1572 /* continue waiting if there is no room in the device buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1573 if (op_free == 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1574 continue;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1575
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1576 /* --- Limit OP buffer use (decreases latency) ------------------------- */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1577
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1578 /* HACK: limit output plugin buffer usage to decrease latency */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1579 if (config->enable_op_max_used)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1580 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1581 gint output_time = the_op->output_time();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1582 gint output_used = the_op->written_time() - output_time;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1583 gint output_limit = MS2B(config->op_max_used_ms - MIN(output_used, config->op_max_used_ms));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1584
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1585 if (output_flush_time != output_time)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1586 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1587 /* slow down output, but always write _some_ data */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1588 if (output_limit < in_format.bps / 100 / 2)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1589 output_limit = in_format.bps / 100 / 2;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1590
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1591 if (op_free > output_limit)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1592 op_free = output_limit;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1593 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1594 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1595
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1596 /* --- write silence --------------------------------------------------- */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1597
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1598 if (!paused && (buffer->silence <= 0) && (buffer->silence_len >= 4))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1599 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1600 /* write as much silence as a) there is left and b) the device can take */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1601 length = buffer->silence_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1602 if (length > op_free)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1603 length = op_free;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1604
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1605 /* make sure we always operate on stereo sample boundary */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1606 length &= -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1607
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1608 /* HACK: don't stay in here too long when in realtime mode (see below) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1609 if (realtime)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1610 gettimeofday(&mark, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1611
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1612 /* write length bytes to the device */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1613 length_bak = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1614 while (length > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1615 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1616 data = zero_4k;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1617 blen = sizeof(zero_4k);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1618 if (blen > length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1619 blen = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1620
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1621 /* make sure zero_4k is cleared. The effect plugin within
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1622 * the output plugin may have modified this buffer! (0.2.8) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1623 memset(zero_4k, 0, blen);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1624
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1625 /* HACK: the original OSS plugin hangs when writing large
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1626 * blocks (greater than device buffer size) in realtime mode */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1627 if (the_op_config.max_write_enable && (blen > the_op_config.max_write_len))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1628 blen = the_op_config.max_write_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1629
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1630 /* finally, write data */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1631 the_op->write_audio(data, blen);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1632 length -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1633
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1634 /* HACK: don't stay in here too long (force yielding every 10 ms) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1635 if (realtime)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1636 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1637 gettimeofday(&tv, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1638 dt = (tv.tv_sec - mark.tv_sec) * 1000
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1639 + (tv.tv_usec - mark.tv_usec) / 1000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1640 if (dt >= 10)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1641 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1642 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1643 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1644
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1645 /* calculate how many bytes actually have been written */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1646 length = length_bak - length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1647 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1648
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1649 /* --- write data ------------------------------------------------- */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1650
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1651 else if (!paused && (buffer->preload <= 0) && (buffer->used >= 4))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1652 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1653 /* write as much data as a) is available and b) the device can take */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1654 length = buffer->used;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1655 if (length > op_free)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1656 length = op_free;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1657
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1658 /* HACK: throttle output (used with fast output plugins) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1659 if (the_op_config.throttle_enable && !realtime && opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1660 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1661 sync = buffer->sync_size - (buffer->size - buffer->used);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1662 if (sync < 0) length = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1663 else if (sync < length) length = sync;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1664 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1665
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1666 /* clip length to silence countdown (if applicable) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1667 if ((buffer->silence >= 4) && (length > buffer->silence))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1668 length = buffer->silence;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1669
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1670 /* clip length to reopen countdown (if applicable) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1671 if ((buffer->reopen >= 0) && (length > buffer->reopen))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1672 length = buffer->reopen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1673
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1674 /* clip length to pause countdown (if applicable) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1675 if ((buffer->pause >= 0) && (length > buffer->pause))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1676 length = buffer->pause;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1677
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1678 /* make sure we always operate on stereo sample boundary */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1679 length &= -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1680
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1681 /* HACK: don't stay in here too long when in realtime mode (see below) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1682 if (realtime)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1683 gettimeofday(&mark, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1684
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1685 /* write length bytes to the device */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1686 length_bak = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1687 while (length > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1688 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1689 data = buffer->data + buffer->rd_index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1690 blen = buffer->size - buffer->rd_index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1691 if (blen > length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1692 blen = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1693
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1694 /* HACK: the original OSS plugin hangs when writing large
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1695 * blocks (greater than device buffer size) in realtime mode */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1696 if (the_op_config.max_write_enable && (blen > the_op_config.max_write_len))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1697 blen = the_op_config.max_write_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1698
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1699 #ifdef HAVE_LIBFFTW
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1700 /* fft playground */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1701 fft_flow(&fft_context, (gpointer) data, blen);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1702 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1703 /* finally, write data */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1704 the_op->write_audio(data, blen);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1705
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1706 buffer->rd_index = (buffer->rd_index + blen) % buffer->size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1707 buffer->used -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1708 length -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1709
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1710 /* HACK: don't stay in here too long (force yielding every 10 ms) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1711 if (realtime)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1712 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1713 gettimeofday(&tv, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1714 dt = (tv.tv_sec - mark.tv_sec) * 1000 + (tv.tv_usec - mark.tv_usec) / 1000;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1715 if (dt >= 10)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1716 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1717 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1718 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1719
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1720 /* calculate how many bytes actually have been written */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1721 length = length_bak - length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1722 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1723 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1724 length = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1725
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1726 /* update realtime throttling */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1727 output_written += length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1728 output_streampos += length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1729
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1730 /* --- check countdowns ------------------------------------------------ */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1731
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1732 if (buffer->silence > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1733 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1734 buffer->silence -= length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1735 if (buffer->silence < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1736 DEBUG(("[crossfade] buffer_thread_f: WARNING: silence overrun: %d\n", buffer->silence));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1737 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1738 else if (buffer->silence_len > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1739 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1740 buffer->silence_len -= length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1741 if (buffer->silence_len <= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1742 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1743 if (buffer->silence_len < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1744 DEBUG(("[crossfade] buffer_thread_f: WARNING: silence_len overrun: %d\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1745 buffer->silence_len));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1746 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1747 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1748
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1749 if ((buffer->reopen >= 0) && !((buffer->silence <= 0) && (buffer->silence_len > 0)))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1750 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1751 buffer->reopen -= length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1752 if (buffer->reopen <= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1753 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1754 if (buffer->reopen < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1755 DEBUG(("[crossfade] buffer_thread_f: WARNING: reopen overrun: %d\n", buffer->reopen));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1756
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1757 DEBUG(("[crossfade] buffer_thread_f: closing/reopening device\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1758 if (buffer->reopen_sync)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1759 sync_output();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1760
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1761 if (the_op->close_audio)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1762 the_op->close_audio();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1763
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1764 if (!the_op->open_audio(out_format.fmt, out_format.rate, out_format.nch))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1765 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1766 DEBUG(("[crossfade] buffer_thread_f: reopening output plugin failed!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1767 g_free(buffer->data);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1768 output_opened = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1769 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1770 THREAD_EXIT(0);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1771 return NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1772 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1773
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1774 output_flush_time = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1775 output_written = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1776 output_streampos = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1777
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1778 /* We need to take the leading gap killer into account here:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1779 * It will fix streampos only after gapkilling has finished.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1780 * So, if gapkilling is still in progress at this point, we
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1781 * have to fix it ourselves. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1782 output_offset = buffer->used;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1783 if ((buffer->gap_len > 0) && (buffer->gap > 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1784 output_offset += buffer->gap_len - buffer->gap;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1785 output_offset = B2MS(output_offset) - xfade_written_time();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1786
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1787 /* make sure reopen is not 0 */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1788 buffer->reopen = -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1789 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1790 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1791
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1792 if (buffer->pause >= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1793 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1794 buffer->pause -= length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1795 if (buffer->pause <= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1796 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1797 if (buffer->pause < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1798 DEBUG(("[crossfade] buffer_thread_f: WARNING: pause overrun: %d\n", buffer->pause));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1799
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1800 DEBUG(("[crossfade] buffer_thread_f: pausing output\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1801
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1802 paused = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1803 sync_output();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1804
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1805 if (paused)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1806 the_op->pause(1);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1807 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1808 DEBUG(("[crossfade] buffer_thread_f: unpause during sync\n")) buffer->pause = -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1809 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1810 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1811 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1812
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1813 /* ----------------------------------------------------------------------- */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1814
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1815 /* cleanup: close output */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1816 if (output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1817 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1818 DEBUG(("[crossfade] buffer_thread_f: closing output...\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1819
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1820 if (the_op->close_audio)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1821 the_op->close_audio();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1822
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1823 DEBUG(("[crossfade] buffer_thread_f: closing output... done\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1824
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1825 g_free(buffer->data);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1826 output_opened = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1827 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1828 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1829 DEBUG(("[crossfade] buffer_thread_f: output already closed!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1830
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1831 /* ----------------------------------------------------------------------- */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1832
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1833 /* unlock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1834 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1835
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1836 /* done */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1837 DEBUG(("[crossfade] buffer_thread_f: thread finished\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1838 THREAD_EXIT(0);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1839 return NULL;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1840 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1841
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1842 void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1843 xfade_close_audio()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1844 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1845 DEBUG(("[crossfade] close:\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1846 DEBUG(("[crossfade] close: playing=%d filename=%s\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1847 xfplayer_input_playing(), xfplaylist_get_filename(xfplaylist_get_position())));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1848
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1849 /* lock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1850 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1851
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1852 /* sanity... the vorbis plugin likes to call close_audio() twice */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1853 if (!opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1854 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1855 DEBUG(("[crossfade] close: WARNING: not opened!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1856 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1857 return;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1858 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1859
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1860 #if defined(COMPILE_FOR_AUDACIOUS) && AUDACIOUS_ABI_VERSION >= 2
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1861 /* HACK: to distinguish between STOP and EOP, check Audacious'
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1862 input_playing() variable. It seems to be TRUE at this point
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1863 only when the end of the playlist is reached.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1864
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1865 Normally, 'playing' is constantly being updated in the
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1866 xfade_buffer_playing() callback, but Audacious does not seem
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1867 to use it. Therefore, we can set 'playing' to FALSE here,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1868 which later 'buffer_thread' will interpret as EOP (see above).
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1869 */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1870 if (xfplayer_input_playing())
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1871 playing = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1872 #else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1873 /* HACK: use patched XMMS 'input_stopped_for_restart' */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1874 if (input_stopped_for_restart && *input_stopped_for_restart)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1875 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1876 DEBUG(("[crossfade] close: playback will restart soon\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1877 output_restart = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1878 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1879 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1880 output_restart = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1881 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1882
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1883 if (playing)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1884 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1885 /* immediatelly close output when paused */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1886 if (paused)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1887 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1888 buffer->pause = -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1889 paused = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1890 if (config->output_keep_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1891 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1892 buffer->used = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1893 the_op->flush(0);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1894 the_op->pause(0);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1895 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1896 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1897 stopped = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1898 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1899
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1900 /* HACK: If playlist_get_info_going is not true here,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1901 * XMMS is about to exit. In this case, we stop
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1902 * the buffer thread before returning from this
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1903 * function. Otherwise, SEGFAULT may occur when
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1904 * XMMS tries to cleanup an output plugin which
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1905 * we are still using.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1906 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1907 * NOTE: Not quite. There still are some problems when
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1908 * XMMS is exitting while a song is playing. So
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1909 * this HACK has been enabled again.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1910 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1911 * NOTE: Another thing: If output_keep_opened is enabled,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1912 * close_audio() is never called, so that the patch
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1913 * can not work.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1914 */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1915 #if 1
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1916 if ((xmms_is_quitting && *xmms_is_quitting)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1917 || (xmms_playlist_get_info_going && !*xmms_playlist_get_info_going))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1918 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1919 DEBUG(("[crossfade] close: stop (about to quit)\n"))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1920
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1921 /* wait for buffer thread to clean up and terminate */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1922 stopped = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1923 #if 1
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1924 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1925 if (THREAD_JOIN(buffer_thread))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1926 PERROR("[crossfade] close: phtread_join()");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1927 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1928 #else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1929 while (output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1930 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1931 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1932 xfade_usleep(10000);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1933 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1934 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1935 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1936 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1937 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1938 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1939 DEBUG(("[crossfade] close: stop\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1940
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1941 fade_config = &config->fc[FADE_CONFIG_MANUAL];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1942 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1943 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1944 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1945 /* gint x = *((gint *)0); */ /* force SEGFAULT for debugging */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1946 DEBUG(("[crossfade] close: songchange/eop\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1947
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1948 /* kill trailing gap (does not use buffer->gap_*) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1949 if (output_opened && xfade_cfg_gap_trail_enable(config))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1950 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1951 gint gap_len = MS2B(xfade_cfg_gap_trail_len(config)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1952 gint gap_level = xfade_cfg_gap_trail_level(config);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1953 gint length = MIN(gap_len, buffer->used);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1954
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1955 /* DEBUG(("[crossfade] close: len=%d level=%d length=%d\n", gap_len, gap_level, length)); */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1956
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1957 buffer->gap_killed = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1958 while (length > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1959 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1960 gint wr_xedni = (buffer->rd_index + buffer->used - 1) % buffer->size + 1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1961 gint blen = MIN(length, wr_xedni);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1962 gint16 *p = buffer->data + wr_xedni, left, right;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1963 gint index = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1964
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1965 while (index < blen)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1966 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1967 right = *--p;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1968 left = *--p;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1969 if (ABS(left) >= gap_level) break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1970 if (ABS(right) >= gap_level) break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1971 index += 4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1972 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1973
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1974 buffer->used -= index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1975 buffer->gap_killed += index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1976
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1977 if (index < blen)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1978 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1979 length -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1980 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1981
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1982 DEBUG(("[crossfade] close: trailing gap size: %d/%d ms\n", B2MS(buffer->gap_killed), B2MS(gap_len)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1983 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1984
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1985 /* skip to previous zero crossing */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1986 if (output_opened && config->gap_crossing)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1987 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1988 int crossing;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1989
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1990 buffer->gap_skipped = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1991 for (crossing = 0; crossing < 4; crossing++)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1992 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1993 while (buffer->used > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1994 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1995 gint wr_xedni = (buffer->rd_index + buffer->used - 1) % buffer->size + 1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1996 gint blen = MIN(buffer->used, wr_xedni);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1997 gint16 *p = buffer->data + wr_xedni, left;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1998 gint index = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1999
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2000 while (index < blen)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2001 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2002 left = (--p, *--p);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2003 if ((crossing & 1) ^ (left > 0))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2004 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2005 index += 4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2006 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2007
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2008 buffer->used -= index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2009 buffer->gap_skipped += index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2010
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2011 if (index < blen)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2012 break;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2013 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2014 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2015 DEBUG(("[crossfade] close: skipped %d bytes to previous zero crossing\n", buffer->gap_skipped));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2016
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2017 /* update gap_killed (for undoing gap_killer in case of EOP) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2018 buffer->gap_killed += buffer->gap_skipped;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2019 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2020
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2021 fade_config = &config->fc[FADE_CONFIG_XFADE];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2022 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2023
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2024 /* XMMS has left the building */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2025 opened = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2026
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2027 /* update last_close */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2028 gettimeofday(&last_close, NULL);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2029 input_playing = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2030
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2031 /* unlock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2032 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2033 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2034
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2035 void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2036 xfade_flush(gint time)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2037 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2038 gint pos;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2039 gchar *file;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2040
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2041 DEBUG(("[crossfade] flush: time=%d\n", time));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2042
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2043 /* get filename */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2044 pos = xfplaylist_get_position();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2045 file = xfplaylist_get_filename(pos);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2046
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2047 if (!file)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2048 file = g_strdup(xfplaylist_get_songtitle(pos));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2049
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2050 #if defined(COMPILE_FOR_AUDACIOUS)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2051 /* HACK: special handling for audacious, which just calls flush(0) on a songchange */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2052 if (file && last_filename && strcmp(file, last_filename) != 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2053 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2054 DEBUG(("[crossfade] flush: filename changed, forcing close/reopen...\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2055 xfade_close_audio();
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2056 /* 0.3.14: xfade_close_audio sets fade_config to FADE_CONFIG_MANUAL,
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2057 * but this is an automatic songchange */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2058 fade_config = &config->fc[FADE_CONFIG_XFADE];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2059 xfade_open_audio(in_format.fmt, in_format.rate, in_format.nch);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2060 DEBUG(("[crossfade] flush: filename changed, forcing close/reopen... done\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2061 return;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2062 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2063 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2064
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2065 /* lock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2066 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2067
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2068 /* update streampos with new stream position (input format size) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2069 streampos = ((gint64) time * in_format.bps / 1000) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2070
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2071 /* flush output device / apply seek crossfade */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2072 if (config->fc[FADE_CONFIG_SEEK].type == FADE_TYPE_FLUSH)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2073 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2074 /* flush output plugin */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2075 the_op->flush(time);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2076 output_flush_time = time;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2077 output_streampos = MS2B(time);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2078
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2079 /* flush buffer, disable leading gap killing */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2080 buffer_reset(buffer, config);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2081 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2082 else if (paused)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2083 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2084 fade_config_t fc;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2085
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2086 /* clear buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2087 buffer->used = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2088
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2089 /* apply only the fade_in part of FADE_CONFIG_PAUSE */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2090 memcpy(&fc, &config->fc[FADE_CONFIG_PAUSE], sizeof(fc));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2091 fc.out_len_ms = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2092 fc.ofs_custom_ms = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2093 xfade_apply_fade_config(&fc);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2094 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2095 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2096 xfade_apply_fade_config(&config->fc[FADE_CONFIG_SEEK]);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2097
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2098 /* restart realtime throttling (should find another name for that var) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2099 output_written = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2100
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2101 /* make sure that the gapkiller is disabled */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2102 buffer->gap = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2103
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2104 /* update output offset */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2105 output_offset = the_op->written_time() - time + B2MS(buffer->used) + B2MS(buffer->silence_len);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2106
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2107 /* unlock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2108 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2109
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2110 #ifdef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2111 DEBUG(("[crossfade] flush: time=%d: done.\n", time));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2112 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2113 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2114
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2115 void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2116 xfade_pause(short p)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2117 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2118 /* lock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2119 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2120
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2121 if (p)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2122 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2123 fade_config_t *fc = &config->fc[FADE_CONFIG_PAUSE];
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2124 if (fc->type == FADE_TYPE_PAUSE_ADV)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2125 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2126 int fade, length, n;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2127 int index = buffer->rd_index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2128 int out_len = MS2B(xfade_cfg_fadeout_len(fc)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2129 int in_len = MS2B(xfade_cfg_fadein_len(fc)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2130 int silence_len = MS2B(xfade_cfg_offset(fc)) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2131
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2132 /* limit fadeout/fadein len to available data in buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2133 if ((out_len + in_len) > buffer->used)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2134 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2135 out_len = (buffer->used / 2) & -4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2136 in_len = out_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2137 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2138
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2139 DEBUG(("[crossfade] pause: paused=1 out=%d in=%d silence=%d\n",
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2140 B2MS(out_len), B2MS(in_len), B2MS(silence_len)));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2141
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2142 /* fade out (modifies buffer directly) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2143 fade = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2144 length = out_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2145 while (length > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2146 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2147 gint16 *p = buffer->data + index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2148 gint blen = buffer->size - index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2149 if (blen > length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2150 blen = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2151
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2152 for (n = blen / 4; n > 0; n--)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2153 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2154 gfloat factor = 1.0f - ((gfloat) fade / out_len);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2155 *p = (gfloat)*p * factor; p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2156 *p = (gfloat)*p * factor; p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2157 fade += 4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2158 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2159
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2160 index = (index + blen) % buffer->size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2161 length -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2162 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2163
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2164 /* fade in (modifies buffer directly) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2165 fade = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2166 length = in_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2167 while (length > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2168 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2169 gint16 *p = buffer->data + index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2170 gint blen = buffer->size - index;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2171 if (blen > length)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2172 blen = length;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2173
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2174 for (n = blen / 4; n > 0; n--)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2175 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2176 gfloat factor = (gfloat) fade / in_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2177 *p = (gfloat)*p * factor; p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2178 *p = (gfloat)*p * factor; p++;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2179 fade += 4;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2180 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2181
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2182 index = (index + blen) % buffer->size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2183 length -= blen;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2184 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2185
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2186 /* start silence and pause countdowns */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2187 buffer->silence = out_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2188 buffer->silence_len = silence_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2189 buffer->pause = out_len + silence_len;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2190 paused = FALSE; /* (!) will be set to TRUE in buffer_thread_f */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2191 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2192 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2193 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2194 the_op->pause(1);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2195 paused = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2196 DEBUG(("[crossfade] pause: paused=1\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2197 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2198 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2199 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2200 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2201 the_op->pause(0);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2202 buffer->pause = -1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2203 paused = FALSE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2204 DEBUG(("[crossfade] pause: paused=0\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2205 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2206
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2207 /* unlock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2208 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2209 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2210
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2211 gint
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2212 xfade_buffer_free()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2213 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2214 gint size, free;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2215
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2216 #ifdef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2217 DEBUG(("[crossfade] buffer_free:\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2218 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2219
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2220 /* sanity check */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2221 if (!output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2222 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2223 DEBUG(("[crossfade] buffer_free: WARNING: output closed!\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2224 return buffer->sync_size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2225 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2226
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2227 /* lock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2228 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2229
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2230 size = buffer->size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2231
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2232 /* When running in realtime mode, we need to take special care here:
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2233 * While XMMS is writing data to the output plugin, it will not yield
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2234 * ANY processing time to the buffer thread. It will only stop when
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2235 * xfade_buffer_free() no longer reports free buffer space. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2236 if (realtime)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2237 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2238 gint64 wanted = output_written + buffer->preload_size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2239
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2240 /* Fix for XMMS misbehaviour (possibly a bug): If the free space as
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2241 * returned by xfade_buffer_free() is below a certain minimum block size
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2242 * (tests showed 2304 bytes), XMMS will not send more data until there
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2243 * is enough room for one of those blocks.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2244 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2245 * This breaks preloading in realtime mode. To make sure that the pre-
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2246 * load buffer gets filled we request additional sync_size bytes. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2247 wanted += buffer->sync_size;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2248
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2249 if (wanted <= size)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2250 size = wanted;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2251 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2252
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2253 free = size - buffer->used;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2254 if (free < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2255 free = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2256
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2257 /* unlock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2258 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2259
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2260 /* Convert to input format size. For input rates > output rate this will
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2261 * return less free space than actually is available, but we don't care. */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2262 free /= (out_format.rate / (in_format.rate + 1)) + 1;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2263 if (in_format.is_8bit)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2264 free /= 2;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2265 if (in_format.nch == 1)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2266 free /= 2;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2267
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2268 #ifdef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2269 DEBUG(("[crossfade] buffer_free: %d\n", free));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2270 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2271 return free;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2272 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2273
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2274 gint
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2275 xfade_buffer_playing()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2276 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2277 /* always return FALSE here (if not in pause) so XMMS immediatelly
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2278 * starts playback of the next song */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2279
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2280 /*
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2281 * NOTE: this causes trouble when playing HTTP audio streams.
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2282 *
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2283 * mpg123.lib will start prebuffering (and thus stalling output) when both
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2284 * 1) it's internal buffer is emptied (does happen all the time)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2285 * 2) the output plugin's buffer_playing() (this function) returns FALSE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2286 */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2287
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2288 if (paused)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2289 playing = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2290 else
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2291 playing =
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2292 (is_http && (buffer->used > 0) && the_op->buffer_playing())
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2293 || (buffer->reopen >= 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2294 || (buffer->silence > 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2295 || (buffer->silence_len > 0);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2296
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2297 #ifdef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2298 DEBUG(("[crossfade] buffer_playing: %d\n", playing));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2299 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2300 return playing;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2301 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2302
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2303 gint
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2304 xfade_written_time()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2305 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2306 if (!output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2307 return 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2308 return (gint) (streampos * 1000 / in_format.bps);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2309 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2310
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2311 gint
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2312 xfade_output_time()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2313 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2314 gint time;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2315
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2316 #ifdef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2317 DEBUG(("[crossfade] output_time:\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2318 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2319
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2320 /* sanity check (note: this one _does_ happen all the time) */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2321 if (!output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2322 return 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2323
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2324 /* lock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2325 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2326
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2327 time = the_op->output_time() - output_offset;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2328 if (time < 0)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2329 time = 0;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2330
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2331 /* unlock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2332 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2333
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2334 #ifdef DEBUG_HARDCORE
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2335 DEBUG(("[crossfade] output_time: time=%d\n", time));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2336 #endif
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2337 return time;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2338 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2339
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2340 void
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2341 xfade_cleanup()
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2342 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2343 DEBUG(("[crossfade] cleanup:\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2344
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2345 /* lock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2346 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2347
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2348 /* check if buffer thread is still running */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2349 if (output_opened)
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2350 {
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2351 DEBUG(("[crossfade] cleanup: closing output\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2352
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2353 stopped = TRUE;
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2354
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2355 /* wait for buffer thread to clean up and terminate */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2356 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2357 if (THREAD_JOIN(buffer_thread))
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2358 PERROR("[crossfade] close: thread_join()");
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2359 MUTEX_LOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2360 }
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2361
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2362 /* unlock buffer */
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2363 MUTEX_UNLOCK(&buffer_mutex);
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2364
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2365 DEBUG(("[crossfade] cleanup: done\n"));
2e241e90494a Import work in progress xmms-crossfade rewrite.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2366 }