2012-09-25 22:03:44 +02:00
|
|
|
/*
|
2014-01-13 22:30:36 +01:00
|
|
|
* Copyright (C) 2003-2014 The Music Player Daemon Project
|
2012-09-25 22:03:44 +02:00
|
|
|
* http://www.musicpd.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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "AdPlugDecoderPlugin.h"
|
2013-09-05 18:22:02 +02:00
|
|
|
#include "tag/TagHandler.hxx"
|
2014-01-24 00:02:24 +01:00
|
|
|
#include "../DecoderAPI.hxx"
|
2013-07-29 07:50:08 +02:00
|
|
|
#include "CheckAudioFormat.hxx"
|
2014-02-07 18:52:19 +01:00
|
|
|
#include "fs/Path.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Error.hxx"
|
2013-10-15 22:04:17 +02:00
|
|
|
#include "util/Macros.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "Log.hxx"
|
2012-09-25 22:03:44 +02:00
|
|
|
|
|
|
|
#include <adplug/adplug.h>
|
|
|
|
#include <adplug/emuopl.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
static unsigned sample_rate;
|
|
|
|
|
|
|
|
static bool
|
2013-08-04 11:30:26 +02:00
|
|
|
adplug_init(const config_param ¶m)
|
2012-09-25 22:03:44 +02:00
|
|
|
{
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
2012-09-25 22:03:44 +02:00
|
|
|
|
2013-08-04 11:30:26 +02:00
|
|
|
sample_rate = param.GetBlockValue("sample_rate", 48000u);
|
2013-08-10 18:02:44 +02:00
|
|
|
if (!audio_check_sample_rate(sample_rate, error)) {
|
2013-09-27 22:31:24 +02:00
|
|
|
LogError(error);
|
2012-09-25 22:03:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-02-07 18:52:19 +01:00
|
|
|
adplug_file_decode(Decoder &decoder, Path path_fs)
|
2012-09-25 22:03:44 +02:00
|
|
|
{
|
|
|
|
CEmuopl opl(sample_rate, true, true);
|
|
|
|
opl.init();
|
|
|
|
|
2014-02-07 18:52:19 +01:00
|
|
|
CPlayer *player = CAdPlug::factory(path_fs.c_str(), &opl);
|
2012-09-25 22:03:44 +02:00
|
|
|
if (player == nullptr)
|
|
|
|
return;
|
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
const AudioFormat audio_format(sample_rate, SampleFormat::S16, 2);
|
|
|
|
assert(audio_format.IsValid());
|
2012-09-25 22:03:44 +02:00
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
decoder_initialized(decoder, audio_format, false,
|
2014-08-29 20:52:39 +02:00
|
|
|
SongTime::FromMS(player->songlength()));
|
2012-09-25 22:03:44 +02:00
|
|
|
|
|
|
|
int16_t buffer[2048];
|
2013-10-15 22:04:17 +02:00
|
|
|
const unsigned frames_per_buffer = ARRAY_SIZE(buffer) / 2;
|
2013-09-27 12:11:37 +02:00
|
|
|
DecoderCommand cmd;
|
2012-09-25 22:03:44 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (!player->update())
|
|
|
|
break;
|
|
|
|
|
|
|
|
opl.update(buffer, frames_per_buffer);
|
2013-10-28 23:58:17 +01:00
|
|
|
cmd = decoder_data(decoder, nullptr,
|
2012-09-25 22:03:44 +02:00
|
|
|
buffer, sizeof(buffer),
|
|
|
|
0);
|
2013-09-27 12:11:37 +02:00
|
|
|
} while (cmd == DecoderCommand::NONE);
|
2012-09-25 22:03:44 +02:00
|
|
|
|
|
|
|
delete player;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-10-20 13:32:59 +02:00
|
|
|
adplug_scan_tag(TagType type, const std::string &value,
|
2012-09-25 22:03:44 +02:00
|
|
|
const struct tag_handler *handler, void *handler_ctx)
|
|
|
|
{
|
|
|
|
if (!value.empty())
|
|
|
|
tag_handler_invoke_tag(handler, handler_ctx,
|
|
|
|
type, value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2014-02-07 18:52:19 +01:00
|
|
|
adplug_scan_file(Path path_fs,
|
2012-09-25 22:03:44 +02:00
|
|
|
const struct tag_handler *handler, void *handler_ctx)
|
|
|
|
{
|
|
|
|
CEmuopl opl(sample_rate, true, true);
|
|
|
|
opl.init();
|
|
|
|
|
2014-02-07 18:52:19 +01:00
|
|
|
CPlayer *player = CAdPlug::factory(path_fs.c_str(), &opl);
|
2012-09-25 22:03:44 +02:00
|
|
|
if (player == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tag_handler_invoke_duration(handler, handler_ctx,
|
|
|
|
player->songlength() / 1000);
|
|
|
|
|
|
|
|
if (handler->tag != nullptr) {
|
|
|
|
adplug_scan_tag(TAG_TITLE, player->gettitle(),
|
|
|
|
handler, handler_ctx);
|
|
|
|
adplug_scan_tag(TAG_ARTIST, player->getauthor(),
|
|
|
|
handler, handler_ctx);
|
|
|
|
adplug_scan_tag(TAG_COMMENT, player->getdesc(),
|
|
|
|
handler, handler_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete player;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *const adplug_suffixes[] = {
|
|
|
|
"amd",
|
|
|
|
"d00",
|
|
|
|
"hsc",
|
|
|
|
"laa",
|
|
|
|
"rad",
|
|
|
|
"raw",
|
|
|
|
"sa2",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-10-21 20:31:34 +02:00
|
|
|
const struct DecoderPlugin adplug_decoder_plugin = {
|
2012-09-25 22:03:44 +02:00
|
|
|
"adplug",
|
|
|
|
adplug_init,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
adplug_file_decode,
|
|
|
|
adplug_scan_file,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
adplug_suffixes,
|
|
|
|
nullptr,
|
|
|
|
};
|