2
* Copyright (C) 2003-2010 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 "decoder_api.h"
25
#include <wildmidi_lib.h>
28
#define G_LOG_DOMAIN "wildmidi"
31
WILDMIDI_SAMPLE_RATE = 48000,
35
wildmidi_init(const struct config_param *param)
37
const char *config_file;
40
config_file = config_get_block_string(param, "config_file",
41
"/etc/timidity/timidity.cfg");
42
if (!g_file_test(config_file, G_FILE_TEST_IS_REGULAR)) {
43
g_debug("configuration file does not exist: %s", config_file);
47
ret = WildMidi_Init(config_file, WILDMIDI_SAMPLE_RATE, 0);
58
wildmidi_file_decode(struct decoder *decoder, const char *path_fs)
60
static const struct audio_format audio_format = {
61
.sample_rate = WILDMIDI_SAMPLE_RATE,
62
.format = SAMPLE_FORMAT_S16,
66
const struct _WM_Info *info;
67
enum decoder_command cmd;
69
wm = WildMidi_Open(path_fs);
73
info = WildMidi_GetInfo(wm);
79
decoder_initialized(decoder, &audio_format, true,
80
info->approx_total_samples / WILDMIDI_SAMPLE_RATE);
86
info = WildMidi_GetInfo(wm);
90
len = WildMidi_GetOutput(wm, buffer, sizeof(buffer));
94
cmd = decoder_data(decoder, NULL, buffer, len, 0);
96
if (cmd == DECODE_COMMAND_SEEK) {
97
unsigned long seek_where = WILDMIDI_SAMPLE_RATE *
98
decoder_seek_where(decoder);
100
#ifdef HAVE_WILDMIDI_SAMPLED_SEEK
101
WildMidi_SampledSeek(wm, &seek_where);
103
WildMidi_FastSeek(wm, &seek_where);
105
decoder_command_finished(decoder);
106
cmd = DECODE_COMMAND_NONE;
109
} while (cmd == DECODE_COMMAND_NONE);
115
wildmidi_tag_dup(const char *path_fs)
117
midi *wm = WildMidi_Open(path_fs);
121
const struct _WM_Info *info = WildMidi_GetInfo(wm);
127
struct tag *tag = tag_new();
128
tag->time = info->approx_total_samples / WILDMIDI_SAMPLE_RATE;
135
static const char *const wildmidi_suffixes[] = {
140
const struct decoder_plugin wildmidi_decoder_plugin = {
142
.init = wildmidi_init,
143
.finish = wildmidi_finish,
144
.file_decode = wildmidi_file_decode,
145
.tag_dup = wildmidi_tag_dup,
146
.suffixes = wildmidi_suffixes,