2017-05-01 10:56:40 +02:00
|
|
|
/**
|
|
|
|
* vgmstream for Audacious
|
|
|
|
*/
|
|
|
|
|
2014-08-10 21:33:01 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <algorithm>
|
2017-05-01 10:56:40 +02:00
|
|
|
#include <string.h>
|
2014-08-10 21:33:01 +02:00
|
|
|
|
2015-06-22 10:03:44 +02:00
|
|
|
#if DEBUG
|
|
|
|
#include <ctime>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
2014-08-10 21:33:01 +02:00
|
|
|
|
2017-05-01 10:56:40 +02:00
|
|
|
#include <libaudcore/audio.h>
|
|
|
|
|
|
|
|
|
2014-08-10 21:33:01 +02:00
|
|
|
extern "C" {
|
|
|
|
#include "../src/vgmstream.h"
|
2019-10-06 23:31:32 +02:00
|
|
|
#include "../src/plugins.h"
|
2014-08-10 21:33:01 +02:00
|
|
|
}
|
2015-06-22 10:03:44 +02:00
|
|
|
#include "plugin.h"
|
2014-08-10 21:33:01 +02:00
|
|
|
#include "vfs.h"
|
|
|
|
|
2015-06-22 10:03:44 +02:00
|
|
|
|
2021-08-07 20:41:50 +02:00
|
|
|
#include "../version.h"
|
|
|
|
#ifndef VGMSTREAM_VERSION
|
2021-08-15 19:24:48 +02:00
|
|
|
#define VGMSTREAM_VERSION "unknown version " __DATE__
|
2017-05-01 13:33:45 +02:00
|
|
|
#endif
|
|
|
|
|
2021-08-15 19:24:48 +02:00
|
|
|
#define PLUGIN_NAME "vgmstream plugin " VGMSTREAM_VERSION
|
|
|
|
#define PLUGIN_INFO PLUGIN_NAME " (" __DATE__ ")"
|
|
|
|
|
|
|
|
|
2017-05-01 10:56:40 +02:00
|
|
|
#define CFG_ID "vgmstream" // ID for storing in audacious
|
|
|
|
#define MIN_BUFFER_SIZE 576
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
/* global state */
|
|
|
|
/*EXPORT*/ VgmstreamPlugin aud_plugin_instance;
|
2020-08-01 10:30:12 +02:00
|
|
|
audacious_settings_t settings;
|
2015-07-10 04:32:53 +02:00
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
static const char* tagfile_name = "!tags.m3u";
|
|
|
|
|
2019-10-13 19:09:17 +02:00
|
|
|
/* Audacious will first send the file to a plugin based on this static extension list. If none
|
|
|
|
* accepts it'll try again all plugins, ordered by priority, until one accepts the file. Problem is,
|
|
|
|
* mpg123 plugin has higher priority and tendency to accept files that aren't even MP3. To fix this
|
|
|
|
* we declare a few conflicting formats so we have a better chance.
|
|
|
|
* The extension affects only this priority and in all cases file must accepted during "is_our_file".
|
|
|
|
*/
|
|
|
|
const char *const VgmstreamPlugin::exts[] = {
|
|
|
|
"ahx","asf","awc","ckd","fsb","genh","msf","p3d","rak","scd","str","txth","xvag", nullptr
|
|
|
|
};
|
|
|
|
|
2014-08-10 21:33:01 +02:00
|
|
|
|
2017-05-01 10:56:40 +02:00
|
|
|
const char *const VgmstreamPlugin::defaults[] = {
|
2019-10-06 23:31:32 +02:00
|
|
|
"loop_forever", "FALSE",
|
2020-08-01 10:30:12 +02:00
|
|
|
"ignore_loop", "FALSE",
|
2020-08-01 12:24:54 +02:00
|
|
|
"loop_count", "2.0",
|
2019-10-06 23:31:32 +02:00
|
|
|
"fade_length", "10.0",
|
|
|
|
"fade_delay", "0.0",
|
2020-08-01 12:24:54 +02:00
|
|
|
"downmix_channels", "2",
|
2019-10-06 23:31:32 +02:00
|
|
|
"exts_unknown_on", "FALSE",
|
|
|
|
"exts_common_on", "FALSE",
|
2020-09-12 15:03:22 +02:00
|
|
|
"tagfile_disable", "FALSE",
|
2017-05-01 10:56:40 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// N_(...) for i18n but not much point here
|
2017-05-01 10:56:40 +02:00
|
|
|
const char VgmstreamPlugin::about[] =
|
2021-08-15 19:24:48 +02:00
|
|
|
PLUGIN_INFO "\n"
|
|
|
|
"by hcs, FastElbja, manakoAT, bxaimc, snakemeat, soneek, kode54, bnnm, Nicknine, Thealexbarney, CyberBotX, and many others\n"
|
2017-05-01 10:56:40 +02:00
|
|
|
"\n"
|
2017-05-01 14:18:33 +02:00
|
|
|
"Audacious plugin:\n"
|
2021-08-15 19:24:48 +02:00
|
|
|
"- ported to Audacious 3.6 by Brandon Whitehead\n"
|
|
|
|
"- adopted from Audacious 3 port by Thomas Eppers\n"
|
|
|
|
"- originally written by Todd Jeffreys (http://voidpointer.org/)\n"
|
2017-05-01 14:18:33 +02:00
|
|
|
"\n"
|
2021-08-15 19:24:48 +02:00
|
|
|
"https://github.com/vgmstream/vgmstream/\n"
|
2017-05-01 14:18:33 +02:00
|
|
|
"https://sourceforge.net/projects/vgmstream/ (original)";
|
2015-06-22 10:03:44 +02:00
|
|
|
|
2020-08-01 12:24:54 +02:00
|
|
|
/* widget config: {min, max, step} */
|
2017-05-01 10:56:40 +02:00
|
|
|
const PreferencesWidget VgmstreamPlugin::widgets[] = {
|
2019-10-06 23:31:32 +02:00
|
|
|
WidgetLabel(N_("<b>vgmstream config</b>")),
|
|
|
|
WidgetCheck(N_("Loop forever:"), WidgetBool(settings.loop_forever)),
|
2020-08-01 10:30:12 +02:00
|
|
|
WidgetCheck(N_("Ignore loop:"), WidgetBool(settings.ignore_loop)),
|
2020-08-01 12:24:54 +02:00
|
|
|
WidgetSpin(N_("Loop count:"), WidgetFloat(settings.loop_count), {1, 100, 1.0}),
|
2020-08-01 10:30:12 +02:00
|
|
|
WidgetSpin(N_("Fade length:"), WidgetFloat(settings.fade_time), {0, 60, 0.1}),
|
2019-10-06 23:31:32 +02:00
|
|
|
WidgetSpin(N_("Fade delay:"), WidgetFloat(settings.fade_delay), {0, 60, 0.1}),
|
2020-08-01 12:24:54 +02:00
|
|
|
WidgetSpin(N_("Downmix:"), WidgetInt(settings.downmix_channels), {0, 8, 1}),
|
2020-09-12 15:03:22 +02:00
|
|
|
WidgetCheck(N_("Enable unknown exts:"), WidgetBool(settings.exts_unknown_on)),
|
2019-10-06 23:31:32 +02:00
|
|
|
// Audacious 3.6 will only match one plugin so this option has no actual use
|
|
|
|
// (ex. a fake .flac only gets to the FLAC plugin and never to vgmstream, even on error)
|
|
|
|
//WidgetCheck(N_("Enable common exts"), WidgetBool(settings.exts_common_on)),
|
2020-09-12 15:03:22 +02:00
|
|
|
WidgetCheck(N_("Disable tagfile:"), WidgetBool(settings.tagfile_disable)),
|
2015-06-22 10:03:44 +02:00
|
|
|
};
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
void vgmstream_settings_load() {
|
|
|
|
AUDINFO("load settings\n");
|
2017-05-01 10:56:40 +02:00
|
|
|
aud_config_set_defaults(CFG_ID, VgmstreamPlugin::defaults);
|
2019-10-06 23:31:32 +02:00
|
|
|
settings.loop_forever = aud_get_bool(CFG_ID, "loop_forever");
|
2020-08-01 10:30:12 +02:00
|
|
|
settings.ignore_loop = aud_get_bool(CFG_ID, "ignore_loop");
|
2020-08-01 12:24:54 +02:00
|
|
|
settings.loop_count = aud_get_double(CFG_ID, "loop_count");
|
2020-08-01 10:30:12 +02:00
|
|
|
settings.fade_time = aud_get_double(CFG_ID, "fade_length");
|
2019-10-06 23:31:32 +02:00
|
|
|
settings.fade_delay = aud_get_double(CFG_ID, "fade_delay");
|
|
|
|
settings.downmix_channels = aud_get_int(CFG_ID, "downmix_channels");
|
|
|
|
settings.exts_unknown_on = aud_get_bool(CFG_ID, "exts_unknown_on");
|
|
|
|
settings.exts_common_on = aud_get_bool(CFG_ID, "exts_common_on");
|
2015-06-22 10:03:44 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
void vgmstream_settings_save() {
|
|
|
|
AUDINFO("save settings\n");
|
|
|
|
aud_set_bool(CFG_ID, "loop_forever", settings.loop_forever);
|
2020-08-01 10:30:12 +02:00
|
|
|
aud_set_bool(CFG_ID, "ignore_loop", settings.ignore_loop);
|
2020-08-01 12:24:54 +02:00
|
|
|
aud_set_double(CFG_ID, "loop_count", settings.loop_count);
|
2020-08-01 10:30:12 +02:00
|
|
|
aud_set_double(CFG_ID, "fade_length", settings.fade_time);
|
2019-10-06 23:31:32 +02:00
|
|
|
aud_set_double(CFG_ID, "fade_delay", settings.fade_delay);
|
|
|
|
aud_set_int(CFG_ID, "downmix_channels", settings.downmix_channels);
|
|
|
|
aud_set_bool(CFG_ID, "exts_unknown_on", settings.exts_unknown_on);
|
|
|
|
aud_set_bool(CFG_ID, "exts_common_on", settings.exts_common_on);
|
2015-06-22 10:03:44 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 10:56:40 +02:00
|
|
|
const PluginPreferences VgmstreamPlugin::prefs = {
|
2019-10-06 23:31:32 +02:00
|
|
|
{widgets}, vgmstream_settings_load, vgmstream_settings_save
|
2017-05-01 10:56:40 +02:00
|
|
|
};
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// validate extension (thread safe)
|
2020-08-01 10:30:12 +02:00
|
|
|
bool VgmstreamPlugin::is_our_file(const char * filename, VFSFile & file) {
|
2019-10-06 23:31:32 +02:00
|
|
|
AUDDBG("test file=%s\n", filename);
|
|
|
|
|
|
|
|
vgmstream_ctx_valid_cfg cfg = {0};
|
2015-06-22 10:03:44 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
cfg.accept_unknown = settings.exts_unknown_on;
|
|
|
|
cfg.accept_common = settings.exts_common_on;
|
|
|
|
return vgmstream_ctx_is_valid(filename, &cfg) > 0 ? true : false;
|
2014-08-10 21:33:01 +02:00
|
|
|
}
|
|
|
|
|
2021-08-26 22:16:31 +02:00
|
|
|
|
|
|
|
/* default output in audacious is: "INFO/DEBUG plugin.cc:xxx [(fn name)]: (msg)" */
|
|
|
|
static void vgmstream_log(int level, const char* str) {
|
2021-08-26 18:43:17 +02:00
|
|
|
if (level == VGM_LOG_LEVEL_DEBUG)
|
2021-08-26 22:16:31 +02:00
|
|
|
AUDDBG("%s", str);
|
2021-08-26 18:43:17 +02:00
|
|
|
else
|
2021-08-26 22:16:31 +02:00
|
|
|
AUDINFO("%s", str);
|
2021-08-26 18:43:17 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// called on startup (main thread)
|
2017-05-01 10:56:40 +02:00
|
|
|
bool VgmstreamPlugin::init() {
|
2021-08-26 18:43:17 +02:00
|
|
|
AUDINFO("vgmstream plugin start\n");
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
vgmstream_settings_load();
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2021-08-27 00:23:44 +02:00
|
|
|
vgmstream_set_log_callback(VGM_LOG_LEVEL_ALL, (void*)&vgmstream_log);
|
2021-08-26 18:43:17 +02:00
|
|
|
|
2017-05-01 10:56:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// called on stop (main thread)
|
2017-05-01 10:56:40 +02:00
|
|
|
void VgmstreamPlugin::cleanup() {
|
2021-08-26 18:43:17 +02:00
|
|
|
AUDINFO("vgmstream plugin end\n");
|
2019-10-06 23:31:32 +02:00
|
|
|
|
|
|
|
vgmstream_settings_save();
|
|
|
|
}
|
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
static int get_basename_subtune(const char* filename, char* buf, int buf_len, int* p_subtune) {
|
2019-10-06 23:31:32 +02:00
|
|
|
int subtune;
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
const char* pos = strrchr(filename, '?');
|
|
|
|
if (!pos)
|
|
|
|
return 0;
|
|
|
|
if (sscanf(pos, "?%i", &subtune) != 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (p_subtune)
|
|
|
|
*p_subtune = subtune;
|
|
|
|
|
|
|
|
strncpy(buf, filename, buf_len);
|
|
|
|
char* pos2 = strrchr(buf, '?');
|
|
|
|
if (pos2) //removes '?'
|
|
|
|
pos2[0] = '\0';
|
|
|
|
|
|
|
|
return 1;
|
2014-08-10 21:33:01 +02:00
|
|
|
}
|
|
|
|
|
2020-08-01 10:30:12 +02:00
|
|
|
static void apply_config(VGMSTREAM* vgmstream, audacious_settings_t* settings) {
|
|
|
|
vgmstream_cfg_t vcfg = {0};
|
|
|
|
|
|
|
|
vcfg.allow_play_forever = 1;
|
|
|
|
vcfg.play_forever = settings->loop_forever;
|
|
|
|
vcfg.loop_count = settings->loop_count;
|
|
|
|
vcfg.fade_time = settings->fade_time;
|
|
|
|
vcfg.fade_delay = settings->fade_delay;
|
|
|
|
vcfg.ignore_loop = settings->ignore_loop;
|
|
|
|
|
|
|
|
vgmstream_apply_config(vgmstream, &vcfg);
|
|
|
|
}
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// internal helper, called every time user adds a new file to playlist
|
2020-08-01 10:30:12 +02:00
|
|
|
static bool read_info(const char* filename, Tuple & tuple) {
|
2019-10-06 23:31:32 +02:00
|
|
|
AUDINFO("read file=%s\n", filename);
|
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
// Audacious first calls this as a regular file (use_subtune is 0). If file has subsongs,
|
|
|
|
// you need to detect and call set_subtunes below and return. Then Audacious will call again
|
|
|
|
// this and "play" with "filename?N" (where N=subtune, 1=first), that must be detected and handled
|
|
|
|
// (see plugin.h)
|
|
|
|
char basename[PATH_LIMIT]; //filename without '?'
|
|
|
|
int subtune = 0;
|
|
|
|
int use_subtune = get_basename_subtune(filename, basename, sizeof(basename), &subtune);
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
STREAMFILE* sf = open_vfs(use_subtune ? basename : filename);
|
2020-08-01 10:30:12 +02:00
|
|
|
if (!sf) return false;
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
if (use_subtune)
|
|
|
|
sf->stream_index = subtune;
|
|
|
|
|
2020-08-01 10:30:12 +02:00
|
|
|
VGMSTREAM* infostream = init_vgmstream_from_STREAMFILE(sf);
|
2019-09-21 13:30:55 +02:00
|
|
|
if (!infostream) {
|
2020-08-01 10:30:12 +02:00
|
|
|
close_streamfile(sf);
|
2017-05-01 10:56:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
int total_subtunes = infostream->num_streams;
|
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
// int was changed to short in some version, though vgmstream formats can exceed it
|
2019-10-06 23:31:32 +02:00
|
|
|
if (total_subtunes > 32767)
|
|
|
|
total_subtunes = 32767;
|
2020-09-12 15:03:22 +02:00
|
|
|
// format has subsongs but Audacious didn't ask for subsong yet
|
|
|
|
if (total_subtunes >= 1 && !use_subtune) {
|
2019-10-06 23:31:32 +02:00
|
|
|
//set nullptr to leave subsong index linear (must add +1 to subtune)
|
|
|
|
tuple.set_subtunes(total_subtunes, nullptr);
|
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
close_streamfile(sf);
|
|
|
|
close_vgmstream(infostream);
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-06 23:31:32 +02:00
|
|
|
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2020-08-01 12:24:54 +02:00
|
|
|
apply_config(infostream, &settings);
|
2020-08-01 10:30:12 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
int output_channels = infostream->channels;
|
|
|
|
vgmstream_mixing_autodownmix(infostream, settings.downmix_channels);
|
|
|
|
vgmstream_mixing_enable(infostream, 0, NULL, &output_channels);
|
|
|
|
|
|
|
|
int bitrate = get_vgmstream_average_bitrate(infostream);
|
2020-08-01 10:30:12 +02:00
|
|
|
int length_samples = vgmstream_get_samples(infostream);
|
|
|
|
int length_ms = length_samples * 1000LL / infostream->sample_rate;
|
2019-10-06 23:31:32 +02:00
|
|
|
|
2020-08-01 12:24:54 +02:00
|
|
|
//todo: set_format may throw std::bad_alloc if output_channels isn't supported (only 2?)
|
2019-10-06 23:31:32 +02:00
|
|
|
// short form, not sure if better way
|
|
|
|
tuple.set_format("vgmstream codec", output_channels, infostream->sample_rate, bitrate);
|
|
|
|
tuple.set_filename(filename); //used?
|
|
|
|
tuple.set_int(Tuple::Bitrate, bitrate); //in kb/s
|
2020-08-01 10:30:12 +02:00
|
|
|
tuple.set_int(Tuple::Length, length_ms);
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
//todo here we could call describe_vgmstream() and get substring to add tags and stuff
|
|
|
|
tuple.set_str(Tuple::Codec, "vgmstream codec");
|
2020-09-12 15:03:22 +02:00
|
|
|
if (use_subtune) {
|
|
|
|
tuple.set_int(Tuple::Subtune, subtune);
|
|
|
|
tuple.set_int(Tuple::NumSubtunes, infostream->num_streams);
|
|
|
|
|
|
|
|
char title[1024];
|
|
|
|
vgmstream_get_title(title, sizeof(title), basename, infostream, NULL);
|
|
|
|
tuple.set_str(Tuple::Title, title); //may be overwritten by tags
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// this function is only called when files are added to playlist,
|
|
|
|
// so to reload tags files need to readded
|
|
|
|
if (!settings.tagfile_disable) {
|
|
|
|
//todo improve string functions
|
|
|
|
char tagfile_path[PATH_LIMIT];
|
|
|
|
strcpy(tagfile_path, filename);
|
|
|
|
|
|
|
|
char *path = strrchr(tagfile_path,'/');
|
|
|
|
if (path != NULL) {
|
|
|
|
path[1] = '\0'; /* includes "/", remove after that from tagfile_path */
|
|
|
|
strcat(tagfile_path,tagfile_name);
|
|
|
|
}
|
|
|
|
else { /* ??? */
|
|
|
|
strcpy(tagfile_path,tagfile_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
STREAMFILE* sf_tags = open_vfs(tagfile_path);
|
|
|
|
if (sf_tags != NULL) {
|
|
|
|
VGMSTREAM_TAGS* tags;
|
|
|
|
const char *tag_key, *tag_val;
|
|
|
|
|
|
|
|
tags = vgmstream_tags_init(&tag_key, &tag_val);
|
|
|
|
vgmstream_tags_reset(tags, filename);
|
|
|
|
while (vgmstream_tags_next_tag(tags, sf_tags)) {
|
|
|
|
// see tuple.h (ugly but other plugins do it like this)
|
|
|
|
if (strcasecmp(tag_key, "ARTIST") == 0)
|
|
|
|
tuple.set_str(Tuple::Artist, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "ALBUMARTIST") == 0)
|
|
|
|
tuple.set_str(Tuple::AlbumArtist, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "TITLE") == 0)
|
|
|
|
tuple.set_str(Tuple::Title, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "ALBUM") == 0)
|
|
|
|
tuple.set_str(Tuple::Album, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "PERFORMER") == 0)
|
|
|
|
tuple.set_str(Tuple::Performer, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "COMPOSER") == 0)
|
|
|
|
tuple.set_str(Tuple::Composer, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "COMMENT") == 0)
|
|
|
|
tuple.set_str(Tuple::Comment, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "GENRE") == 0)
|
|
|
|
tuple.set_str(Tuple::Genre, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "TRACK") == 0)
|
|
|
|
tuple.set_int(Tuple::Track, atoi(tag_val));
|
|
|
|
else if (strcasecmp(tag_key, "YEAR") == 0)
|
|
|
|
tuple.set_int(Tuple::Year, atoi (tag_val));
|
|
|
|
#if defined(_AUD_PLUGIN_VERSION) && _AUD_PLUGIN_VERSION >= 48 // Audacious 3.8+
|
|
|
|
else if (strcasecmp(tag_key, "REPLAYGAIN_TRACK_GAIN") == 0)
|
|
|
|
tuple.set_gain(Tuple::TrackGain, Tuple::GainDivisor, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "REPLAYGAIN_TRACK_PEAK") == 0)
|
|
|
|
tuple.set_gain(Tuple::TrackPeak, Tuple::PeakDivisor, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "REPLAYGAIN_ALBUM_GAIN") == 0)
|
|
|
|
tuple.set_gain(Tuple::AlbumGain, Tuple::GainDivisor, tag_val);
|
|
|
|
else if (strcasecmp(tag_key, "REPLAYGAIN_ALBUM_PEAK") == 0)
|
|
|
|
tuple.set_gain(Tuple::AlbumPeak, Tuple::PeakDivisor, tag_val);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
vgmstream_tags_close(tags);
|
|
|
|
close_streamfile(sf_tags);
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 23:31:32 +02:00
|
|
|
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2020-08-01 10:30:12 +02:00
|
|
|
close_streamfile(sf);
|
2019-09-21 13:30:55 +02:00
|
|
|
close_vgmstream(infostream);
|
2017-05-01 10:56:40 +02:00
|
|
|
|
|
|
|
return true;
|
2014-08-10 21:33:01 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// thread safe (for Audacious <= 3.7, unused otherwise)
|
2020-08-01 10:30:12 +02:00
|
|
|
Tuple VgmstreamPlugin::read_tuple(const char * filename, VFSFile & file) {
|
2017-05-01 10:56:40 +02:00
|
|
|
Tuple tuple;
|
2019-10-06 23:31:32 +02:00
|
|
|
read_info(filename, tuple);
|
2017-05-01 10:56:40 +02:00
|
|
|
return tuple;
|
|
|
|
}
|
2014-08-10 21:33:01 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// thread safe (for Audacious >= 3.8, unused otherwise)
|
2017-05-01 10:56:40 +02:00
|
|
|
bool VgmstreamPlugin::read_tag(const char * filename, VFSFile & file, Tuple & tuple, Index<char> * image) {
|
2019-10-06 23:31:32 +02:00
|
|
|
return read_info(filename, tuple);
|
|
|
|
}
|
2014-08-10 21:33:01 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// internal util to seek during play
|
2020-08-01 10:30:12 +02:00
|
|
|
static void do_seek(VGMSTREAM* vgmstream, int seek_ms, int& current_sample_pos) {
|
2019-10-06 23:31:32 +02:00
|
|
|
AUDINFO("seeking\n");
|
|
|
|
|
|
|
|
// compute from ms to samples
|
2020-08-01 10:30:12 +02:00
|
|
|
int seek_sample = (long long)seek_ms * vgmstream->sample_rate / 1000L;
|
2019-10-06 23:31:32 +02:00
|
|
|
|
2020-08-01 10:30:12 +02:00
|
|
|
seek_vgmstream(vgmstream, seek_sample);
|
2019-10-06 23:31:32 +02:00
|
|
|
|
2020-08-01 10:30:12 +02:00
|
|
|
current_sample_pos = seek_sample;
|
2017-05-01 10:56:40 +02:00
|
|
|
}
|
2014-08-10 21:33:01 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// called on play (play thread)
|
2020-08-01 10:30:12 +02:00
|
|
|
bool VgmstreamPlugin::play(const char * filename, VFSFile & file) {
|
2019-10-06 23:31:32 +02:00
|
|
|
AUDINFO("play file=%s\n", filename);
|
2019-09-21 13:30:55 +02:00
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
//handle subsongs (see read_info)
|
|
|
|
char basename[PATH_LIMIT]; //filename without '?'
|
|
|
|
int subtune = 0;
|
|
|
|
int use_subtune = get_basename_subtune(filename, basename, sizeof(basename), &subtune);
|
|
|
|
|
|
|
|
STREAMFILE* sf = open_vfs(use_subtune ? basename : filename);
|
2020-08-01 10:30:12 +02:00
|
|
|
if (!sf) {
|
2019-10-06 23:31:32 +02:00
|
|
|
AUDERR("failed opening file %s\n", filename);
|
2017-05-01 10:56:40 +02:00
|
|
|
return false;
|
2014-08-10 21:33:01 +02:00
|
|
|
}
|
|
|
|
|
2020-09-12 15:03:22 +02:00
|
|
|
if (use_subtune)
|
|
|
|
sf->stream_index = subtune;
|
|
|
|
|
2020-08-01 12:24:54 +02:00
|
|
|
VGMSTREAM* vgmstream = init_vgmstream_from_STREAMFILE(sf);
|
2020-08-01 10:30:12 +02:00
|
|
|
close_streamfile(sf);
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
if (!vgmstream) {
|
|
|
|
AUDINFO("filename %s is not a valid format\n", filename);
|
|
|
|
close_vgmstream(vgmstream);
|
2017-05-01 10:56:40 +02:00
|
|
|
return false;
|
2014-08-10 21:33:01 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
int bitrate = get_vgmstream_average_bitrate(vgmstream);
|
|
|
|
set_stream_bitrate(bitrate);
|
|
|
|
|
|
|
|
//todo apply config
|
2014-08-10 21:33:01 +02:00
|
|
|
|
2020-08-01 10:30:12 +02:00
|
|
|
|
|
|
|
apply_config(vgmstream, &settings);
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
int input_channels = vgmstream->channels;
|
|
|
|
int output_channels = vgmstream->channels;
|
|
|
|
/* enable after all config but before outbuf */
|
|
|
|
vgmstream_mixing_autodownmix(vgmstream, settings.downmix_channels);
|
|
|
|
vgmstream_mixing_enable(vgmstream, MIN_BUFFER_SIZE, &input_channels, &output_channels);
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
//FMT_S8 / FMT_S16_NE / FMT_S24_NE / FMT_S32_NE / FMT_FLOAT
|
|
|
|
open_audio(FMT_S16_LE, vgmstream->sample_rate, output_channels);
|
|
|
|
|
|
|
|
// play
|
|
|
|
short buffer[MIN_BUFFER_SIZE * input_channels];
|
|
|
|
int max_buffer_samples = MIN_BUFFER_SIZE;
|
2020-08-01 10:30:12 +02:00
|
|
|
|
|
|
|
int play_forever = vgmstream_get_play_forever(vgmstream);
|
|
|
|
int length_samples = vgmstream_get_samples(vgmstream);
|
|
|
|
int decode_pos_samples = 0;
|
2017-05-01 10:56:40 +02:00
|
|
|
|
|
|
|
while (!check_stop()) {
|
2020-08-01 10:30:12 +02:00
|
|
|
int to_do = max_buffer_samples;
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// handle seek request
|
2017-05-01 10:56:40 +02:00
|
|
|
int seek_value = check_seek();
|
2020-08-01 10:30:12 +02:00
|
|
|
if (seek_value >= 0) {
|
|
|
|
do_seek(vgmstream, seek_value, decode_pos_samples);
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-01 10:56:40 +02:00
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
// check stream finished
|
2020-08-01 10:30:12 +02:00
|
|
|
if (!play_forever) {
|
|
|
|
if (decode_pos_samples >= length_samples)
|
2017-05-01 10:56:40 +02:00
|
|
|
break;
|
|
|
|
|
2020-08-01 10:30:12 +02:00
|
|
|
if (decode_pos_samples + to_do > length_samples)
|
|
|
|
to_do = length_samples - decode_pos_samples;
|
2017-05-01 10:56:40 +02:00
|
|
|
}
|
|
|
|
|
2020-08-01 10:30:12 +02:00
|
|
|
render_vgmstream(buffer, to_do, vgmstream);
|
|
|
|
|
|
|
|
write_audio(buffer, to_do * sizeof(short) * output_channels);
|
|
|
|
decode_pos_samples += to_do;
|
2017-05-01 10:56:40 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 23:31:32 +02:00
|
|
|
AUDINFO("play finished\n");
|
|
|
|
|
|
|
|
close_vgmstream(vgmstream);
|
2017-05-01 10:56:40 +02:00
|
|
|
return true;
|
2015-07-10 04:32:53 +02:00
|
|
|
}
|