//
// FMODAudioEngine::stopAndGetFade from 0x140058a50 to 0x140058b8f (319 bytes)
//
// 5 xrefs:
// > FMODAudioEngine::stopChannel_1 @ 0x140058909
// > FMODAudioEngine::fadeInMusic @ 0x14005c462
// > FMODAudioEngine::fadeOutMusic @ 0x14005c5a7
// > FMODAudioEngine::fadeMusic @ 0x14005c6ea
// > ??> @ 0x1406c51b4
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
float FMODAudioEngine::stopAndGetFade(FMODAudioEngine *a1, FMOD::Channel *a2)
{
FMOD_RESULT FadePoints; // eax
bool v5; // zf
FMOD_RESULT v6; // eax
__int64 v7; // r8
__int64 v8; // rdx
int v9; // ecx
float v10; // xmm1_4
unsigned __int64 v11; // rax
int v12; // ecx
float v13; // xmm0_4
unsigned __int64 v15; // rax
__int64 v16; // [rsp+20h] [rbp-18h] BYREF
__int64 v17; // [rsp+28h] [rbp-10h]
int v18; // [rsp+48h] [rbp+10h] BYREF
float v19; // [rsp+50h] [rbp+18h] BYREF
float v20; // [rsp+54h] [rbp+1Ch]
unsigned __int64 v21; // [rsp+58h] [rbp+20h] BYREF
if ( !a2 )
return 1.0;
v18 = 0;
FadePoints = (unsigned int)FMOD_Channel_GetFadePoints(a2, &v18, 0, 0);
v5 = v18 == 0;
a1->m_lastResult = FadePoints;
if ( v5 )
return 1.0;
FMOD_Channel_GetDSPClock(a2, 0, &v21);
a1->m_lastResult = FMOD::ChannelControl::getDSPClock(a2, nullptr, &v21);
v6 = (unsigned int)FMOD_Channel_GetFadePoints(a2, &v18, &v16, &v19);
v7 = v17;
v8 = v16;
a1->m_lastResult = v6;
FMOD_Channel_RemoveFadePoints(a2, v8, v7);
v9 = v17 - v16;
if ( v17 - v16 < 0 )
{
v11 = v9 & 1 | ((unsigned __int64)(v17 - v16) >> 1);
v10 = (float)(int)v11 + (float)(int)v11;
}
else
{
v10 = (float)v9;
}
v12 = v21 - v16;
v13 = (float)(v20 - v19) / v10;
if ( (__int64)(v21 - v16) >= 0 )
return (float)(v13 * (float)v12) + v19;
v15 = v12 & 1 | ((v21 - v16) >> 1);
return (float)(v13 * (float)((float)(int)v15 + (float)(int)v15)) + v19;
}