Skip to content

Commit

Permalink
Audio: Ensure Voice handle exists before stopping it (julianxhokaxhiu…
Browse files Browse the repository at this point in the history
…#694)

This also fixes a side effect for FF8 that would stop music on the Fisherman Horizon Concert when using the external audio layer
  • Loading branch information
myst6re authored May 18, 2024
1 parent 3f9a356 commit aaae318
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- External textures: Add support for modding VRAM pages directly, like Tonberry Mods does, see [documentation](https://github.com/julianxhokaxhiu/FFNx/blob/master/docs/ff8/mods/external_textures.md) ( https://github.com/julianxhokaxhiu/FFNx/pull/687 https://github.com/julianxhokaxhiu/FFNx/pull/692 )
- External textures: Fix filename lookup which can match more textures than it should in a VRAM page ( https://github.com/julianxhokaxhiu/FFNx/pull/687 )
- External textures: Split `battle/A8DEF.TIM` into three files to avoid redundant textures ( https://github.com/julianxhokaxhiu/FFNx/pull/687 )
- External music: Fix music get stopped in Fisherman's Horizon concert ( https://github.com/julianxhokaxhiu/FFNx/pull/694 )
- Rendering: Avoid texture reupload in case of palette swap ( https://github.com/julianxhokaxhiu/FFNx/pull/687 )
- Rendering: Fix texture unload when multiple palettes are written ( https://github.com/julianxhokaxhiu/FFNx/pull/687 )
- Rendering: Prevent the game from sending textures with half-alpha colors ( https://github.com/julianxhokaxhiu/FFNx/pull/687 )
Expand Down
23 changes: 17 additions & 6 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@ void NxAudioEngine::playSynchronizedMusics(const std::vector<std::string>& names
}
}

if (trace_all || trace_music) ffnx_trace("NxAudioEngine::%s: handle=%X\n", __func__, groupHandle);

if (!_engine.isVoiceGroupEmpty(groupHandle)) {
_musics[channel].handle = groupHandle;
_musics[channel].id = id;
Expand Down Expand Up @@ -1090,7 +1092,7 @@ bool NxAudioEngine::playVoice(const char* name, int slot, float volume)
exists = getFilenameFullPath(filename, name, NxAudioEngineLayer::NXAUDIOENGINE_VOICE);
}

if (trace_all || trace_voice) ffnx_trace("NxAudioEngine::%s: slot[%d] %s\n", __func__, slot, filename);
if (trace_all || trace_voice) ffnx_trace("NxAudioEngine::%s: slot[%d] %s exists=%d\n", __func__, slot, filename, exists);

if (exists)
{
Expand Down Expand Up @@ -1123,14 +1125,23 @@ bool NxAudioEngine::playVoice(const char* name, int slot, float volume)

void NxAudioEngine::stopVoice(int slot, double time)
{
SoLoud::handle handle = _currentVoice[slot].handle;

if (trace_all || trace_voice) ffnx_trace("NxAudioEngine::%s: slot=%d time=%lf handle=%X\n", __func__, slot, time, handle);

if (!_engine.isValidVoiceHandle(handle))
{
return;
}

if (time > 0.0)
{
_engine.fadeVolume(_currentVoice[slot].handle, 0, time);
_engine.scheduleStop(_currentVoice[slot].handle, time);
_engine.fadeVolume(handle, 0, time);
_engine.scheduleStop(handle, time);
}
else
{
_engine.stop(_currentVoice[slot].handle);
_engine.stop(handle);
}
}

Expand Down Expand Up @@ -1250,7 +1261,7 @@ bool NxAudioEngine::playAmbient(const char* name, float volume, double time)
exists = getFilenameFullPath(filename, name, NxAudioEngineLayer::NXAUDIOENGINE_AMBIENT);
}

if (trace_all || trace_ambient) ffnx_trace("NxAudioEngine::%s: %s\n", __func__, filename);
if (trace_all || trace_ambient) ffnx_trace("NxAudioEngine::%s: %s exists=%d handle=%X\n", __func__, filename, exists, _currentAmbient.handle);

// Stop any previously playing ambient
if (_engine.isValidVoiceHandle(_currentAmbient.handle))
Expand Down Expand Up @@ -1377,7 +1388,7 @@ bool NxAudioEngine::playMovieAudio(const char* nameWithPath, int slot, float vol
char filename[MAX_PATH];
bool exists = getFilenameFullPath(filename, nameWithPath, NxAudioEngineLayer::NXAUDIOENGINE_MOVIE_AUDIO);

if (trace_all || trace_movies) ffnx_trace("NxAudioEngine::%s: %s\n", __func__, filename);
if (trace_all || trace_movies) ffnx_trace("NxAudioEngine::%s: %s exists=%d\n", __func__, filename, exists);

// Stop any previously playing movie audio
if (_engine.isValidVoiceHandle(_currentMovieAudio[slot].handle))
Expand Down

0 comments on commit aaae318

Please sign in to comment.