Skip to content

Commit

Permalink
Added a way to set the audio position
Browse files Browse the repository at this point in the history
  • Loading branch information
QuestionableM committed Dec 16, 2023
1 parent 76bc583 commit 30688fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Code/Hooks/fmod_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ FMOD_RESULT FakeEventDescription::setVolume(float new_volume)
return this->updateVolume();
}

FMOD_RESULT FakeEventDescription::setPosition(float new_position)
{
return this->channel->setPosition(static_cast<unsigned int>(new_position * 1000.0f), FMOD_TIMEUNIT_MS);
}

FMOD_RESULT FakeEventDescription::updateVolume()
{
return this->channel->setVolume(this->custom_volume * SM::GameSettings::GetEffectsVolume());
Expand Down Expand Up @@ -301,6 +306,12 @@ static FMOD_RESULT fake_event_desc_setReverbIndex(FakeEventDescription* fake_eve
return FMOD_OK;
}

static FMOD_RESULT fake_event_desc_setPosition(FakeEventDescription* fake_event, float position)
{
fake_event->setPosition(position);
return FMOD_OK;
}

inline static std::unordered_map<std::string, v_fmod_set_parameter_function> g_fake_event_parameter_table =
{
//Legacy audio parameters
Expand All @@ -313,7 +324,8 @@ inline static std::unordered_map<std::string, v_fmod_set_parameter_function> g_f
{ "CAE_Pitch" , fake_event_desc_setPitch },
{ "CAE_Volume" , fake_event_desc_setVolume },
{ "CAE_Reverb" , fake_event_desc_setReverb },
{ "CAE_ReverbIdx", fake_event_desc_setReverbIndex }
{ "CAE_ReverbIdx", fake_event_desc_setReverbIndex },
{ "CAE_Position" , fake_event_desc_setPosition }
};

FMOD_RESULT FMODHooks::h_FMOD_Studio_EventInstance_setParameterByName(FMOD::Studio::EventInstance* event_instance, const char* name, float value, bool ignoreseekspeed)
Expand Down
1 change: 1 addition & 0 deletions Code/Hooks/fmod_hooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct FakeEventDescription
}

FMOD_RESULT setVolume(float new_volume);
FMOD_RESULT setPosition(float new_position);
FMOD_RESULT updateVolume();

void updateReverbData();
Expand Down

0 comments on commit 30688fc

Please sign in to comment.