Skip to content

Commit

Permalink
Add support for starting points to custom skin music
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Jun 24, 2023
1 parent 3f388d2 commit 61f841d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions romsel_dsimenutheme/arm9/source/graphics/themefilenames.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@
#define TFN_FONT_LARGE_DSI TFN_UI_DIRECTORY"/font/large-dsi.nftr"

#define TFN_SOUND_EFFECTBANK TFN_UI_DIRECTORY"/sound/sfx.bin"
#define TFN_START_SOUND_BG TFN_UI_DIRECTORY"/sound/bgm.start.wav"
#define TFN_SOUND_BG TFN_UI_DIRECTORY"/sound/bgm.wav"
#define TFN_START_SOUND_BG_CACHE TFN_UI_DIRECTORY"/sound/bgm.start.pcm.raw"
#define TFN_SOUND_BG_CACHE TFN_UI_DIRECTORY"/sound/bgm.pcm.raw"

#define TFN_DEFAULT_SOUND_EFFECTBANK TFN_SYSTEM_SOUND_DIRECTORY"/defaultfx.bin"
Expand Down
27 changes: 24 additions & 3 deletions romsel_dsimenutheme/arm9/source/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,17 @@ SoundControl::SoundControl()
break;
}
if (customSkin) {
std::string musicStartPath = TFN_START_SOUND_BG;
std::string musicPath = TFN_SOUND_BG;
std::string cacheStartPath = TFN_START_SOUND_BG_CACHE;
std::string cachePath = TFN_SOUND_BG_CACHE;
bool closed = false;
if (access(musicPath.c_str(), F_OK) == 0) {
loopableMusic = (access(musicStartPath.c_str(), F_OK) == 0);
if (loopableMusic) {
stream_start_source = fopen(musicStartPath.c_str(), "rb");
}

// Read properties from WAV header
u8 wavFormat = 0;
u8 numChannels = 1;
Expand All @@ -229,21 +236,35 @@ SoundControl::SoundControl()
fread(&stream.sampling_rate, sizeof(u16), 1, stream_source);

if (wavFormat == 0x11) {
// If ADPCM and hasn't been successfully converted yet, do so now
if(access(cachePath.c_str(), F_OK) != 0 || getFileSize(cachePath.c_str()) == 0) {
// If music is ADPCM and hasn't been successfully converted yet, do so now
if (loopableMusic && (access(cacheStartPath.c_str(), F_OK) != 0 || getFileSize(cacheStartPath.c_str()) == 0)) { // Start point
if (adpcm_main(musicStartPath.c_str(), cacheStartPath.c_str(), numChannels == 2) == -1) {
remove(cacheStartPath.c_str());
}
}
if (access(cachePath.c_str(), F_OK) != 0 || getFileSize(cachePath.c_str()) == 0) { // Loop point
if (adpcm_main(musicPath.c_str(), cachePath.c_str(), numChannels == 2) == -1) {
remove(cachePath.c_str());
}
}
if (loopableMusic) {
fclose(stream_start_source);
}
fclose(stream_source);
closed = true;
} else {
seekPos = 0x2C;
}
} else {
loopableMusic = (access(cacheStartPath.c_str(), F_OK) == 0);
closed = true;
}
if (closed) stream_source = fopen(cachePath.c_str(), "rb");
if (closed) {
if (loopableMusic) {
stream_start_source = fopen(cacheStartPath.c_str(), "rb");
}
stream_source = fopen(cachePath.c_str(), "rb");
}
if (stream_source) break; } // fallthrough if stream_source fails.
}
case 4:
Expand Down

0 comments on commit 61f841d

Please sign in to comment.