2
* Copyright (C) 2003-2013 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
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 General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "MikmodDecoderPlugin.hxx"
22
#include "DecoderAPI.hxx"
23
#include "tag/TagHandler.hxx"
24
#include "system/FatalError.hxx"
25
#include "util/Domain.hxx"
32
static constexpr Domain mikmod_domain("mikmod");
34
/* this is largely copied from alsaplayer */
36
static constexpr size_t MIKMOD_FRAME_SIZE = 4096;
51
mikmod_mpd_update(void)
56
mikmod_mpd_is_present(void)
61
static char drv_name[] = PACKAGE_NAME;
62
static char drv_version[] = VERSION;
64
#if (LIBMIKMOD_VERSION > 0x030106)
65
static char drv_alias[] = PACKAGE;
68
static MDRIVER drv_mpd = {
74
#if (LIBMIKMOD_VERSION > 0x030106)
76
#if (LIBMIKMOD_VERSION >= 0x030200)
77
nullptr, /* CmdLineHelp */
79
nullptr, /* CommandLine */
81
mikmod_mpd_is_present,
107
static bool mikmod_loop;
108
static unsigned mikmod_sample_rate;
111
mikmod_decoder_init(const config_param ¶m)
113
static char params[] = "";
115
mikmod_loop = param.GetBlockValue("loop", false);
116
mikmod_sample_rate = param.GetBlockValue("sample_rate", 44100u);
117
if (!audio_valid_sample_rate(mikmod_sample_rate))
118
FormatFatalError("Invalid sample rate in line %d: %u",
119
param.line, mikmod_sample_rate);
124
MikMod_RegisterDriver(&drv_mpd);
125
MikMod_RegisterAllLoaders();
128
md_mixfreq = mikmod_sample_rate;
129
md_mode = (DMODE_SOFT_MUSIC | DMODE_INTERP | DMODE_STEREO |
132
if (MikMod_Init(params)) {
133
FormatError(mikmod_domain,
134
"Could not init MikMod: %s",
135
MikMod_strerror(MikMod_errno));
143
mikmod_decoder_finish(void)
149
mikmod_decoder_file_decode(Decoder &decoder, const char *path_fs)
151
/* deconstify the path because libmikmod wants a non-const
153
char *const path2 = const_cast<char *>(path_fs);
157
SBYTE buffer[MIKMOD_FRAME_SIZE];
159
handle = Player_Load(path2, 128, 0);
161
if (handle == nullptr) {
162
FormatError(mikmod_domain,
163
"failed to open mod: %s", path_fs);
167
handle->loop = mikmod_loop;
169
const AudioFormat audio_format(mikmod_sample_rate, SampleFormat::S16, 2);
170
assert(audio_format.IsValid());
172
decoder_initialized(decoder, audio_format, false, 0);
174
Player_Start(handle);
176
DecoderCommand cmd = DecoderCommand::NONE;
177
while (cmd == DecoderCommand::NONE && Player_Active()) {
178
ret = VC_WriteBytes(buffer, sizeof(buffer));
179
cmd = decoder_data(decoder, nullptr, buffer, ret, 0);
187
mikmod_decoder_scan_file(const char *path_fs,
188
const struct tag_handler *handler, void *handler_ctx)
190
/* deconstify the path because libmikmod wants a non-const
192
char *const path2 = const_cast<char *>(path_fs);
194
MODULE *handle = Player_Load(path2, 128, 0);
196
if (handle == nullptr) {
197
FormatDebug(mikmod_domain,
198
"Failed to open file: %s", path_fs);
204
char *title = Player_LoadTitle(path2);
205
if (title != nullptr) {
206
tag_handler_invoke_tag(handler, handler_ctx,
208
#if (LIBMIKMOD_VERSION >= 0x030200)
218
static const char *const mikmod_decoder_suffixes[] = {
237
const struct DecoderPlugin mikmod_decoder_plugin = {
240
mikmod_decoder_finish,
242
mikmod_decoder_file_decode,
243
mikmod_decoder_scan_file,
246
mikmod_decoder_suffixes,