61
|
1
|
|
2 /* MikMod sound library
|
|
3 (c) 1998 Miodrag Vallat and others - see file AUTHORS for complete list
|
|
4
|
|
5 This library is free software; you can redistribute it and/or modify
|
|
6 it under the terms of the GNU Library General Public License as
|
|
7 published by the Free Software Foundation; either version 2 of
|
|
8 the License, or (at your option) any later version.
|
|
9
|
|
10 This program is distributed in the hope that it will be useful,
|
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 GNU Library General Public License for more details.
|
|
14
|
|
15 You should have received a copy of the GNU Library General Public
|
|
16 License along with this library; if not, write to the Free Software
|
|
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
18
|
|
19 Modified 2/1/99 for xmms by J. Nick Koston (BlueDraco)
|
|
20 */
|
|
21
|
|
22 /*==============================================================================
|
|
23
|
|
24 $Id: drv_xmms.c,v 1.4 2002/04/27 18:47:08 havard Exp $
|
|
25
|
|
26 Output data to xmms
|
|
27
|
|
28 ==============================================================================*/
|
|
29
|
|
30 #ifdef HAVE_CONFIG_H
|
|
31 #include "config.h"
|
|
32 #endif
|
|
33
|
|
34 #ifdef HAVE_UNISTD_H
|
|
35 #include <unistd.h>
|
|
36 #endif
|
|
37 #include <stdlib.h>
|
|
38 #include "libaudacious/util.h"
|
|
39
|
|
40 #include "mikmod-plugin.h"
|
|
41
|
|
42 static int buffer_size;
|
|
43
|
|
44 static SBYTE *audiobuffer = NULL;
|
|
45 extern MIKMODConfig mikmod_cfg;
|
|
46 static short audio_open = FALSE;
|
|
47 gboolean mikmod_xmms_audio_error = FALSE;
|
|
48 extern gboolean mikmod_going;
|
|
49
|
|
50 static BOOL xmms_IsThere(void)
|
|
51 {
|
|
52 return 1;
|
|
53 }
|
|
54
|
|
55 static BOOL xmms_Init(void)
|
|
56 {
|
|
57 AFormat fmt;
|
|
58 int nch;
|
|
59
|
|
60 buffer_size = 512;
|
|
61 if (!mikmod_cfg.force8bit)
|
|
62 buffer_size *= 2;
|
|
63 if (!mikmod_cfg.force_mono)
|
|
64 buffer_size *= 2;
|
|
65 if (!(audiobuffer = (SBYTE *) g_malloc0(buffer_size)))
|
|
66 return 1;
|
|
67
|
|
68 fmt = (md_mode & DMODE_16BITS) ? FMT_S16_NE : FMT_U8;
|
|
69 nch = (md_mode & DMODE_STEREO) ? 2 : 1;
|
|
70
|
|
71 if (audio_open)
|
|
72 mikmod_ip.output->close_audio();
|
|
73
|
|
74 if (!mikmod_ip.output->open_audio(fmt, md_mixfreq, nch))
|
|
75 {
|
|
76 mikmod_xmms_audio_error = TRUE;
|
|
77 return 1;
|
|
78 }
|
|
79 audio_open = TRUE;
|
|
80
|
|
81 return VC_Init();
|
|
82 }
|
|
83
|
|
84 static void xmms_Exit(void)
|
|
85 {
|
|
86 VC_Exit();
|
|
87 if (audiobuffer)
|
|
88 {
|
|
89 g_free(audiobuffer);
|
|
90 audiobuffer = NULL;
|
|
91 }
|
|
92 if (audio_open)
|
|
93 {
|
|
94 mikmod_ip.output->close_audio();
|
|
95 audio_open = FALSE;
|
|
96 }
|
|
97
|
|
98 }
|
|
99
|
|
100 static void xmms_Update(void)
|
|
101 {
|
|
102 gint length;
|
|
103
|
|
104 length = VC_WriteBytes((SBYTE *) audiobuffer, buffer_size);
|
|
105 mikmod_ip.add_vis_pcm(mikmod_ip.output->written_time(), mikmod_cfg.force8bit ? FMT_U8 : FMT_S16_NE, mikmod_cfg.force_mono ? 1 : 2, length, audiobuffer);
|
|
106
|
|
107 while(mikmod_ip.output->buffer_free() < length && mikmod_going)
|
|
108 xmms_usleep(10000);
|
|
109 if(mikmod_going)
|
|
110 mikmod_ip.output->write_audio(audiobuffer, length);
|
|
111
|
|
112 }
|
|
113
|
|
114 static BOOL xmms_Reset(void)
|
|
115 {
|
|
116 VC_Exit();
|
|
117 return VC_Init();
|
|
118 }
|
|
119
|
|
120 MDRIVER drv_xmms =
|
|
121 {
|
|
122 NULL,
|
|
123 "xmms",
|
|
124 "xmms output driver v1.0",
|
|
125 0, 255,
|
|
126 #if (LIBMIKMOD_VERSION > 0x030106)
|
|
127 "xmms",
|
|
128 NULL,
|
|
129 #endif
|
|
130 xmms_IsThere,
|
|
131 VC_SampleLoad,
|
|
132 VC_SampleUnload,
|
|
133 VC_SampleSpace,
|
|
134 VC_SampleLength,
|
|
135 xmms_Init,
|
|
136 xmms_Exit,
|
|
137 xmms_Reset,
|
|
138 VC_SetNumVoices,
|
|
139 VC_PlayStart,
|
|
140 VC_PlayStop,
|
|
141 xmms_Update,
|
|
142 NULL,
|
|
143 VC_VoiceSetVolume,
|
|
144 VC_VoiceGetVolume,
|
|
145 VC_VoiceSetFrequency,
|
|
146 VC_VoiceGetFrequency,
|
|
147 VC_VoiceSetPanning,
|
|
148 VC_VoiceGetPanning,
|
|
149 VC_VoicePlay,
|
|
150 VC_VoiceStop,
|
|
151 VC_VoiceStopped,
|
|
152 VC_VoiceGetPosition,
|
|
153 VC_VoiceRealVolume
|
|
154
|
|
155 };
|