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
|
46 DMODE_16BITS
| DMODE_INTERP
;
48 if (MikMod_Init(NULL
)) {
49 d_print("Could not initialize mikmod, reason: %s\n",
50 MikMod_strerror(MikMod_errno
));
58 static int mik_open(struct input_plugin_data
*ip_data
)
61 struct mik_private
*priv
;
62 int mi
= mikmod_init();
65 return -IP_ERROR_INTERNAL
;
67 mf
= Player_Load(ip_data
->filename
, 255, 0);
70 return -IP_ERROR_ERRNO
;
72 priv
= xnew(struct mik_private
, 1);
75 ip_data
->private = priv
;
76 ip_data
->sf
= sf_bits(16) | sf_rate(44100) | sf_channels(2) | sf_signed(1);
80 static int mik_close(struct input_plugin_data
*ip_data
)
82 struct mik_private
*priv
= ip_data
->private;
85 Player_Free(priv
->file
);
86 free(ip_data
->private);
87 ip_data
->private = NULL
;
91 static int mik_read(struct input_plugin_data
*ip_data
, char *buffer
, int count
)
94 struct mik_private
*priv
= ip_data
->private;
97 Player_Start(priv
->file
);
102 length
= VC_WriteBytes(buffer
, count
);
107 static int mik_seek(struct input_plugin_data
*ip_data
, double offset
)
109 /* cannot seek in modules properly */
110 return -IP_ERROR_FUNCTION_NOT_SUPPORTED
;
113 static int mik_read_comments(struct input_plugin_data
*ip_data
, struct keyval
**comments
)
115 /* Player_LoadTitle segfaults when we are playing a mod file.
116 * This is a bug in libmikmod.
123 name
= Player_LoadTitle(ip_data
->filename
);
124 c
= xnew0(struct keyval
, 2);
126 if (name
!= NULL
&& *name
!= 0) {
127 c
[0].key
= xstrdup("title");
128 c
[0].val
= xstrdup(name
);
130 c
[0].key
= xstrdup("title");
131 c
[0].val
= xstrdup(ip_data
->filename
);
135 *comments
= xnew0(struct keyval
, 1);
140 static int mik_duration(struct input_plugin_data
*ip_data
)
142 return -IP_ERROR_FUNCTION_NOT_SUPPORTED
;
145 const struct input_plugin_ops ip_ops
= {
150 .read_comments
= mik_read_comments
,
151 .duration
= mik_duration
154 const char * const ip_extensions
[] = {
155 "mod", "s3m", "xm", "it", "669", "amf", "dsm",
156 "far", "med", "mtm", "stm", "ult",
160 const char * const ip_mime_types
[] = { NULL
};