2 * Adapted from AlsaPlayer 0.99.76
5 * Copyright (C) 1999 Paul N. Fisher <rao@gnu.org>
6 * Copyright (C) 2002 Andy Lo A Foe <andy@alsaplayer.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 static int mikmod_init(void)
35 static int inited
= 0;
40 MikMod_RegisterAllDrivers();
41 MikMod_RegisterAllLoaders();
44 /* we should let the user decide which one is better... */
45 md_mode
= (DMODE_SOFT_MUSIC
| DMODE_SOFT_SNDFX
| DMODE_STEREO
| DMODE_16BITS
49 if (MikMod_Init(NULL
)) {
50 d_print("Could not initialize mikmod, reason: %s\n",
51 MikMod_strerror(MikMod_errno
));
59 static int mik_open(struct input_plugin_data
*ip_data
)
62 struct mik_private
*priv
;
66 return -IP_ERROR_INTERNAL
;
68 mf
= Player_Load(ip_data
->filename
, 255, 0);
71 return -IP_ERROR_ERRNO
;
73 priv
= xnew(struct mik_private
, 1);
76 ip_data
->private = priv
;
77 ip_data
->sf
= sf_bits(16) | sf_rate(44100) | sf_channels(2) | sf_signed(1);
81 static int mik_close(struct input_plugin_data
*ip_data
)
83 struct mik_private
*priv
= ip_data
->private;
86 Player_Free(priv
->file
);
87 free(ip_data
->private);
88 ip_data
->private = NULL
;
92 static int mik_read(struct input_plugin_data
*ip_data
, char *buffer
, int count
)
95 struct mik_private
*priv
= ip_data
->private;
98 Player_Start(priv
->file
);
100 if (!Player_Active())
103 length
= VC_WriteBytes(buffer
, count
);
108 static int mik_seek(struct input_plugin_data
*ip_data
, double offset
)
110 /* cannot seek in modules properly */
111 return -IP_ERROR_FUNCTION_NOT_SUPPORTED
;
114 static int mik_read_comments(struct input_plugin_data
*ip_data
, struct keyval
**comments
)
116 /* Player_LoadTitle segfaults when we are playing a mod file.
117 * This is a bug in libmikmod.
124 name
=Player_LoadTitle(ip_data
->filename
);
125 c
= xnew0(struct keyval
, 2);
127 if (name
!= NULL
&& *name
!= 0) {
128 c
[0].key
= xstrdup("title");
129 c
[0].val
= xstrdup(name
);
131 c
[0].key
= xstrdup("title");
132 c
[0].val
= xstrdup(ip_data
->filename
);
136 *comments
= xnew0(struct keyval
, 1);
141 static int mik_duration(struct input_plugin_data
*ip_data
)
143 return -IP_ERROR_FUNCTION_NOT_SUPPORTED
;
146 const struct input_plugin_ops ip_ops
= {
151 .read_comments
= mik_read_comments
,
152 .duration
= mik_duration
155 const char * const ip_extensions
[] = {
156 "mod", "s3m", "xm", "it", "669", "amf", "dsm",
157 "far", "med", "mtm", "stm", "ult",
161 const char * const ip_mime_types
[] = { NULL
};