- fixed plugin dol path that was broken in last release.

- added option to upsample/resample music audio to 48khz. code taken from wiixplorer thanks to dimok.
This commit is contained in:
Fledge68 2020-05-25 17:17:50 -05:00
parent 0263a20778
commit 64cf5a6858
18 changed files with 130 additions and 67 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 MiB

After

Width:  |  Height:  |  Size: 4.1 MiB

View File

@ -1,6 +1,6 @@
#define APP_NAME "WiiFlow WFL" #define APP_NAME "WiiFlow WFL"
#define APP_VERSION "5.4.6" #define APP_VERSION "5.4.7"
#define APP_DATA_DIR "wiiflow" #define APP_DATA_DIR "wiiflow"
#define APPS_DIR "apps/wiiflow" #define APPS_DIR "apps/wiiflow"

View File

@ -416,6 +416,7 @@ bool CMenu::init(bool usb_mounted)
/* Init background Music Player and song info */ /* Init background Music Player and song info */
MusicPlayer.Init(m_cfg, m_musicDir, fmt("%s/music", m_themeDataDir.c_str())); MusicPlayer.Init(m_cfg, m_musicDir, fmt("%s/music", m_themeDataDir.c_str()));
m_music_info = m_cfg.getBool("GENERAL", "display_music_info", false); m_music_info = m_cfg.getBool("GENERAL", "display_music_info", false);
MusicPlayer.SetResampleSetting(m_cfg.getBool("general", "resample_to_48khz", false));
/* Init Button Manager and build the menus */ /* Init Button Manager and build the menus */
_buildMenus(); _buildMenus();

View File

@ -66,17 +66,6 @@ void CMenu::_showConfig7(int curPage)
if(m_config7LblUser[i] != -1) if(m_config7LblUser[i] != -1)
m_btnMgr.show(m_config7LblUser[i]); m_btnMgr.show(m_config7LblUser[i]);
if(curPage == 13)
{
m_btnMgr.show(m_config7Lbl1);
m_btnMgr.show(m_config7Btn1);
m_btnMgr.show(m_config7Lbl2);
m_btnMgr.show(m_config7Btn2);
m_btnMgr.show(m_config7Lbl3);
m_btnMgr.show(m_config7Btn3);
}
else
{
m_btnMgr.show(m_config7Lbl1); m_btnMgr.show(m_config7Lbl1);
m_btnMgr.show(m_config7Btn1); m_btnMgr.show(m_config7Btn1);
m_btnMgr.show(m_config7Lbl2); m_btnMgr.show(m_config7Lbl2);
@ -85,7 +74,7 @@ void CMenu::_showConfig7(int curPage)
m_btnMgr.show(m_config7Btn3); m_btnMgr.show(m_config7Btn3);
m_btnMgr.show(m_config7Lbl4); m_btnMgr.show(m_config7Lbl4);
if(curPage == 7 || curPage == 11 || curPage == 12) if(curPage == 7 || curPage == 11 || curPage == 12 || curPage == 13)
m_btnMgr.show(m_config7Btn4); m_btnMgr.show(m_config7Btn4);
else else
{ {
@ -93,7 +82,6 @@ void CMenu::_showConfig7(int curPage)
m_btnMgr.show(m_config7Btn4M); m_btnMgr.show(m_config7Btn4M);
m_btnMgr.show(m_config7Btn4P); m_btnMgr.show(m_config7Btn4P);
} }
}
if(curPage == 7) if(curPage == 7)
{ {
@ -169,6 +157,8 @@ void CMenu::_showConfig7(int curPage)
m_btnMgr.setText(m_config7Btn2, m_cfg.getBool("general", "box_mode", false) ? _t("on", L"On") : _t("off", L"Off")); m_btnMgr.setText(m_config7Btn2, m_cfg.getBool("general", "box_mode", false) ? _t("on", L"On") : _t("off", L"Off"));
m_btnMgr.setText(m_config7Lbl3, _t("cfg727", L"Use Plugin Database Titles")); m_btnMgr.setText(m_config7Lbl3, _t("cfg727", L"Use Plugin Database Titles"));
m_btnMgr.setText(m_config7Btn3, m_cfg.getBool(PLUGIN_DOMAIN, "database_titles", true) ? _t("yes", L"Yes") : _t("no", L"No")); m_btnMgr.setText(m_config7Btn3, m_cfg.getBool(PLUGIN_DOMAIN, "database_titles", true) ? _t("yes", L"Yes") : _t("no", L"No"));
m_btnMgr.setText(m_config7Lbl4, _t("cfg728", L"Upsample music to 48khz"));
m_btnMgr.setText(m_config7Btn4, m_cfg.getBool("general", "resample_to_48khz", true) ? _t("yes", L"Yes") : _t("no", L"No"));
} }
} }
@ -367,6 +357,15 @@ int CMenu::_config7(int curPage)
m_cfg.setBool(PLUGIN_DOMAIN, "database_titles", val); m_cfg.setBool(PLUGIN_DOMAIN, "database_titles", val);
m_btnMgr.setText(m_config7Btn3, val ? _t("yes", L"Yes") : _t("no", L"No")); m_btnMgr.setText(m_config7Btn3, val ? _t("yes", L"Yes") : _t("no", L"No"));
} }
if(m_btnMgr.selected(m_config7Btn4))
{
bool val = !m_cfg.getBool("general", "resample_to_48khz");
m_cfg.setBool("general", "resample_to_48khz", val);
m_btnMgr.setText(m_config7Btn4, val ? _t("yes", L"Yes") : _t("no", L"No"));
MusicPlayer.SetResampleSetting(val);
MusicPlayer.Stop();
MusicPlayer.LoadCurrentFile();
}
} }
} }
} }

