1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/*
* Adapted from AlsaPlayer 0.99.76
*
* mikmod_engine.c
* Copyright (C) 1999 Paul N. Fisher <rao@gnu.org>
* Copyright (C) 2002 Andy Lo A Foe <andy@alsaplayer.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "ip.h"
#include "xmalloc.h"
#include <mikmod.h>
#include "debug.h"
#include "comment.h"
struct mik_private {
MODULE *file;
};
static int mikmod_init(void)
{
static int inited = 0;
if (inited)
return 1;
MikMod_RegisterAllDrivers();
MikMod_RegisterAllLoaders();
md_reverb = 0;
/* we should let the user decide which one is better... */
md_mode = DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX | DMODE_STEREO |
DMODE_16BITS | DMODE_INTERP;
if (MikMod_Init(NULL)) {
d_print("Could not initialize mikmod, reason: %s\n",
MikMod_strerror(MikMod_errno));
return 0;
}
inited = 1;
return 1;
}
static int mik_open(struct input_plugin_data *ip_data)
{
MODULE *mf = NULL;
struct mik_private *priv;
int mi = mikmod_init();
if (!mi)
return -IP_ERROR_INTERNAL;
mf = Player_Load(ip_data->filename, 255, 0);
if (!mf)
return -IP_ERROR_ERRNO;
priv = xnew(struct mik_private, 1);
priv->file = mf;
ip_data->private = priv;
ip_data->sf = sf_bits(16) | sf_rate(44100) | sf_channels(2) | sf_signed(1);
#ifdef WORDS_BIGENDIAN
ip_data->sf |= sf_bigendian(1);
#endif
channel_map_init_stereo(ip_data->channel_map);
return 0;
}
static int mik_close(struct input_plugin_data *ip_data)
{
struct mik_private *priv = ip_data->private;
Player_Stop();
Player_Free(priv->file);
free(ip_data->private);
ip_data->private = NULL;
return 0;
}
static int mik_read(struct input_plugin_data *ip_data, char *buffer, int count)
{
int length;
struct mik_private *priv = ip_data->private;
if (!Player_Active())
Player_Start(priv->file);
if (!Player_Active())
return 0;
length = VC_WriteBytes(buffer, count);
return length;
}
static int mik_seek(struct input_plugin_data *ip_data, double offset)
{
/* cannot seek in modules properly */
return -IP_ERROR_FUNCTION_NOT_SUPPORTED;
}
static int mik_read_comments(struct input_plugin_data *ip_data, struct keyval **comments)
{
struct mik_private *priv = ip_data->private;
GROWING_KEYVALS(c);
const char *val;
val = priv->file->songname;
if (val && val[0])
comments_add_const(&c, "title", val);
val = priv->file->comment;
if (val && val[0])
comments_add_const(&c, "comment", val);
keyvals_terminate(&c);
*comments = c.keyvals;
return 0;
}
static int mik_duration(struct input_plugin_data *ip_data)
{
return -IP_ERROR_FUNCTION_NOT_SUPPORTED;
}
static long mik_bitrate(struct input_plugin_data *ip_data)
{
return -IP_ERROR_FUNCTION_NOT_SUPPORTED;
}
static char *mik_codec(struct input_plugin_data *ip_data)
{
struct mik_private *priv = ip_data->private;
const char *codec = priv->file->modtype;
return (codec && codec[0]) ? xstrdup(codec) : NULL;
}
static char *mik_codec_profile(struct input_plugin_data *ip_data)
{
return NULL;
}
const struct input_plugin_ops ip_ops = {
.open = mik_open,
.close = mik_close,
.read = mik_read,
.seek = mik_seek,
.read_comments = mik_read_comments,
.duration = mik_duration,
.bitrate = mik_bitrate,
.bitrate_current = mik_bitrate,
.codec = mik_codec,
.codec_profile = mik_codec_profile
};
const int ip_priority = 40;
const char * const ip_extensions[] = {
"mod", "s3m", "xm", "it", "669", "amf", "dsm",
"far", "med", "mtm", "stm", "ult",
NULL
};
const char * const ip_mime_types[] = { NULL };
const char * const ip_options[] = { NULL };
|