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
|
/*
* 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include "ip.h"
#include "xmalloc.h"
#include <mikmod.h>
#include "debug.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_HQMIXER */
| 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);
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)
{
/* Player_LoadTitle segfaults when we are playing a mod file.
* This is a bug in libmikmod.
*/
#if 0
struct keyval *c;
const char *name;
/* FIXME */
name=Player_LoadTitle(ip_data->filename);
c = xnew0(struct keyval, 2);
if (name != NULL && *name != 0) {
c[0].key = xstrdup("title");
c[0].val = xstrdup(name);
} else {
c[0].key = xstrdup("title");
c[0].val = xstrdup(ip_data->filename);
}
*comments = c;
#else
*comments = xnew0(struct keyval, 1);
#endif
return 0;
}
static int mik_duration(struct input_plugin_data *ip_data)
{
return -IP_ERROR_FUNCTION_NOT_SUPPORTED;
}
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
};
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 };
|