View File

@ -193,16 +193,16 @@ void CMenu::_launchHomebrew(const char *filepath, vector<string> arguments)
m_cfg.save(true); m_cfg.save(true);
Playlog_Delete(); Playlog_Delete();
/* no more error msgs - remove btns and sounds */
cleanup();
/* load boot.dol into memory and load app_booter.bin into memory */ /* load boot.dol into memory and load app_booter.bin into memory */
bool ret = (LoadHomebrew(filepath) && LoadAppBooter(fmt("%s/app_booter.bin", m_binsDir.c_str()))); bool ret = (LoadHomebrew(filepath) && LoadAppBooter(fmt("%s/app_booter.bin", m_binsDir.c_str())));
if(ret == false) if(ret == false)
{ {
//error(_t("errgame14", L"app_booter.bin not found!")); error(_t("errgame14", L"app_booter.bin not found!"));
_exitWiiflow(); _exitWiiflow();
} }
/* no more error msgs - remove btns and sounds */
cleanup();
AddBootArgument(filepath); AddBootArgument(filepath);
for(u32 i = 0; i < arguments.size(); ++i) for(u32 i = 0; i < arguments.size(); ++i)

View File

@ -35,16 +35,12 @@ public:
AifDecoder(const char *filepath); AifDecoder(const char *filepath);
AifDecoder(const u8 *snd, int len); AifDecoder(const u8 *snd, int len);
~AifDecoder(); ~AifDecoder();
int GetFormat() { return Format; };
int GetSampleRate() { return SampleRate; };
int Read(u8 *buffer, int buffer_size); int Read(u8 *buffer, int buffer_size);
protected: protected:
void OpenFile(); void OpenFile();
void CloseFile(); void CloseFile();
u32 DataOffset; u32 DataOffset;
u32 DataSize; u32 DataSize;
u32 SampleRate;
u8 Format;
}; };
#endif #endif

View File

@ -100,6 +100,9 @@ void BNSDecoder::OpenFile()
CloseFile(); CloseFile();
return; return;
} }
// set sound information
Format = SoundData.format;
SampleRate = SoundData.frequency;
Decode(); Decode();
} }

