mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-18 07:44:43 +01:00
Update Audacious plugin
- make extension list use formats.c and remove exts.cc - Audacious 3.8 preparations (untested) - cleanup
This commit is contained in:
parent
b37bdeff01
commit
825ebbdec9
@ -38,10 +38,10 @@ enum { PATH_LIMIT = 32768 };
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VGM_USE_G7221
|
#ifdef VGM_USE_G7221
|
||||||
#include "g7221.h"
|
#include <g7221.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef VGM_USE_G719
|
#ifdef VGM_USE_G719
|
||||||
#include "g719.h"
|
#include <g719.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VGM_USE_MP4V2
|
#ifdef VGM_USE_MP4V2
|
||||||
@ -54,7 +54,7 @@ enum { PATH_LIMIT = 32768 };
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VGM_USE_MAIATRAC3PLUS
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
||||||
#include "maiatrac3plus.h"
|
#include <maiatrac3plus.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VGM_USE_FFMPEG
|
#ifdef VGM_USE_FFMPEG
|
||||||
@ -62,10 +62,11 @@ enum { PATH_LIMIT = 32768 };
|
|||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <clHCA.h>
|
||||||
|
|
||||||
#include "coding/g72x_state.h"
|
#include "coding/g72x_state.h"
|
||||||
#include "coding/acm_decoder.h"
|
#include "coding/acm_decoder.h"
|
||||||
#include "coding/nwa_decoder.h"
|
#include "coding/nwa_decoder.h"
|
||||||
#include "clHCA.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* The encoding type specifies the format the sound data itself takes */
|
/* The encoding type specifies the format the sound data itself takes */
|
||||||
|
285
unix/exts.cc
285
unix/exts.cc
@ -1,285 +0,0 @@
|
|||||||
#include <cstdlib>
|
|
||||||
#include "plugin.h"
|
|
||||||
|
|
||||||
const char *const VgmStreamPlugin::exts[] =
|
|
||||||
{
|
|
||||||
"2dx9",
|
|
||||||
"2pfs",
|
|
||||||
|
|
||||||
"aax",
|
|
||||||
"acm",
|
|
||||||
"adm",
|
|
||||||
"adp",
|
|
||||||
"adpcm",
|
|
||||||
"ads",
|
|
||||||
"adx",
|
|
||||||
"afc",
|
|
||||||
"agsc",
|
|
||||||
"ahx",
|
|
||||||
"aifc",
|
|
||||||
"aix",
|
|
||||||
"amts",
|
|
||||||
"as4",
|
|
||||||
"asd",
|
|
||||||
"asf",
|
|
||||||
"asr",
|
|
||||||
"ass",
|
|
||||||
"ast",
|
|
||||||
"aud",
|
|
||||||
"aus",
|
|
||||||
|
|
||||||
"baka",
|
|
||||||
"baf",
|
|
||||||
"bar",
|
|
||||||
"bcstm",
|
|
||||||
"bcwav",
|
|
||||||
"bfwav",
|
|
||||||
"bfwavnsmbu",
|
|
||||||
"bg00",
|
|
||||||
"bgw",
|
|
||||||
"bh2pcm",
|
|
||||||
"bmdx",
|
|
||||||
"bms",
|
|
||||||
"bns",
|
|
||||||
"bnsf",
|
|
||||||
"bo2",
|
|
||||||
"brstm",
|
|
||||||
"brstmspm",
|
|
||||||
"btsnd",
|
|
||||||
"bvg",
|
|
||||||
|
|
||||||
"caf",
|
|
||||||
"capdsp",
|
|
||||||
"cbd2",
|
|
||||||
"ccc",
|
|
||||||
"cfn",
|
|
||||||
"ckd",
|
|
||||||
"cnk",
|
|
||||||
"cps",
|
|
||||||
|
|
||||||
"dcs",
|
|
||||||
"de2",
|
|
||||||
"ddsp",
|
|
||||||
"dmsg",
|
|
||||||
"dsp",
|
|
||||||
"dspw",
|
|
||||||
"dtk",
|
|
||||||
"dvi",
|
|
||||||
"dxh",
|
|
||||||
|
|
||||||
"eam",
|
|
||||||
"emff",
|
|
||||||
"enth",
|
|
||||||
|
|
||||||
"fag",
|
|
||||||
"filp",
|
|
||||||
"fsb",
|
|
||||||
"fwav",
|
|
||||||
|
|
||||||
"gbts",
|
|
||||||
"gca",
|
|
||||||
"gcm",
|
|
||||||
"gcub",
|
|
||||||
"gcw",
|
|
||||||
"genh",
|
|
||||||
"gms",
|
|
||||||
"gsb",
|
|
||||||
|
|
||||||
"hgc1",
|
|
||||||
"his",
|
|
||||||
"hlwav",
|
|
||||||
"hps",
|
|
||||||
"hsf",
|
|
||||||
"hwas",
|
|
||||||
|
|
||||||
"iab",
|
|
||||||
"idsp",
|
|
||||||
"idvi",
|
|
||||||
"ikm",
|
|
||||||
"ild",
|
|
||||||
"int",
|
|
||||||
"isd",
|
|
||||||
"ivaud",
|
|
||||||
"ivag",
|
|
||||||
"ivb",
|
|
||||||
|
|
||||||
"joe",
|
|
||||||
"jstm",
|
|
||||||
|
|
||||||
"kces",
|
|
||||||
"kcey",
|
|
||||||
"khv",
|
|
||||||
"klbs",
|
|
||||||
"kovs",
|
|
||||||
"kraw",
|
|
||||||
|
|
||||||
"leg",
|
|
||||||
"logg",
|
|
||||||
"lpcm",
|
|
||||||
"lps",
|
|
||||||
"lsf",
|
|
||||||
"lwav",
|
|
||||||
|
|
||||||
"matx",
|
|
||||||
"mca",
|
|
||||||
"mcg",
|
|
||||||
"mi4",
|
|
||||||
"mib",
|
|
||||||
"mic",
|
|
||||||
"mihb",
|
|
||||||
"mpdsp",
|
|
||||||
"mpds",
|
|
||||||
"msa",
|
|
||||||
"msf",
|
|
||||||
"mss",
|
|
||||||
"msvp",
|
|
||||||
"mtaf",
|
|
||||||
"mus",
|
|
||||||
"musc",
|
|
||||||
"musx",
|
|
||||||
"mwv",
|
|
||||||
"mxst",
|
|
||||||
"myspd",
|
|
||||||
|
|
||||||
"ndp",
|
|
||||||
"ngca",
|
|
||||||
"npsf",
|
|
||||||
"nus3bank",
|
|
||||||
"nwa",
|
|
||||||
|
|
||||||
"omu",
|
|
||||||
"otm",
|
|
||||||
|
|
||||||
"p2bt",
|
|
||||||
"p3d",
|
|
||||||
"past",
|
|
||||||
"pcm",
|
|
||||||
"pdt",
|
|
||||||
"pnb",
|
|
||||||
"pos",
|
|
||||||
"ps2stm",
|
|
||||||
"psh",
|
|
||||||
"psnd",
|
|
||||||
"psw",
|
|
||||||
|
|
||||||
"ras",
|
|
||||||
"raw",
|
|
||||||
"rkv",
|
|
||||||
"rnd",
|
|
||||||
"rrds",
|
|
||||||
"rsd",
|
|
||||||
"rsf",
|
|
||||||
"rstm",
|
|
||||||
"rvws",
|
|
||||||
"rwar",
|
|
||||||
"rwav",
|
|
||||||
"rws",
|
|
||||||
"rwsd",
|
|
||||||
"rwx",
|
|
||||||
"rxw",
|
|
||||||
|
|
||||||
"s14",
|
|
||||||
"sab",
|
|
||||||
"sad",
|
|
||||||
"sap",
|
|
||||||
"sc",
|
|
||||||
"scd",
|
|
||||||
"sck",
|
|
||||||
"sd9",
|
|
||||||
"sdt",
|
|
||||||
"seg",
|
|
||||||
"sf0",
|
|
||||||
"sfl",
|
|
||||||
"sfs",
|
|
||||||
"sfx",
|
|
||||||
"sgb",
|
|
||||||
"sgd",
|
|
||||||
"sgx",
|
|
||||||
"sl3",
|
|
||||||
"sli",
|
|
||||||
"smp",
|
|
||||||
"smpl",
|
|
||||||
"snd",
|
|
||||||
"snds",
|
|
||||||
"sng",
|
|
||||||
"sns",
|
|
||||||
"spd",
|
|
||||||
"spm",
|
|
||||||
"sps",
|
|
||||||
"spsd",
|
|
||||||
"spw",
|
|
||||||
"ss2",
|
|
||||||
"ss3",
|
|
||||||
"ss7",
|
|
||||||
"ssm",
|
|
||||||
"sss",
|
|
||||||
"ster",
|
|
||||||
"stma",
|
|
||||||
"str",
|
|
||||||
"strm",
|
|
||||||
"sts",
|
|
||||||
"stx",
|
|
||||||
"svag",
|
|
||||||
"svs",
|
|
||||||
"swav",
|
|
||||||
"swd",
|
|
||||||
|
|
||||||
"tec",
|
|
||||||
"thp",
|
|
||||||
"tk1",
|
|
||||||
"tk5",
|
|
||||||
"tra",
|
|
||||||
"tun",
|
|
||||||
"tydsp",
|
|
||||||
|
|
||||||
"um3",
|
|
||||||
|
|
||||||
"vag",
|
|
||||||
"vas",
|
|
||||||
"vawx",
|
|
||||||
"vb",
|
|
||||||
"vbk",
|
|
||||||
"vgs",
|
|
||||||
"vgv",
|
|
||||||
"vig",
|
|
||||||
"vms",
|
|
||||||
"voi",
|
|
||||||
"vpk",
|
|
||||||
"vs",
|
|
||||||
"vsf",
|
|
||||||
|
|
||||||
"waa",
|
|
||||||
"wac",
|
|
||||||
"wad",
|
|
||||||
"wam",
|
|
||||||
"wavm",
|
|
||||||
"wb",
|
|
||||||
"wii",
|
|
||||||
"wmus",
|
|
||||||
"wp2",
|
|
||||||
"wpd",
|
|
||||||
"wsd",
|
|
||||||
"wsi",
|
|
||||||
"wvs",
|
|
||||||
|
|
||||||
"xa",
|
|
||||||
"xa2",
|
|
||||||
"xa30",
|
|
||||||
"xau",
|
|
||||||
"xmu",
|
|
||||||
"xnb",
|
|
||||||
"xsf",
|
|
||||||
"xss",
|
|
||||||
"xvag",
|
|
||||||
"xvas",
|
|
||||||
"xwav",
|
|
||||||
"xwb",
|
|
||||||
|
|
||||||
"ydsp",
|
|
||||||
"ymf",
|
|
||||||
|
|
||||||
"zsd",
|
|
||||||
"zwdsp",
|
|
||||||
/* terminator */
|
|
||||||
NULL
|
|
||||||
};
|
|
407
unix/plugin.cc
407
unix/plugin.cc
@ -1,235 +1,288 @@
|
|||||||
|
/**
|
||||||
|
* vgmstream for Audacious
|
||||||
|
*/
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <libaudcore/audio.h>
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#include "../src/formats.h"
|
||||||
#include "../src/vgmstream.h"
|
#include "../src/vgmstream.h"
|
||||||
}
|
}
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "vfs.h"
|
#include "vfs.h"
|
||||||
|
|
||||||
#include <libaudcore/audio.h>
|
|
||||||
|
|
||||||
VgmStreamPlugin aud_plugin_instance;
|
#define VERSION "1.3.0"
|
||||||
|
#define CFG_ID "vgmstream" // ID for storing in audacious
|
||||||
|
#define MIN_BUFFER_SIZE 576
|
||||||
|
|
||||||
|
/* internal state */
|
||||||
|
VgmstreamPlugin aud_plugin_instance;
|
||||||
Settings vgmstream_cfg;
|
Settings vgmstream_cfg;
|
||||||
VGMSTREAM *vgmstream = NULL;
|
VGMSTREAM *vgmstream = NULL;
|
||||||
#define CFG_ID "vgmstream" // ID for storing in audacious
|
|
||||||
|
|
||||||
const char *const VgmStreamPlugin::defaults[] = {
|
|
||||||
"loop_forever", "1", "loop_count", "2", "fade_length",
|
|
||||||
"3", "fade_delay", "3", NULL};
|
|
||||||
|
|
||||||
const char VgmStreamPlugin::about[] =
|
const char *const VgmstreamPlugin::defaults[] = {
|
||||||
"audacious-vgmstream version: " AUDACIOUSVGMSTREAM_VERSION "\n\n"
|
"loop_forever", "1",
|
||||||
"ported to audacious 3.6 by Brandon Whitehead\n"
|
"loop_count", "2",
|
||||||
"adopted from audacious 3 port by Thomas Eppers\n"
|
"fade_length", "3",
|
||||||
|
"fade_delay", "3",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
const char VgmstreamPlugin::about[] =
|
||||||
|
"vgmstream for Audacious version: " VERSION "\n"
|
||||||
|
"\n"
|
||||||
|
"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"
|
"originally written by Todd Jeffreys (http://voidpointer.org/)\n"
|
||||||
"vgmstream written by hcs, FastElbja, manakoAT, and bxaimc "
|
"vgmstream written by hcs, FastElbja, manakoAT, and bxaimc\n"
|
||||||
"(http://www.sf.net/projects/vgmstream)";
|
"http://www.sf.net/projects/vgmstream";
|
||||||
|
|
||||||
const PreferencesWidget VgmStreamPlugin::widgets[] = {
|
const PreferencesWidget VgmstreamPlugin::widgets[] = {
|
||||||
WidgetLabel(N_("<b>VGMStream Config</b>")),
|
WidgetLabel(N_("<b>vgmstream Config</b>")),
|
||||||
WidgetCheck(N_("Loop Forever:"), WidgetBool(vgmstream_cfg.loop_forever)),
|
WidgetCheck(N_("Loop Forever:"), WidgetBool(vgmstream_cfg.loop_forever)),
|
||||||
WidgetSpin(N_("Loop Count:"), WidgetInt(vgmstream_cfg.loop_count),
|
WidgetSpin(N_("Loop Count:"), WidgetInt(vgmstream_cfg.loop_count), {1, 20, 1}),
|
||||||
{1, 20, 1}),
|
WidgetSpin(N_("Fade Length:"), WidgetFloat(vgmstream_cfg.fade_length), {0, 60, 0.1}),
|
||||||
WidgetSpin(N_("Fade Length:"), WidgetFloat(vgmstream_cfg.fade_length),
|
WidgetSpin(N_("Fade Delay:"), WidgetFloat(vgmstream_cfg.fade_delay), {0, 60, 0.1}),
|
||||||
{0, 60, 0.1}),
|
|
||||||
WidgetSpin(N_("Fade Delay:"), WidgetFloat(vgmstream_cfg.fade_delay),
|
|
||||||
{0, 60, 0.1}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void vgmstream_cfg_load() {
|
void vgmstream_cfg_load() {
|
||||||
debugMessage("cfg_load called");
|
debugMessage("cfg_load called");
|
||||||
aud_config_set_defaults(CFG_ID, VgmStreamPlugin::defaults);
|
aud_config_set_defaults(CFG_ID, VgmstreamPlugin::defaults);
|
||||||
vgmstream_cfg.loop_forever = aud_get_bool(CFG_ID, "loop_forever");
|
vgmstream_cfg.loop_forever = aud_get_bool(CFG_ID, "loop_forever");
|
||||||
vgmstream_cfg.loop_count = aud_get_int(CFG_ID, "loop_count");
|
vgmstream_cfg.loop_count = aud_get_int(CFG_ID, "loop_count");
|
||||||
vgmstream_cfg.fade_length = aud_get_double(CFG_ID, "fade_length");
|
vgmstream_cfg.fade_length = aud_get_double(CFG_ID, "fade_length");
|
||||||
vgmstream_cfg.fade_delay = aud_get_double(CFG_ID, "fade_delay");
|
vgmstream_cfg.fade_delay = aud_get_double(CFG_ID, "fade_delay");
|
||||||
}
|
}
|
||||||
|
|
||||||
void vgmstream_cfg_save() {
|
void vgmstream_cfg_save() {
|
||||||
debugMessage("cfg_save called");
|
debugMessage("cfg_save called");
|
||||||
aud_set_bool(CFG_ID, "loop_forever", vgmstream_cfg.loop_forever);
|
aud_set_bool(CFG_ID, "loop_forever", vgmstream_cfg.loop_forever);
|
||||||
aud_set_int(CFG_ID, "loop_count", vgmstream_cfg.loop_count);
|
aud_set_int(CFG_ID, "loop_count", vgmstream_cfg.loop_count);
|
||||||
aud_set_double(CFG_ID, "fade_length", vgmstream_cfg.fade_length);
|
aud_set_double(CFG_ID, "fade_length", vgmstream_cfg.fade_length);
|
||||||
aud_set_double(CFG_ID, "fade_delay", vgmstream_cfg.fade_delay);
|
aud_set_double(CFG_ID, "fade_delay", vgmstream_cfg.fade_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
const PluginPreferences VgmStreamPlugin::prefs = {
|
const PluginPreferences VgmstreamPlugin::prefs = {
|
||||||
{widgets}, vgmstream_cfg_load, vgmstream_cfg_save};
|
{widgets}, vgmstream_cfg_load, vgmstream_cfg_save
|
||||||
|
};
|
||||||
|
|
||||||
bool VgmStreamPlugin::init() {
|
// validate extension
|
||||||
debugMessage("init");
|
bool VgmstreamPlugin::is_our_file(const char *filename, VFSFile &file) {
|
||||||
vgmstream_cfg_load();
|
const char * ext = strrchr(filename,'.');
|
||||||
debugMessage("after load cfg");
|
if (ext==NULL)
|
||||||
return true;
|
ext = filename+strlen(filename); /* point to null, i.e. an empty string for the extension */
|
||||||
|
else
|
||||||
|
ext = ext+1; /* skip the dot */
|
||||||
|
|
||||||
|
const char ** ext_list = vgmstream_get_formats();
|
||||||
|
int ext_list_len = vgmstream_get_formats_length();
|
||||||
|
|
||||||
|
for (int i=0; i < ext_list_len; i++) {
|
||||||
|
if (!strcasecmp(ext, ext_list[i]))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VgmStreamPlugin::cleanup() {
|
bool VgmstreamPlugin::init() {
|
||||||
debugMessage("cleanup");
|
debugMessage("init");
|
||||||
vgmstream_cfg_save();
|
|
||||||
|
vgmstream_cfg_load();
|
||||||
|
|
||||||
|
debugMessage("after load cfg");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VgmstreamPlugin::cleanup() {
|
||||||
|
debugMessage("cleanup");
|
||||||
|
|
||||||
|
vgmstream_cfg_save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// called every time the user adds a new file to playlist
|
// called every time the user adds a new file to playlist
|
||||||
Tuple VgmStreamPlugin::read_tuple(const char *filename, VFSFile &file) {
|
bool read_data(const char * filename, Tuple & tuple) {
|
||||||
debugMessage("probe for tuple");
|
|
||||||
Tuple tuple;
|
|
||||||
int ms;
|
|
||||||
int rate;
|
|
||||||
VGMSTREAM *vgmstream = NULL;
|
|
||||||
STREAMFILE *streamfile = NULL;
|
|
||||||
|
|
||||||
streamfile = open_vfs(filename);
|
STREAMFILE *streamfile = open_vfs(filename);
|
||||||
vgmstream = init_vgmstream_from_STREAMFILE(streamfile);
|
if (!streamfile) return false;
|
||||||
|
|
||||||
tuple.set_filename(filename);
|
VGMSTREAM *vgmstream = init_vgmstream_from_STREAMFILE(streamfile);
|
||||||
rate = vgmstream->sample_rate * 2 * vgmstream->channels;
|
if (!vgmstream) {
|
||||||
tuple.set_int(Tuple::Bitrate, rate);
|
close_streamfile(streamfile);
|
||||||
|
return false;
|
||||||
ms = get_vgmstream_play_samples(vgmstream_cfg.loop_count,
|
|
||||||
vgmstream_cfg.fade_length,
|
|
||||||
vgmstream_cfg.fade_delay, vgmstream) *
|
|
||||||
1000LL / vgmstream->sample_rate;
|
|
||||||
tuple.set_int(Tuple::Length, ms);
|
|
||||||
|
|
||||||
close_streamfile(streamfile);
|
|
||||||
close_vgmstream(vgmstream);
|
|
||||||
|
|
||||||
return tuple;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VgmStreamPlugin::play(const char *filename, VFSFile &file) {
|
|
||||||
int current_sample_pos = 0;
|
|
||||||
int rate;
|
|
||||||
|
|
||||||
debugMessage("start play");
|
|
||||||
STREAMFILE *streamfile = open_vfs(filename);
|
|
||||||
|
|
||||||
if (!streamfile) {
|
|
||||||
printf("failed opening %s\n", filename);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vgmstream = init_vgmstream_from_STREAMFILE(streamfile);
|
|
||||||
close_streamfile(streamfile);
|
|
||||||
|
|
||||||
if (!vgmstream || vgmstream->channels <= 0) {
|
|
||||||
printf("Error::Channels are zero or couldn't init plugin\n");
|
|
||||||
if (vgmstream)
|
|
||||||
close_vgmstream(vgmstream);
|
|
||||||
vgmstream = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
short buffer[576 * vgmstream->channels];
|
|
||||||
int max_buffer_samples =
|
|
||||||
sizeof(buffer) / sizeof(buffer[0]) / vgmstream->channels;
|
|
||||||
|
|
||||||
int stream_samples_amount = get_vgmstream_play_samples(
|
|
||||||
vgmstream_cfg.loop_count, vgmstream_cfg.fade_length,
|
|
||||||
vgmstream_cfg.fade_delay, vgmstream);
|
|
||||||
rate = get_vgmstream_average_bitrate(vgmstream);
|
|
||||||
|
|
||||||
set_stream_bitrate(rate);
|
|
||||||
open_audio(FMT_S16_LE, vgmstream->sample_rate, 2);
|
|
||||||
|
|
||||||
int fade_samples = vgmstream_cfg.fade_length * vgmstream->sample_rate;
|
|
||||||
while (!check_stop()) {
|
|
||||||
int toget = max_buffer_samples;
|
|
||||||
|
|
||||||
int seek_value = check_seek();
|
|
||||||
if (seek_value > 0)
|
|
||||||
seek(seek_value, current_sample_pos);
|
|
||||||
|
|
||||||
// If we haven't configured the plugin to play forever
|
|
||||||
// or the current song is not loopable.
|
|
||||||
if (!vgmstream_cfg.loop_forever || !vgmstream->loop_flag) {
|
|
||||||
if (current_sample_pos >= stream_samples_amount)
|
|
||||||
break;
|
|
||||||
if (current_sample_pos + toget > stream_samples_amount)
|
|
||||||
toget = stream_samples_amount - current_sample_pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render_vgmstream(buffer, toget, vgmstream);
|
tuple.set_filename(filename);
|
||||||
|
int rate = get_vgmstream_average_bitrate(vgmstream);
|
||||||
|
tuple.set_int(Tuple::Bitrate, rate);
|
||||||
|
|
||||||
if (vgmstream->loop_flag && fade_samples > 0 &&
|
int ms = get_vgmstream_play_samples(vgmstream_cfg.loop_count, vgmstream_cfg.fade_length, vgmstream_cfg.fade_delay, vgmstream);
|
||||||
!vgmstream_cfg.loop_forever) {
|
ms = ms* 1000LL / vgmstream->sample_rate;
|
||||||
int samples_into_fade =
|
tuple.set_int(Tuple::Length, ms);
|
||||||
current_sample_pos - (stream_samples_amount - fade_samples);
|
|
||||||
if (samples_into_fade + toget > 0) {
|
|
||||||
for (int j = 0; j < toget; j++, samples_into_fade++) {
|
|
||||||
if (samples_into_fade > 0) {
|
|
||||||
double fadedness =
|
|
||||||
(double)(fade_samples - samples_into_fade) / fade_samples;
|
|
||||||
for (int k = 0; k < vgmstream->channels; k++)
|
|
||||||
buffer[j * vgmstream->channels + k] *= fadedness;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
write_audio(buffer, toget * sizeof(short) * vgmstream->channels);
|
tuple.set_str(Tuple::Codec, "vgmstream codec");//doesn't show?
|
||||||
current_sample_pos += toget;
|
// here we could call describe_vgmstream() and get substring to add tags and stuff
|
||||||
}
|
|
||||||
|
|
||||||
debugMessage("finished");
|
close_streamfile(streamfile);
|
||||||
if (vgmstream)
|
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
vgmstream = NULL;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VgmStreamPlugin::seek(int seek_value, int ¤t_sample_pos) {
|
//for Audacious <= 3.7 (unused otherwise)
|
||||||
debugMessage("seeking");
|
Tuple VgmstreamPlugin::read_tuple(const char *filename, VFSFile &file) {
|
||||||
// compute from ms to samples
|
debugMessage("read_tuple");
|
||||||
int seek_needed_samples =
|
|
||||||
(long long)seek_value * vgmstream->sample_rate / 1000L;
|
|
||||||
short buffer[576 * vgmstream->channels];
|
|
||||||
int max_buffer_samples =
|
|
||||||
sizeof(buffer) / sizeof(buffer[0]) / vgmstream->channels;
|
|
||||||
|
|
||||||
int samples_to_do = 0;
|
Tuple tuple;
|
||||||
if (seek_needed_samples < current_sample_pos) {
|
read_data(filename, tuple);
|
||||||
// go back in time, reopen file
|
return tuple;
|
||||||
debugMessage("reopen file to seek backward");
|
}
|
||||||
reset_vgmstream(vgmstream);
|
|
||||||
current_sample_pos = 0;
|
|
||||||
samples_to_do = seek_needed_samples;
|
|
||||||
} else if (current_sample_pos < seek_needed_samples) {
|
|
||||||
// go forward in time
|
|
||||||
samples_to_do = seek_needed_samples - current_sample_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// do the actual seeking
|
//for Audacious >= 3.8 (unused otherwise)
|
||||||
if (samples_to_do >= 0) {
|
bool VgmstreamPlugin::read_tag(const char * filename, VFSFile & file, Tuple & tuple, Index<char> * image) {
|
||||||
debugMessage("render forward");
|
debugMessage("read_tag");
|
||||||
|
|
||||||
// render till seeked sample
|
return read_data(filename, tuple);
|
||||||
while (samples_to_do > 0) {
|
}
|
||||||
int seek_samples = std::min(max_buffer_samples, samples_to_do);
|
|
||||||
current_sample_pos += seek_samples;
|
bool VgmstreamPlugin::play(const char *filename, VFSFile &file) {
|
||||||
samples_to_do -= seek_samples;
|
debugMessage("start play");
|
||||||
render_vgmstream(buffer, seek_samples, vgmstream);
|
|
||||||
|
int current_sample_pos = 0;
|
||||||
|
int rate;
|
||||||
|
|
||||||
|
STREAMFILE *streamfile = open_vfs(filename);
|
||||||
|
if (!streamfile) {
|
||||||
|
printf("failed opening %s\n", filename);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
vgmstream = init_vgmstream_from_STREAMFILE(streamfile);
|
||||||
|
close_streamfile(streamfile);
|
||||||
|
|
||||||
|
if (!vgmstream || vgmstream->channels <= 0) {
|
||||||
|
printf("Error::Channels are zero or couldn't init plugin\n");
|
||||||
|
if (vgmstream)
|
||||||
|
close_vgmstream(vgmstream);
|
||||||
|
vgmstream = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
short buffer[MIN_BUFFER_SIZE * vgmstream->channels];
|
||||||
|
int max_buffer_samples = sizeof(buffer) / sizeof(buffer[0]) / vgmstream->channels;
|
||||||
|
|
||||||
|
int stream_samples_amount = get_vgmstream_play_samples(
|
||||||
|
vgmstream_cfg.loop_count, vgmstream_cfg.fade_length,
|
||||||
|
vgmstream_cfg.fade_delay, vgmstream);
|
||||||
|
rate = get_vgmstream_average_bitrate(vgmstream);
|
||||||
|
|
||||||
|
set_stream_bitrate(rate);
|
||||||
|
open_audio(FMT_S16_LE, vgmstream->sample_rate, 2);
|
||||||
|
|
||||||
|
int fade_samples = vgmstream_cfg.fade_length * vgmstream->sample_rate;
|
||||||
|
while (!check_stop()) {
|
||||||
|
int toget = max_buffer_samples;
|
||||||
|
|
||||||
|
int seek_value = check_seek();
|
||||||
|
if (seek_value > 0)
|
||||||
|
seek(seek_value, current_sample_pos);
|
||||||
|
|
||||||
|
// If we haven't configured the plugin to play forever
|
||||||
|
// or the current song is not loopable.
|
||||||
|
if (!vgmstream_cfg.loop_forever || !vgmstream->loop_flag) {
|
||||||
|
if (current_sample_pos >= stream_samples_amount)
|
||||||
|
break;
|
||||||
|
if (current_sample_pos + toget > stream_samples_amount)
|
||||||
|
toget = stream_samples_amount - current_sample_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
render_vgmstream(buffer, toget, vgmstream);
|
||||||
|
|
||||||
|
if (vgmstream->loop_flag && fade_samples > 0 &&
|
||||||
|
!vgmstream_cfg.loop_forever) {
|
||||||
|
int samples_into_fade =
|
||||||
|
current_sample_pos - (stream_samples_amount - fade_samples);
|
||||||
|
if (samples_into_fade + toget > 0) {
|
||||||
|
for (int j = 0; j < toget; j++, samples_into_fade++) {
|
||||||
|
if (samples_into_fade > 0) {
|
||||||
|
double fadedness =
|
||||||
|
(double)(fade_samples - samples_into_fade) / fade_samples;
|
||||||
|
for (int k = 0; k < vgmstream->channels; k++)
|
||||||
|
buffer[j * vgmstream->channels + k] *= fadedness;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
write_audio(buffer, toget * sizeof(short) * vgmstream->channels);
|
||||||
|
current_sample_pos += toget;
|
||||||
|
}
|
||||||
|
|
||||||
|
debugMessage("finished");
|
||||||
|
if (vgmstream)
|
||||||
|
close_vgmstream(vgmstream);
|
||||||
|
vgmstream = NULL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VgmstreamPlugin::seek(int seek_value, int ¤t_sample_pos) {
|
||||||
|
debugMessage("seeking");
|
||||||
|
|
||||||
|
// compute from ms to samples
|
||||||
|
int seek_needed_samples = (long long)seek_value * vgmstream->sample_rate / 1000L;
|
||||||
|
short buffer[MIN_BUFFER_SIZE * vgmstream->channels];
|
||||||
|
int max_buffer_samples = sizeof(buffer) / sizeof(buffer[0]) / vgmstream->channels;
|
||||||
|
|
||||||
|
int samples_to_do = 0;
|
||||||
|
if (seek_needed_samples < current_sample_pos) {
|
||||||
|
// go back in time, reopen file
|
||||||
|
debugMessage("reopen file to seek backward");
|
||||||
|
reset_vgmstream(vgmstream);
|
||||||
|
current_sample_pos = 0;
|
||||||
|
samples_to_do = seek_needed_samples;
|
||||||
|
} else if (current_sample_pos < seek_needed_samples) {
|
||||||
|
// go forward in time
|
||||||
|
samples_to_do = seek_needed_samples - current_sample_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
// do the actual seeking
|
||||||
|
if (samples_to_do >= 0) {
|
||||||
|
debugMessage("render forward");
|
||||||
|
|
||||||
|
// render till seeked sample
|
||||||
|
while (samples_to_do > 0) {
|
||||||
|
int seek_samples = std::min(max_buffer_samples, samples_to_do);
|
||||||
|
current_sample_pos += seek_samples;
|
||||||
|
samples_to_do -= seek_samples;
|
||||||
|
render_vgmstream(buffer, seek_samples, vgmstream);
|
||||||
|
}
|
||||||
|
debugMessage("after render vgmstream");
|
||||||
}
|
}
|
||||||
debugMessage("after render vgmstream");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void debugMessage(const char *str) {
|
void debugMessage(const char *str) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
timeval curTime;
|
timeval curTime;
|
||||||
gettimeofday(&curTime, NULL);
|
gettimeofday(&curTime, NULL);
|
||||||
int milli = curTime.tv_usec / 1000;
|
int milli = curTime.tv_usec / 1000;
|
||||||
|
|
||||||
char buffer[80];
|
char buffer[80];
|
||||||
strftime(buffer, 80, "%H:%M:%S", localtime(&curTime.tv_sec));
|
strftime(buffer, 80, "%H:%M:%S", localtime(&curTime.tv_sec));
|
||||||
|
|
||||||
char currentTime[84] = "";
|
char currentTime[84] = "";
|
||||||
sprintf(currentTime, "%s:%d", buffer, milli);
|
sprintf(currentTime, "%s:%d", buffer, milli);
|
||||||
printf("[%s] Debug: %s\n", currentTime, str);
|
printf("[%s] Debug: %s\n", currentTime, str);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -7,37 +7,46 @@
|
|||||||
#include <libaudcore/preferences.h>
|
#include <libaudcore/preferences.h>
|
||||||
#include <libaudcore/runtime.h>
|
#include <libaudcore/runtime.h>
|
||||||
|
|
||||||
class VgmStreamPlugin : public InputPlugin {
|
class VgmstreamPlugin : public InputPlugin {
|
||||||
public:
|
public:
|
||||||
static const char *const exts[];
|
//static const char *const exts[];
|
||||||
static const char *const defaults[];
|
static const char *const defaults[];
|
||||||
static const char about[];
|
static const char about[];
|
||||||
static const PreferencesWidget widgets[];
|
static const PreferencesWidget widgets[];
|
||||||
static const PluginPreferences prefs;
|
static const PluginPreferences prefs;
|
||||||
|
|
||||||
static constexpr PluginInfo info = {
|
static constexpr PluginInfo info = {
|
||||||
N_("VGMStream Decoder"), N_("vgmstream"), about, &prefs,
|
N_("vgmstream Decoder"), N_("vgmstream"), about, &prefs,
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr auto iinfo = InputInfo().with_exts(exts);
|
// accepted exts are validated at runtime in is_our_file now, this is to set a static list
|
||||||
|
//static constexpr auto iinfo = InputInfo().with_exts(exts);
|
||||||
|
//constexpr VgmstreamPlugin() : InputPlugin(info, iinfo) {}
|
||||||
|
//constexpr VgmstreamPlugin() : InputPlugin (info, InputInfo().with_exts(exts)) {}
|
||||||
|
|
||||||
constexpr VgmStreamPlugin() : InputPlugin(info, iinfo) {}
|
constexpr VgmstreamPlugin() : InputPlugin (info, NULL) {}
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
bool is_our_file(const char *filename, VFSFile &file) { return false; }
|
bool is_our_file(const char *filename, VFSFile &file);
|
||||||
Tuple read_tuple(const char *filename, VFSFile &file);
|
Tuple read_tuple(const char *filename, VFSFile &file);
|
||||||
bool play(const char *filename, VFSFile &file);
|
bool read_tag(const char * filename, VFSFile & file, Tuple & tuple, Index<char> * image);
|
||||||
|
bool play(const char *filename, VFSFile &file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void seek(int seek_value, int ¤t_sample_pos);
|
void seek(int seek_value, int ¤t_sample_pos);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// reminder of usage, probably no more need
|
||||||
|
//const char *const VgmstreamPlugin::exts[] = { "ext1", "ext2", ..., NULL }
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool loop_forever;
|
bool loop_forever;
|
||||||
int loop_count;
|
int loop_count;
|
||||||
double fade_length;
|
double fade_length;
|
||||||
double fade_delay;
|
double fade_delay;
|
||||||
} Settings;
|
} Settings;
|
||||||
|
|
||||||
extern Settings vgmstream_cfg;
|
extern Settings vgmstream_cfg;
|
||||||
@ -46,6 +55,4 @@ void debugMessage(const char *str);
|
|||||||
void vgmstream_cfg_load();
|
void vgmstream_cfg_load();
|
||||||
void vgmstream_cfg_save();
|
void vgmstream_cfg_save();
|
||||||
|
|
||||||
#define AUDACIOUSVGMSTREAM_VERSION "1.2.0"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user