Skip to content

Commit

Permalink
Sys: Make file buffer opt-in as it's not completely reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
tallbl0nde committed Nov 1, 2020
1 parent 0e3aaa0 commit cc3e30e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Sysmodule/source/sources/MP3.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include <cstring>
#include "Log.hpp"
#include "nx/File.hpp"
#include <mpg123.h>
#include "sources/MP3.hpp"

#ifdef USE_FILE_BUFFER
#include "nx/File.hpp"
#endif

mpg123_handle * MP3::mpg = nullptr;

MP3::MP3(const std::string & path) : Source() {
Expand All @@ -17,8 +20,14 @@ MP3::MP3(const std::string & path) : Source() {
}

// Attempt to open file
#ifdef USE_FILE_BUFFER
this->file = new NX::File(path);
int result = mpg123_open_handle(this->mpg, this->file);
#else
this->file = nullptr;
int result = mpg123_open(this->mpg, path.c_str());
#endif

if (result != MPG123_OK) {
MP3::logErrorMsg();
Log::writeError("[MP3] Unable to open file");
Expand Down Expand Up @@ -97,7 +106,9 @@ MP3::~MP3() {
}

// Delete file handle
#ifdef USE_FILE_BUFFER
delete this->file;
#endif
}

bool MP3::initLib() {
Expand All @@ -116,11 +127,13 @@ bool MP3::initLib() {
}

// Enable support for custom file object
#ifdef USE_FILE_BUFFER
result = mpg123_replace_reader_handle(MP3::mpg, NX::File::readFile, NX::File::seekFile, nullptr);
if (result != MPG123_OK) {
Log::writeError("[MP3] Unable to enable custom file object support: " + std::to_string(result));
return false;
}
#endif

// Enable gapless decoding
result = mpg123_param(MP3::mpg, MPG123_FLAGS, MPG123_QUIET | MPG123_GAPLESS, 0.0f);
Expand Down

0 comments on commit cc3e30e

Please sign in to comment.