View File

@ -45,8 +45,6 @@ public:
BNSDecoder(const char * filepath); BNSDecoder(const char * filepath);
BNSDecoder(const u8 * snd, int len); BNSDecoder(const u8 * snd, int len);
virtual ~BNSDecoder(); virtual ~BNSDecoder();
int GetFormat() { return SoundData.format; };
int GetSampleRate() { return SoundData.frequency; };
int Read(u8 * buffer, int buffer_size); int Read(u8 * buffer, int buffer_size);
protected: protected:
void OpenFile(); void OpenFile();

View File

@ -33,8 +33,6 @@ public:
Mp3Decoder(const char * filepath); Mp3Decoder(const char * filepath);
Mp3Decoder(const u8 * sound, int len); Mp3Decoder(const u8 * sound, int len);
~Mp3Decoder(); ~Mp3Decoder();
int GetFormat() { return Format; };
int GetSampleRate() { return SampleRate; };
int Rewind(); int Rewind();
int Read(u8 * buffer, int buffer_size); int Read(u8 * buffer, int buffer_size);
protected: protected:
@ -45,7 +43,5 @@ protected:
mad_timer_t Timer; mad_timer_t Timer;
u8 * GuardPtr; u8 * GuardPtr;
u8 * ReadBuffer; u8 * ReadBuffer;
u8 Format;
u32 SampleRate;
u32 SynthPos; u32 SynthPos;
}; };

View File

