annotate Plugins/Output/jack/jack.c @ 997:e64eb333b63f trunk

[svn] Properly nullify the tag pointer or we could be passing a stale one.
author chainsaw
date Mon, 01 May 2006 08:38:43 -0700
parents 495a1a6f1d99
children 57b57595b404
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
325
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1 /* xmms - jack output plugin
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2 * Copyright 2002 Chris Morgan<cmorgan@alum.wpi.edu>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
3 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
4 * audacious port (2005) by Giacomo Lozito from develia.org
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
5 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
6 * This code maps xmms calls into the jack translation library
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
7 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
8
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
9 #include "libaudacious/configfile.h"
903
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
10 #include "libaudacious/util.h"
325
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
11 #include <dlfcn.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
12 #include <gtk/gtk.h>
903
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
13 #include <glib/gi18n.h>
325
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
14 #include <stdio.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
15 #include "config.h"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
16 #include "bio2jack.h" /* includes for the bio2jack library */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
17 #include "jack.h"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
18 #include "xconvert.h" /* xmms rate conversion header file */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
19 #include <string.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
20
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
21
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
22
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
23 /* set to 1 for verbose output */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
24 #define VERBOSE_OUTPUT 0
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
25
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
26 jackconfig jack_cfg;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
27
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
28 #define OUTFILE stderr
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
29
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
30 #define TRACE(...) \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
31 if(jack_cfg.isTraceEnabled) { \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
32 fprintf(OUTFILE, "%s:", __FUNCTION__), \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
33 fprintf(OUTFILE, __VA_ARGS__), \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
34 fflush(OUTFILE); \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
35 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
36
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
37 #define ERR(...) \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
38 if(jack_cfg.isTraceEnabled) { \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
39 fprintf(OUTFILE, "ERR: %s:", __FUNCTION__), \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
40 fprintf(OUTFILE, __VA_ARGS__), \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
41 fflush(OUTFILE); \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
42 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
43
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
44
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
45 static int driver = 0; /* handle to the jack output device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
46
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
47 typedef struct format_info {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
48 AFormat format;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
49 long frequency;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
50 int channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
51 long bps;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
52 } format_info_t;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
53
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
54 static format_info_t input;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
55 static format_info_t effect;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
56 static format_info_t output;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
57
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
58 static convert_freq_func_t freq_convert; /* rate convert function */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
59 static struct xmms_convert_buffers *convertb; /* convert buffer */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
60
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
61 #define MAKE_FUNCPTR(f) static typeof(f) * fp_##f = NULL;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
62 MAKE_FUNCPTR(xmms_convert_buffers_new);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
63 MAKE_FUNCPTR(xmms_convert_buffers_destroy);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
64 MAKE_FUNCPTR(xmms_convert_get_frequency_func);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
65 void *xmmslibhandle; /* handle to the dlopen'ed libxmms.so */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
66
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
67 static int isXmmsFrequencyAvailable = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
68
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
69 static gboolean output_opened; /* true if we have a connection to jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
70
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
71 static GtkWidget *dialog, *button, *label;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
72
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
73
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
74 /* Giacomo's note: removed the destructor from the original xmms-jack, cause
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
75 destructors + thread join + NPTL currently leads to problems; solved this
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
76 by adding a cleanup function callback for output plugins in Audacious, this
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
77 is used to close the JACK connection and to perform a correct shutdown */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
78 void jack_cleanup(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
79 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
80 int errval;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
81 TRACE("cleanup\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
82
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
83 if((errval = JACK_Close(driver)))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
84 ERR("error closing device, errval of %d\n", errval);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
85
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
86 /* only clean this up if we have the function to call */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
87 if(isXmmsFrequencyAvailable)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
88 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
89 fp_xmms_convert_buffers_destroy(convertb); /* clean up the rate conversion buffers */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
90 dlclose(xmmslibhandle);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
91 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
92
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
93 return;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
94 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
95
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
96
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
97 void jack_sample_rate_error(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
98 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
99 dialog = gtk_dialog_new();
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
100 gtk_window_set_title(GTK_WINDOW(dialog), ("Sample rate mismatch"));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
101 gtk_container_border_width(GTK_CONTAINER(dialog), 5);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
102 label = gtk_label_new((
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
103 "Xmms is asking for a sample rate that differs from\n "
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
104 "that of the jack server. Xmms 1.2.8 or later\n"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
105 "contains resampling routines that xmms-jack will\n"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
106 "dynamically load and use to perform resampling.\n"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
107 "Or you can restart the jack server\n"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
108 "with a sample rate that matches the one that\n"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
109 "xmms desires. -r is the option for the jack\n"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
110 "alsa driver so -r 44100 or -r 48000 should do\n\n"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
111 "Chris Morgan <cmorgan@alum.wpi.edu>\n"));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
112
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
113 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
114 gtk_widget_show(label);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
115
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
116 button = gtk_button_new_with_label((" Close "));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
117 gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(dialog));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
118 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, FALSE, FALSE, 0);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
119 gtk_widget_show(button);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
120
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
121 gtk_widget_show(dialog);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
122 gtk_widget_grab_focus(button);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
123 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
124
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
125
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
126 /* Return the number of milliseconds of audio data that has been */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
127 /* written out to the device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
128 gint jack_get_written_time(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
129 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
130 long return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
131 return_val = JACK_GetPosition(driver, MILLISECONDS, WRITTEN);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
132
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
133 TRACE("returning %ld milliseconds\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
134 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
135 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
136
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
137
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
138 /* Return the current number of milliseconds of audio data that has */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
139 /* been played out of the audio device, not including the buffer */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
140 gint jack_get_output_time(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
141 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
142 gint return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
143
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
144 /* don't try to get any values if the device is still closed */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
145 if(JACK_GetState(driver) == CLOSED)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
146 return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
147 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
148 return_val = JACK_GetPosition(driver, MILLISECONDS, PLAYED); /* get played position in terms of milliseconds */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
149
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
150 TRACE("returning %d milliseconds\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
151 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
152 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
153
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
154
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
155 /* returns TRUE if we are currently playing */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
156 /* NOTE: this was confusing at first BUT, if the device is open and there */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
157 /* is no more audio to be played, then the device is NOT PLAYING */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
158 gint jack_playing(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
159 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
160 gint return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
161
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
162 /* If we are playing see if we ACTUALLY have something to play */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
163 if(JACK_GetState(driver) == PLAYING)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
164 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
165 /* If we have zero bytes stored, we are done playing */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
166 if(JACK_GetBytesStored(driver) == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
167 return_val = FALSE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
168 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
169 return_val = TRUE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
170 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
171 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
172 return_val = FALSE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
173
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
174 TRACE("returning %d\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
175 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
176 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
177
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
178
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
179 void jack_set_port_connection_mode()
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
180 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
181 /* setup the port connection mode that determines how bio2jack will connect ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
182 enum JACK_PORT_CONNECTION_MODE mode;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
183
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
184 if(strcmp(jack_cfg.port_connection_mode, "CONNECT_ALL") == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
185 mode = CONNECT_ALL;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
186 else if(strcmp(jack_cfg.port_connection_mode, "CONNECT_OUTPUT") == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
187 mode = CONNECT_OUTPUT;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
188 else if(strcmp(jack_cfg.port_connection_mode, "CONNECT_NONE") == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
189 mode = CONNECT_NONE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
190 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
191 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
192 TRACE("Defaulting to CONNECT_ALL");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
193 mode = CONNECT_ALL;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
194 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
195 JACK_SetPortConnectionMode(mode);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
196 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
197
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
198 /* Initialize necessary things */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
199 void jack_init(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
200 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
201 /* read the isTraceEnabled setting from the config file */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
202 ConfigFile *cfgfile;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
203 gchar *filename;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
204
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
205 filename = g_strconcat(g_get_home_dir(), "/.audacious/config", NULL);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
206 cfgfile = xmms_cfg_open_file(filename);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
207 if (!cfgfile)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
208 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
209 jack_cfg.isTraceEnabled = FALSE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
210 jack_cfg.port_connection_mode = "CONNECT_ALL"; /* default to connect all */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
211 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
212 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
213 xmms_cfg_read_boolean(cfgfile, "jack", "isTraceEnabled", &jack_cfg.isTraceEnabled);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
214 if(!xmms_cfg_read_string(cfgfile, "jack", "port_connection_mode", &jack_cfg.port_connection_mode))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
215 jack_cfg.port_connection_mode = "CONNECT_ALL";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
216 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
217
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
218 xmms_cfg_free(cfgfile);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
219 g_free(filename);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
220
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
221 TRACE("initializing\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
222 JACK_Init(); /* initialize the driver */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
223
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
224 /* set the bio2jack name so users will see xmms-jack in their */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
225 /* jack client list */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
226 JACK_SetClientName("audacious-jack");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
227
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
228 /* set the port connection mode */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
229 jack_set_port_connection_mode();
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
230
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
231 xmmslibhandle = dlopen("libaudacious.so", RTLD_NOW);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
232 if(xmmslibhandle)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
233 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
234 fp_xmms_convert_buffers_new = dlsym(xmmslibhandle, "xmms_convert_buffers_new");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
235 fp_xmms_convert_buffers_destroy = dlsym(xmmslibhandle, "xmms_convert_buffers_destroy");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
236 fp_xmms_convert_get_frequency_func = dlsym(xmmslibhandle, "xmms_convert_get_frequency_func");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
237
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
238 if(!fp_xmms_convert_buffers_new)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
239 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
240 TRACE("fp_xmms_convert_buffers_new couldn't be dlsym'ed\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
241 TRACE("dlerror: %s\n", dlerror());
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
242 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
243
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
244 if(!fp_xmms_convert_buffers_destroy)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
245 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
246 TRACE("fp_xmms_convert_buffers_destroy couldn't be dlsym'ed\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
247 TRACE("dlerror: %s\n", dlerror());
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
248 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
249
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
250 if(!fp_xmms_convert_get_frequency_func)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
251 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
252 TRACE("fp_xmms_get_frequency_func couldn't be dlsym'ed\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
253 TRACE("dlerror: %s\n", dlerror());
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
254 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
255
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
256 if(!fp_xmms_convert_buffers_new || !fp_xmms_convert_buffers_destroy ||
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
257 !fp_xmms_convert_get_frequency_func)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
258 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
259 dlclose(xmmslibhandle); /* close the library, no need to keep it open */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
260 TRACE("One or more frequency convertion functions are missing, upgrade to xmms >=1.2.8\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
261 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
262 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
263 TRACE("Found frequency convertion functions, setting isXmmsFrequencyAvailable to 1\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
264 isXmmsFrequencyAvailable = 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
265 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
266 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
267 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
268 TRACE("unable to dlopen '%s'\n", "libaudacious.so");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
269 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
270
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
271 /* only initialize this stuff if we have the functions available */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
272 if(isXmmsFrequencyAvailable)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
273 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
274 convertb = fp_xmms_convert_buffers_new ();
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
275 freq_convert = fp_xmms_convert_get_frequency_func(FMT_S16_LE, 2);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
276 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
277
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
278 output_opened = FALSE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
279 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
280
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
281
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
282 /* Return the amount of data that can be written to the device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
283 gint jack_free(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
284 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
285 unsigned long return_val = JACK_GetBytesFreeSpace(driver);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
286 unsigned long tmp;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
287
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
288 /* adjust for frequency differences, otherwise xmms could send us */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
289 /* as much data as we have free, then we go to convert this to */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
290 /* the output frequency and won't have enough space, so adjust */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
291 /* by the ratio of the two */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
292 if(effect.frequency != output.frequency)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
293 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
294 tmp = return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
295 return_val = (return_val * effect.frequency) / output.frequency;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
296 TRACE("adjusting from %ld to %ld free bytes to compensate for frequency differences\n", tmp, return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
297 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
298
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
299 if(return_val > G_MAXINT)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
300 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
301 TRACE("Warning: return_val > G_MAXINT\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
302 return_val = G_MAXINT;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
303 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
304
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
305 TRACE("free space of %ld bytes\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
306
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
307 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
308 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
309
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
310
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
311 /* Close the device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
312 void jack_close(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
313 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
314 TRACE("\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
315
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
316 JACK_Reset(driver); /* flush buffers, reset position and set state to STOPPED */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
317 TRACE("resetting driver, not closing now, destructor will close for us\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
318 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
319
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
320
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
321 /* Open the device up */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
322 gint jack_open(AFormat fmt, gint sample_rate, gint num_channels)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
323 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
324 int bits_per_sample;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
325 int retval;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
326 unsigned long rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
327
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
328 TRACE("fmt == %d, sample_rate == %d, num_channels == %d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
329 fmt, sample_rate, num_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
330
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
331 if((fmt == FMT_U8) || (fmt == FMT_S8))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
332 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
333 bits_per_sample = 8;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
334 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
335 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
336 bits_per_sample = 16;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
337 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
338
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
339 /* record some useful information */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
340 input.format = fmt;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
341 input.frequency = sample_rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
342 input.bps = bits_per_sample * sample_rate * num_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
343 input.channels = num_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
344
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
345 /* setup the effect as matching the input format */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
346 effect.format = input.format;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
347 effect.frequency = input.frequency;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
348 effect.channels = input.channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
349 effect.bps = input.bps;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
350
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
351 /* if we are already opened then don't open again */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
352 if(output_opened)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
353 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
354 /* if something has changed we should close and re-open the connect to jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
355 if((output.channels != input.channels) ||
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
356 (output.frequency != input.frequency) ||
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
357 (output.format != input.format))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
358 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
359 TRACE("output.channels is %d, jack_open called with %d channels\n", output.channels, input.channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
360 TRACE("output.frequency is %ld, jack_open called with %ld\n", output.frequency, input.frequency);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
361 TRACE("output.format is %d, jack_open called with %d\n", output.format, input.format);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
362 jack_close();
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
363 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
364 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
365 TRACE("output_opened is TRUE and no options changed, not reopening\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
366 return 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
367 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
368 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
369
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
370 /* try to open the jack device with the requested rate at first */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
371 output.frequency = input.frequency;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
372 output.bps = input.bps;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
373 output.channels = input.channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
374 output.format = input.format;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
375
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
376 rate = output.frequency;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
377 retval = JACK_Open(&driver, bits_per_sample, &rate, output.channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
378 output.frequency = rate; /* avoid compile warning as output.frequency differs in type
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
379 from what JACK_Open() wants for the type of the rate parameter */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
380 if((retval == ERR_RATE_MISMATCH) && isXmmsFrequencyAvailable)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
381 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
382 TRACE("xmms(input) wants rate of '%ld', jacks rate(output) is '%ld', opening at jack rate\n", input.frequency, output.frequency);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
383
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
384 /* open the jack device with true jack's rate, return 0 upon failure */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
385 retval = JACK_Open(&driver, bits_per_sample, &rate, output.channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
386 output.frequency = rate; /* avoid compile warning as output.frequency differs in type
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
387 from what JACK_Open() wants for the type of the rate parameter */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
388 if(retval)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
389 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
390 TRACE("failed to open jack with JACK_Open(), error %d\n", retval);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
391 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
392 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
393 TRACE("success!!\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
394 } else if((retval == ERR_RATE_MISMATCH) && !isXmmsFrequencyAvailable)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
395 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
396 TRACE("JACK_Open(), sample rate mismatch with no resampling routines available\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
397
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
398 jack_sample_rate_error(); /* notify the user that we can't resample */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
399
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
400 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
401 } else if(retval != ERR_SUCCESS)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
402 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
403 TRACE("failed to open jack with JACK_Open(), error %d\n", retval);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
404 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
405 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
406
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
407 output_opened = TRUE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
408
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
409 return 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
410 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
411
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
412
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
413 /* write some audio out to the device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
414 void jack_write(gpointer ptr, gint length)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
415 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
416 long written;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
417 EffectPlugin *ep;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
418 AFormat new_format;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
419 int new_frequency, new_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
420 long positionMS;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
421
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
422 TRACE("starting length of %d\n", length);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
423
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
424 /* copy the current values into temporary values */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
425 new_format = input.format;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
426 new_frequency = input.frequency;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
427 new_channels = input.channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
428
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
429 /* query xmms for the current plugin */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
430 ep = get_current_effect_plugin();
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
431 if(effects_enabled() && ep && ep->query_format)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
432 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
433 ep->query_format(&new_format, &new_frequency, &new_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
434 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
435
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
436 /* if the format has changed take this into account by modifying */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
437 /* the time offset and reopening the device with the new format settings */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
438 if (new_format != effect.format ||
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
439 new_frequency != effect.frequency ||
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
440 new_channels != effect.channels)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
441 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
442 TRACE("format changed, storing new values and opening/closing jack\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
443 TRACE("effect.format == %d, new_format == %d, effect.frequency == %ld, new_frequency == %d, effect.channels == %d, new_channels = %d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
444 effect.format, new_format, effect.frequency, new_frequency, effect.channels, new_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
445
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
446 positionMS = JACK_GetPosition(driver, MILLISECONDS, PLAYED);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
447
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
448 jack_close();
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
449 jack_open(new_format, new_frequency, new_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
450
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
451 /* restore the position after the open and close */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
452 JACK_SetState(driver, PAUSED);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
453 JACK_SetPosition(driver, MILLISECONDS, positionMS);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
454 JACK_SetState(driver, PLAYING);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
455 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
456
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
457 /* if effects are enabled and we have a plugin, run the current */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
458 /* samples through the plugin */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
459 if (effects_enabled() && ep && ep->mod_samples)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
460 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
461 length = ep->mod_samples(&ptr, length,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
462 input.format,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
463 input.frequency,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
464 input.channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
465 TRACE("effects_enabled(), length is now %d\n", length);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
466 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
467
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
468 TRACE("effect.frequency == %ld, input.frequency == %ld, output.frequency == %ld\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
469 effect.frequency, input.frequency, output.frequency);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
470
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
471 /* if we need rate conversion, perform it here */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
472 if((effect.frequency != output.frequency) && isXmmsFrequencyAvailable)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
473 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
474 TRACE("performing rate conversion from '%ld'(effect) to '%ld'(output)\n", effect.frequency, output.frequency);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
475 length = freq_convert (convertb, &ptr, length, effect.frequency, output.frequency);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
476 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
477
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
478 TRACE("length = %d\n", length);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
479 /* loop until we have written all the data out to the jack device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
480 /* this is due to xmms' audio driver api */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
481 char *buf = (char*)ptr;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
482 while(length > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
483 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
484 TRACE("writing %d bytes\n", length);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
485 written = JACK_Write(driver, (unsigned char*)buf, length);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
486 length-=written;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
487 buf+=written;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
488 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
489 TRACE("finished\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
490 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
491
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
492
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
493 /* Flush any output currently buffered */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
494 /* and set the number of bytes written based on ms_offset_time, */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
495 /* the number of milliseconds of offset passed in */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
496 /* This is done so the driver itself keeps track of */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
497 /* current playing position of the mp3 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
498 void jack_flush(gint ms_offset_time)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
499 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
500 TRACE("setting values for ms_offset_time of %d\n", ms_offset_time);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
501
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
502 JACK_Reset(driver); /* flush buffers and set state to STOPPED */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
503
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
504 /* update the internal driver values to correspond to the input time given */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
505 JACK_SetPosition(driver, MILLISECONDS, ms_offset_time);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
506
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
507 JACK_SetState(driver, PLAYING);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
508 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
509
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
510
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
511 /* Pause the jack device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
512 void jack_pause(short p)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
513 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
514 TRACE("p == %d\n", p);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
515
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
516 /* pause the device if p is non-zero, unpause the device if p is zero and */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
517 /* we are currently paused */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
518 if(p)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
519 JACK_SetState(driver, PAUSED);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
520 else if(JACK_GetState(driver) == PAUSED)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
521 JACK_SetState(driver, PLAYING);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
522 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
523
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
524
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
525 /* Set the volume */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
526 void jack_set_volume(int l, int r)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
527 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
528 if(output.channels == 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
529 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
530 TRACE("l(%d)\n", l);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
531 } else if(output.channels > 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
532 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
533 TRACE("l(%d), r(%d)\n", l, r);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
534 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
535
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
536 if(output.channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
537 JACK_SetVolumeForChannel(driver, 0, l);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
538 if(output.channels > 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
539 JACK_SetVolumeForChannel(driver, 1, r);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
540 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
541
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
542
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
543 /* Get the current volume setting */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
544 void jack_get_volume(int *l, int *r)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
545 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
546 unsigned int _l, _r;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
547
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
548 if(output.channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
549 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
550 JACK_GetVolumeForChannel(driver, 0, &_l);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
551 (*l) = _l;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
552 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
553 if(output.channels > 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
554 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
555 JACK_GetVolumeForChannel(driver, 1, &_r);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
556 (*r) = _r;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
557 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
558
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
559 #if VERBOSE_OUTPUT
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
560 if(output.channels == 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
561 TRACE("l(%d)\n", *l);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
562 else if(output.channels > 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
563 TRACE("l(%d), r(%d)\n", *l, *r);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
564 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
565 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
566
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
567
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
568 void jack_about(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
569 {
903
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
570 static GtkWidget *aboutbox;
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
571
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
572 if (!aboutbox)
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
573 {
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
574 aboutbox = xmms_show_message(
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
575 _("About JACK Output Plugin 0.15"),
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
576 _("XMMS jack Driver 0.15\n\n"
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
577 "xmms-jack.sf.net\nChris Morgan<cmorgan@alum.wpi.edu>\n\n"
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
578 "Audacious port by\nGiacomo Lozito from develia.org"),
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
579 _("Ok"), FALSE, NULL, NULL);
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
580 g_signal_connect(GTK_OBJECT(aboutbox), "destroy",
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
581 (GCallback)gtk_widget_destroyed, &aboutbox);
495a1a6f1d99 [svn] prevent jack o.p. aboutbox from spawning multiple times
giacomo
parents: 517
diff changeset
582 }
325
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
583 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
584
517
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 325
diff changeset
585 static void
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 325
diff changeset
586 jack_tell_audio(AFormat * fmt, gint * srate, gint * nch)
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 325
diff changeset
587 {
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 325
diff changeset
588 (*fmt) = input.format;
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 325
diff changeset
589 (*srate) = input.frequency;
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 325
diff changeset
590 (*nch) = input.channels;
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 325
diff changeset
591 }
325
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
592
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
593 OutputPlugin jack_op =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
594 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
595 NULL,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
596 NULL,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
597 "JACK Output Plugin 0.15",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
598 jack_init,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
599 jack_cleanup,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
600 jack_about,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
601 jack_configure,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
602 jack_get_volume,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
603 jack_set_volume,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
604 jack_open,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
605 jack_write,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
606 jack_close,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
607 jack_flush,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
608 jack_pause,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
609 jack_free,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
610 jack_playing,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
611 jack_get_output_time,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
612 jack_get_written_time,
517
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 325
diff changeset
613 jack_tell_audio
325
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
614 };
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
615
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
616
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
617 OutputPlugin *get_oplugin_info(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
618 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
619 return &jack_op;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
620 }