diff --git a/src/plugins/gmedecoder/Constants.h b/src/plugins/gmedecoder/Constants.h index aaa58947c..1c80c9229 100644 --- a/src/plugins/gmedecoder/Constants.h +++ b/src/plugins/gmedecoder/Constants.h @@ -39,6 +39,9 @@ #include #include #include +#include +#include +#include #ifdef WIN32 #define DLLEXPORT __declspec(dllexport) @@ -83,4 +86,24 @@ static inline bool parseExternalId(const std::string& externalId, std::string& f static inline std::string createExternalId(const std::string& fn, int track) { return "gme://" + std::to_string(track) + "/" + fn; -} \ No newline at end of file +} + +static std::string getM3uFor(const std::string& fn) { + size_t lastDot = fn.find_last_of("."); + if (lastDot != std::string::npos) { + std::string m3u = fn.substr(0, lastDot) + ".m3u"; + if (access(m3u.c_str(), R_OK) != -1) { + return m3u; + } + } + return ""; +} + +static bool exists(const std::string& externalId) { + std::string fn; + int trackNum; + if (!parseExternalId(externalId, fn, trackNum)) { + return false; + } + return access(fn.c_str(), R_OK) != -1; +} diff --git a/src/plugins/gmedecoder/GmeDataStream.cpp b/src/plugins/gmedecoder/GmeDataStream.cpp index dd796a8f6..87e1b9804 100644 --- a/src/plugins/gmedecoder/GmeDataStream.cpp +++ b/src/plugins/gmedecoder/GmeDataStream.cpp @@ -41,10 +41,9 @@ using namespace musik::core::sdk; extern IEnvironment* environment; bool GmeDataStream::Open(const char *uri, unsigned int options) { - std::string fn; - if (parseExternalId(uri, fn, this->trackNumber)) { + if (parseExternalId(uri, this->filename, this->trackNumber)) { if (environment) { - this->stream = environment->GetDataStream(fn.c_str()); + this->stream = environment->GetDataStream(this->filename.c_str()); if (this->stream) { return true; } diff --git a/src/plugins/gmedecoder/GmeDataStream.h b/src/plugins/gmedecoder/GmeDataStream.h index 3152fc5d8..9a3b17891 100644 --- a/src/plugins/gmedecoder/GmeDataStream.h +++ b/src/plugins/gmedecoder/GmeDataStream.h @@ -56,8 +56,10 @@ class GmeDataStream: public musik::core::sdk::IDataStream { virtual bool CanPrefetch() override; int GetTrackNumber() { return this->trackNumber; } + std::string GetFilename() { return this->filename; } private: int trackNumber { 0 }; + std::string filename; musik::core::sdk::IDataStream* stream { nullptr }; }; \ No newline at end of file diff --git a/src/plugins/gmedecoder/GmeDecoder.cpp b/src/plugins/gmedecoder/GmeDecoder.cpp index edb95fe31..cb0c4770a 100644 --- a/src/plugins/gmedecoder/GmeDecoder.cpp +++ b/src/plugins/gmedecoder/GmeDecoder.cpp @@ -39,8 +39,9 @@ static const int BUFFER_SAMPLE_COUNT = 2048; static const int CHANNELS = 2; static const int SAMPLE_RATE = 44100; -static const int SAMPLES_PER_MS = SAMPLE_RATE / 1000; -static const int FADE_LENGTH_MS = 2000; +static const int SAMPLES_PER_MS = (SAMPLE_RATE * CHANNELS) / 1000; +static const int FADE_LENGTH_MS = 2500; +static const int MAXIMUM_DURATION_MS = 150000; /* 2.5 mins */ static const float F_SHRT_MAX = (float) SHRT_MAX; GmeDecoder::GmeDecoder() { @@ -64,6 +65,11 @@ bool GmeDecoder::Open(musik::core::sdk::IDataStream *stream) { if (!gme_open_data(data, length, &this->gme, SAMPLE_RATE)) { int trackNum = this->stream->GetTrackNumber(); + std::string m3u = getM3uFor(this->stream->GetFilename()); + if (m3u.size()) { + gme_load_m3u(this->gme, m3u.c_str()); + } + bool error = !!gme_track_info(this->gme, &this->info, trackNum) || !!gme_start_track(this->gme, trackNum); @@ -75,7 +81,7 @@ bool GmeDecoder::Open(musik::core::sdk::IDataStream *stream) { this->info = nullptr; } else { - gme_set_fade(this->gme, this->info->play_length - FADE_LENGTH_MS, FADE_LENGTH_MS); + gme_set_fade(this->gme, MAXIMUM_DURATION_MS - FADE_LENGTH_MS, FADE_LENGTH_MS); } } } diff --git a/src/plugins/gmedecoder/GmeIndexerSource.cpp b/src/plugins/gmedecoder/GmeIndexerSource.cpp index 064d64463..5aa0a49e9 100644 --- a/src/plugins/gmedecoder/GmeIndexerSource.cpp +++ b/src/plugins/gmedecoder/GmeIndexerSource.cpp @@ -39,50 +39,27 @@ #include #include #include -#include -#include -#include using namespace musik::core::sdk; -static std::string getM3uFor(const std::string& fn) { - size_t lastDot = fn.find_last_of("."); - if (lastDot != std::string::npos) { - std::string m3u = fn.substr(0, lastDot) + ".m3u"; - if (access(m3u.c_str(), R_OK) != -1) { - return m3u; - } - } - return ""; -} - -static bool exists(const std::string& externalId) { - std::string fn; - int trackNum; - if (!parseExternalId(externalId, fn, trackNum)) { - return false; - } - return access(fn.c_str(), R_OK) != -1; -} - static void updateMetadata( const std::string& fn, IIndexerSource* source, IIndexerWriter* indexer) { gme_t* data = nullptr; - gme_err_t err = gme_open_file(fn.c_str(), &data, 44100); + gme_err_t err = gme_open_file(fn.c_str(), &data, gme_info_only); if (err) { std::cerr << "error opening file: " << err << "\n"; } else { - // std::string m3u = getM3uFor(fn); - // if (m3u.size()) { - // err = gme_load_m3u(data, m3u.c_str()); - // if (err) { - // std::cerr << "m3u found, but load failed: " << err << "\n"; - // } - // } + std::string m3u = getM3uFor(fn); + if (m3u.size()) { + err = gme_load_m3u(data, m3u.c_str()); + if (err) { + std::cerr << "m3u found, but load failed: " << err << "\n"; + } + } for (int i = 0; i < gme_track_count(data); i++) { gme_info_t* info = nullptr; diff --git a/src/plugins/gmedecoder/GmeIndexerSource.h b/src/plugins/gmedecoder/GmeIndexerSource.h index df0598bff..336ba0a6f 100644 --- a/src/plugins/gmedecoder/GmeIndexerSource.h +++ b/src/plugins/gmedecoder/GmeIndexerSource.h @@ -38,6 +38,7 @@ #include #include #include +#include class GmeIndexerSource: public musik::core::sdk::IIndexerSource { public: