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 "AdPlugDecoderPlugin.h"
22
#include "tag/TagHandler.hxx"
23
#include "DecoderAPI.hxx"
24
#include "CheckAudioFormat.hxx"
25
#include "util/Error.hxx"
26
#include "util/Macros.hxx"
29
#include <adplug/adplug.h>
30
#include <adplug/emuopl.h>
34
static unsigned sample_rate;
37
adplug_init(const config_param ¶m)
41
sample_rate = param.GetBlockValue("sample_rate", 48000u);
42
if (!audio_check_sample_rate(sample_rate, error)) {
51
adplug_file_decode(Decoder &decoder, const char *path_fs)
53
CEmuopl opl(sample_rate, true, true);
56
CPlayer *player = CAdPlug::factory(path_fs, &opl);
57
if (player == nullptr)
60
const AudioFormat audio_format(sample_rate, SampleFormat::S16, 2);
61
assert(audio_format.IsValid());
63
decoder_initialized(decoder, audio_format, false,
64
player->songlength() / 1000.);
67
const unsigned frames_per_buffer = ARRAY_SIZE(buffer) / 2;
71
if (!player->update())
74
opl.update(buffer, frames_per_buffer);
75
cmd = decoder_data(decoder, nullptr,
76
buffer, sizeof(buffer),
78
} while (cmd == DecoderCommand::NONE);
84
adplug_scan_tag(TagType type, const std::string &value,
85
const struct tag_handler *handler, void *handler_ctx)
88
tag_handler_invoke_tag(handler, handler_ctx,
93
adplug_scan_file(const char *path_fs,
94
const struct tag_handler *handler, void *handler_ctx)
96
CEmuopl opl(sample_rate, true, true);
99
CPlayer *player = CAdPlug::factory(path_fs, &opl);
100
if (player == nullptr)
103
tag_handler_invoke_duration(handler, handler_ctx,
104
player->songlength() / 1000);
106
if (handler->tag != nullptr) {
107
adplug_scan_tag(TAG_TITLE, player->gettitle(),
108
handler, handler_ctx);
109
adplug_scan_tag(TAG_ARTIST, player->getauthor(),
110
handler, handler_ctx);
111
adplug_scan_tag(TAG_COMMENT, player->getdesc(),
112
handler, handler_ctx);
119
static const char *const adplug_suffixes[] = {
130
const struct DecoderPlugin adplug_decoder_plugin = {