@ -135,6 +135,11 @@ void Musicplayer::SetVolume(u8 volume)
MusicFile.SetVolume(CurrentVolume); MusicFile.SetVolume(CurrentVolume);
} }
void Musicplayer::SetResampleSetting(bool resample)
{
ResampleSetting = resample;
}
void Musicplayer::Previous() void Musicplayer::Previous()
{ {
if(FileNames.empty() || PosFromPrevFile()) if(FileNames.empty() || PosFromPrevFile())

View File

@ -37,6 +37,8 @@ public:
void SetMaxVolume(u8 volume); void SetMaxVolume(u8 volume);
u8 GetVolume() { return CurrentVolume; }; u8 GetVolume() { return CurrentVolume; };
u8 GetMaxVolume() { return Volume; }; u8 GetMaxVolume() { return Volume; };
bool ResampleSetting;
void SetResampleSetting(bool resample);
void Previous(); void Previous();
void Next(); void Next();
@ -51,11 +53,11 @@ public:
bool SongChanged(); bool SongChanged();
time_t DisplayTime; time_t DisplayTime;
bool OneSong; bool OneSong;
/* Plugin */
void LoadFile(const char *name, bool display_change = true); void LoadFile(const char *name, bool display_change = true);
void LoadCurrentFile();
protected: protected:
bool PosFromPrevFile(); bool PosFromPrevFile();
void LoadCurrentFile();
u8 Volume; u8 Volume;
u8 CurrentVolume; u8 CurrentVolume;

View File

@ -96,25 +96,18 @@ void OggDecoder::OpenFile()
} }
ogg_info = ov_info(&ogg_file, -1); ogg_info = ov_info(&ogg_file, -1);
if(!ogg_info)
{
ov_clear(&ogg_file);
delete file_fd;
file_fd = NULL;
return;
}
Format = ((ogg_info->channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
SampleRate = ogg_info->rate;
Decode(); Decode();
} }
int OggDecoder::GetFormat()
{
if(!file_fd)
return VOICE_STEREO_16BIT;
return ((ogg_info->channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
}
int OggDecoder::GetSampleRate()
{
if(!file_fd)
return 0;
return (int) ogg_info->rate;
}
int OggDecoder::Rewind() int OggDecoder::Rewind()
{ {
if(!file_fd) if(!file_fd)

View File

@ -34,8 +34,6 @@ public:
OggDecoder(const char * filepath); OggDecoder(const char * filepath);
OggDecoder(const u8 * snd, int len); OggDecoder(const u8 * snd, int len);
~OggDecoder(); ~OggDecoder();
int GetFormat();
int GetSampleRate();
int Rewind(); int Rewind();
int Read(u8 * buffer, int buffer_size); int Read(u8 * buffer, int buffer_size);
int Tell(); int Tell();

View File

@ -26,9 +26,14 @@
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <gccore.h> #include <gccore.h>
#include <malloc.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "SoundDecoder.hpp" #include "SoundDecoder.hpp"
#include "MusicPlayer.hpp"
static const u32 FixedPointShift = 15;
static const u32 FixedPointScale = 1 << FixedPointShift;
SoundDecoder::SoundDecoder() SoundDecoder::SoundDecoder()
{ {
@ -57,6 +62,9 @@ SoundDecoder::~SoundDecoder()
if(file_fd) if(file_fd)
delete file_fd; delete file_fd;
file_fd = NULL; file_fd = NULL;
if(ResampleBuffer)
free(ResampleBuffer);
} }
void SoundDecoder::Init() void SoundDecoder::Init()
@ -64,6 +72,7 @@ void SoundDecoder::Init()
SoundType = SOUND_RAW; SoundType = SOUND_RAW;
SoundBlocks = 8; SoundBlocks = 8;
SoundBlockSize = 8192; SoundBlockSize = 8192;
ResampleTo48kHz = MusicPlayer.ResampleSetting;
CurPos = 0; CurPos = 0;
LoopStart = 0; LoopStart = 0;
LoopEnd = 0; LoopEnd = 0;
@ -73,6 +82,8 @@ void SoundDecoder::Init()
ExitRequested = false; ExitRequested = false;
SoundBuffer.SetBufferBlockSize(SoundBlockSize); SoundBuffer.SetBufferBlockSize(SoundBlockSize);
SoundBuffer.Resize(SoundBlocks); SoundBuffer.Resize(SoundBlocks);
ResampleBuffer = NULL;
ResampleRatio = 0;
} }
int SoundDecoder::Rewind() int SoundDecoder::Rewind()
@ -92,6 +103,47 @@ int SoundDecoder::Read(u8 * buffer, int buffer_size)
return ret; return ret;
} }
void SoundDecoder::EnableUpsample(void)
{
if( (ResampleBuffer == NULL)
&& IsStereo() && Is16Bit()
&& SampleRate != 32000
&& SampleRate != 48000)
{
ResampleBuffer = (u8*)memalign(32, SoundBlockSize);
ResampleRatio = ( FixedPointScale * SampleRate ) / 48000;
SoundBlockSize = ( SoundBlockSize * ResampleRatio ) / FixedPointScale;
SoundBlockSize &= ~0x03;
// set new sample rate
SampleRate = 48000;
}
}
void SoundDecoder::Upsample(s16 *src, s16 *dst, u32 nr_src_samples, u32 nr_dst_samples)
{
int timer = 0;
for(u32 i = 0, n = 0; i < nr_dst_samples; i += 2)
{
if((n+3) < nr_src_samples) {
// simple fixed point linear interpolation
dst[i] = src[n] + ( ((src[n+2] - src[n] ) * timer) >> FixedPointShift );
dst[i+1] = src[n+1] + ( ((src[n+3] - src[n+1]) * timer) >> FixedPointShift );
}
else {
dst[i] = src[n];
dst[i+1] = src[n+1];
}
timer += ResampleRatio;
if(timer >= (int)FixedPointScale) {
n += 2;
timer -= FixedPointScale;
}
}
}
void SoundDecoder::Decode() void SoundDecoder::Decode()
{ {
if(!file_fd || ExitRequested || EndOfFile) if(!file_fd || ExitRequested || EndOfFile)
@ -121,6 +173,10 @@ void SoundDecoder::Decode()
return; return;
} }
//*******************************************
if(ResampleTo48kHz && !ResampleBuffer)
EnableUpsample();
while(done < SoundBlockSize) while(done < SoundBlockSize)
{ {
int ret = Read(&write_buf[done], SoundBlockSize-done); int ret = Read(&write_buf[done], SoundBlockSize-done);
@ -146,6 +202,17 @@ void SoundDecoder::Decode()
if(done > 0) if(done > 0)
{ {
// check if we need to resample
if(ResampleBuffer && ResampleRatio)
{
memcpy(ResampleBuffer, write_buf, done);
int src_samples = done >> 1;
int dest_samples = ( src_samples * FixedPointScale ) / ResampleRatio;
dest_samples &= ~0x01;
Upsample((s16*)ResampleBuffer, (s16*)write_buf, src_samples, dest_samples);
done = dest_samples << 1;
}
SoundBuffer.SetBufferSize(newWhich, done); SoundBuffer.SetBufferSize(newWhich, done);
SoundBuffer.SetBufferReady(newWhich, true); SoundBuffer.SetBufferReady(newWhich, true);
} }

View File

@ -55,8 +55,8 @@ public:
virtual int Tell() { return CurPos; }; virtual int Tell() { return CurPos; };
virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); }; virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); };
virtual int Rewind(); virtual int Rewind();
virtual int GetFormat() { return VOICE_STEREO_16BIT; }; virtual u8 GetFormat() { return Format; }
virtual int GetSampleRate() { return 48000; }; virtual u16 GetSampleRate() { return SampleRate; }
virtual void Decode(); virtual void Decode();
virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); }; virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); };
virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); }; virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); };
@ -74,8 +74,11 @@ public:
virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); }; virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); };
virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); }; virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); };
virtual bool Is16Bit() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_MONO_16BIT); }; virtual bool Is16Bit() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_MONO_16BIT); };
void EnableUpsample(void);
protected: protected:
void Init(); void Init();
void Upsample(s16 *src, s16 *dst, u32 nr_src_samples, u32 nr_dst_samples);
CFile * file_fd; CFile * file_fd;
BufferCircle SoundBuffer; BufferCircle SoundBuffer;
@ -83,12 +86,17 @@ protected:
u16 SoundBlocks; u16 SoundBlocks;
int SoundBlockSize; int SoundBlockSize;
int CurPos; int CurPos;
bool ResampleTo48kHz;
bool Loop; bool Loop;
int LoopStart; int LoopStart;
int LoopEnd; int LoopEnd;
bool EndOfFile; bool EndOfFile;
bool Decoding; bool Decoding;
bool ExitRequested; bool ExitRequested;
u8 Format;
u16 SampleRate;
u8 *ResampleBuffer;
u32 ResampleRatio;
}; };
#endif #endif

View File

@ -82,16 +82,12 @@ public:
WavDecoder(const char * filepath); WavDecoder(const char * filepath);
WavDecoder(const u8 * snd, int len); WavDecoder(const u8 * snd, int len);
~WavDecoder(); ~WavDecoder();
int GetFormat() { return Format; };
int GetSampleRate() { return SampleRate; };
int Read(u8 * buffer, int buffer_size); int Read(u8 * buffer, int buffer_size);
protected: protected:
void OpenFile(); void OpenFile();
void CloseFile(); void CloseFile();
u32 DataOffset; u32 DataOffset;
u32 DataSize; u32 DataSize;
u32 SampleRate;
u8 Format;
bool Is16Bit; bool Is16Bit;
}; };

View File

@ -69,6 +69,7 @@ cfg724=Lock coverflow layouts
cfg725=Shutdown to idle standby cfg725=Shutdown to idle standby
cfg726=Covers Box Mode cfg726=Covers Box Mode
cfg727=Use Plugin Database Titles cfg727=Use Plugin Database Titles
cfg728=Upsample music to 48khz
cfga2=Install game cfga2=Install game
cfga3=Install cfga3=Install
cfga6=Language cfga6=Language