Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
fix audiochannelcontrol bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnut committed Jan 24, 2024
1 parent 8dec96f commit 2a47e3e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
37 changes: 17 additions & 20 deletions src/Hacks/AudioChannelControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,47 @@ using namespace geode::prelude;

FMOD_RESULT AudioChannelControl::setVolumeHook(FMOD::Channel* channel, float volume)
{
audioChannel = channel;

if (speed != 1.f)
setFrequency(channel, speed);
channel->setFrequency(44100 * speed);

return channel->setVolume(volume);
}

void AudioChannelControl::set(float frequency)
{
if (audioChannel == nullptr)
return;

speed = frequency;
setFrequency(audioChannel, frequency);

FMOD::Channel* audioChannel;

for(int i = 0; i < 2; i++)
{
FMODAudioEngine::sharedEngine()->m_system->getChannel(126 + i, &audioChannel);
if(audioChannel)
audioChannel->setFrequency(44100 * frequency);
}
}

void AudioChannelControl::setPitch(float pitch)
{
auto system = FMODAudioEngine::sharedEngine()->m_system;
FMOD::ChannelGroup* group;
system->getMasterChannelGroup(&group);

if (!audioChannel || !system)
return;

static FMOD::DSP* pitchShifter;
static FMOD::DSP* pitchShifter = nullptr;

if (pitchShifter)
{
audioChannel->removeDSP(pitchShifter);
group->removeDSP(pitchShifter);
pitchShifter->release();
pitchShifter = nullptr;
}

if (pitch == 1.f)
return;

system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &pitchShifter);

pitchShifter->setParameterFloat(FMOD_DSP_PITCHSHIFT_FFTSIZE, 4096);
pitchShifter->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, pitch);

audioChannel->addDSP(0, pitchShifter);
group->addDSP(0, pitchShifter);
}

class $modify(PlayLayer)
Expand All @@ -68,8 +67,6 @@ class $modify(PlayLayer)

$execute
{
AudioChannelControl::setFrequency = reinterpret_cast<decltype(AudioChannelControl::setFrequency)>(GetProcAddress(
reinterpret_cast<HMODULE>(util::fmod_base), "?setPitch@ChannelControl@FMOD@@QAG?AW4FMOD_RESULT@@M@Z"));
void* setVolumeAddress = reinterpret_cast<void*>(GetProcAddress(
reinterpret_cast<HMODULE>(util::fmod_base), "?setVolume@ChannelControl@FMOD@@QAG?AW4FMOD_RESULT@@M@Z"));

Expand Down
4 changes: 1 addition & 3 deletions src/Hacks/AudioChannelControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

namespace AudioChannelControl
{
static FMOD::Channel* audioChannel;
static float speed = 1.f;
inline float speed = 1.f;

FMOD_RESULT setVolumeHook(FMOD::Channel*, float);
inline void* (__stdcall* setFrequency)(FMOD::Channel*, float);

void set(float);
void setPitch(float);
Expand Down
7 changes: 4 additions & 3 deletions src/Macrobot/Macrobot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class $modify(CCKeyboardDispatcher){
class $modify(PlayLayer){
void loadFromCheckpoint(CheckpointObject * checkpoint)
{
if (playerMode != -1 && playerObject1)
if (checkpoints.contains(checkpoint) && playerMode != -1 && playerObject1)
{
CheckpointData checkpointData = checkpoints[checkpoint];
const auto check = [&](const Action &action) -> bool { return action.time >= checkpointData.time; };
Expand Down Expand Up @@ -175,8 +175,6 @@ void Macrobot::GJBaseGameLayerProcessCommands(GJBaseGameLayer *self)
double currentTime = *((double *)GameManager::get()->getPlayLayer() + 1412);
gameTime = currentTime;

int correctionType = Mod::get()->getSavedValue<int>("macrobot/corrections", 0);

if (playerMode == 0 && macro.inputs.size() > 0 && actionIndex < macro.inputs.size() &&
gameTime >= macro.inputs[actionIndex].time)
{
Expand All @@ -187,6 +185,9 @@ void Macrobot::GJBaseGameLayerProcessCommands(GJBaseGameLayer *self)
GameManager::get()->getPlayLayer()->handleButton(true, ac.button, !ac.player2);
else
GameManager::get()->getPlayLayer()->handleButton(false, ac.button, !ac.player2);

int correctionType = Mod::get()->getSavedValue<int>("macrobot/corrections", 0);

if (correctionType > 0 && ac.correction.has_value())
{
Correction &co = ac.correction.value();
Expand Down
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ void init()
Common::calculateFramerate();
Common::setPriority();
Common::onAudioSpeedChange();
Common::onAudioPitchChange();
Common::loadIcons();
Clickpacks::init();
SafeMode::updateState();
Expand Down

0 comments on commit 2a47e3e

Please sign in to comment.