Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAEWeaponAudioEntity #753

Merged
merged 26 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3d50c25
Refactor `PlayGoggleSound`
Pirulax Jul 17, 2024
afb3278
`PlayMiniGunFireSounds`
Pirulax Jul 17, 2024
693e3d7
Refactor `PlayWeaponLoopSound`
Pirulax Jul 17, 2024
f6109eb
Refactor class var names, etc
Pirulax Jul 17, 2024
189aa68
Merge branch 'master' of github.com:gta-reversed/gta-reversed-modern …
Pirulax Jul 17, 2024
905faa4
Fix `CAEAudioUtility::AudioLog10`
Pirulax Jul 18, 2024
dcaff18
Fix `CAEAudioUtility::GetCurrentTimeInMS`
Pirulax Jul 18, 2024
2a1691a
Refactor `CAEAudioEnvironment::GetPositionRelativeToCamera`
Pirulax Jul 18, 2024
bb0e9a9
Refactor `CAEAudioEnvironment::GetDistanceAttenuation`
Pirulax Jul 18, 2024
de6e8a9
Fix initialization order bug
Pirulax Jul 18, 2024
8f6370a
`PlayGunSounds`
Pirulax Jul 18, 2024
8c1d06f
`ReportChainsawEvent`
Pirulax Jul 18, 2024
7ce3713
`UpdateParameters`
Pirulax Jul 21, 2024
e6c6a6c
Finishing touches
Pirulax Jul 21, 2024
e886b9e
`CAEGlobalWeaponAudioEntity::ServiceAmbientGunFire`
Pirulax Jul 22, 2024
85360c0
Merge branch 'master' of github.com:gta-reversed/gta-reversed-modern …
Pirulax Jul 22, 2024
5a1f071
fix imgui menu after update
Pirulax Jul 22, 2024
31bb809
Fix recursion
Pirulax Jul 22, 2024
887c79e
Fix `CWorld::ProcessLineOfSight`
Pirulax Jul 22, 2024
cb452c9
Fix `TeleportDebugModule` serialization
Pirulax Jul 22, 2024
8ddc6f1
`CAEGlobalWeaponAudioEntity::ServiceAmbientGunFire`: Fix waterfall ef…
Pirulax Jul 22, 2024
0caa8ef
Update source/game_sa/Audio/entities/AEExplosionAudioEntity.cpp
Pirulax Sep 21, 2024
bfe7ad3
Fix `GetPositionRelativeToCamera`
Pirulax Sep 22, 2024
b80a513
Merge branch 'reverse/CAEWeaponAudioEntity' of https://github.com/Pir…
Pirulax Sep 22, 2024
5bce95f
Move `gSoundDistAttenuationTable` into its own data header
Pirulax Sep 30, 2024
7d4e09d
Merge branch 'master' into reverse/CAEWeaponAudioEntity
Pirulax Oct 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 170 additions & 40 deletions source/game_sa/Audio/AEAudioEnvironment.cpp

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions source/game_sa/Audio/AEAudioEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ class CAEAudioEnvironment {
static float GetDistanceAttenuation(float dist);
static float GetDirectionalMikeAttenuation(const CVector& soundDir);
static void GetReverbEnvironmentAndDepth(int8* reverbEnv, int32* depth);
static void GetPositionRelativeToCamera(CVector* vecOut, const CVector* vecPos);
static void GetPositionRelativeToCamera(CVector* vecOut, CPlaceable* placeable);

static void GetPositionRelativeToCamera(CVector& out, const CVector* vecPos);
static CVector GetPositionRelativeToCamera(const CVector& pos) { CVector o; GetPositionRelativeToCamera(o, &pos); return o; }

static void GetPositionRelativeToCamera(CVector& out, CPlaceable* placeable);
static CVector GetPositionRelativeToCamera(CPlaceable* placeable) { CVector o; GetPositionRelativeToCamera(o, placeable); return o; }
};

static constexpr int32 NUM_AUDIO_ENVIRONMENTS = 68;
extern sReverbEnvironment (&gAudioZoneToReverbEnvironmentMap)[NUM_AUDIO_ENVIRONMENTS];

static constexpr int32 NUM_SOUND_DIST_ATTENUATION_ENTRIES = 1280;
extern float (&gSoundDistAttenuationTable)[NUM_SOUND_DIST_ATTENUATION_ENTRIES];
19 changes: 14 additions & 5 deletions source/game_sa/Audio/AEAudioUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#include "AEAudioUtility.h"

uint64& CAEAudioUtility::startTimeMs = *reinterpret_cast<uint64*>(0xb610f8);
auto& Frequency = StaticRef<LARGE_INTEGER>(0xB610F0);
uint64& startTimeMs = *reinterpret_cast<uint64*>(0xb610f8);
float (&CAEAudioUtility::m_sfLogLookup)[50][2] = *reinterpret_cast<float (*)[50][2]>(0xb61100);

// NOTE: Not sure about the size.
Expand Down Expand Up @@ -65,16 +66,23 @@ float CAEAudioUtility::GetPiecewiseLinear(float x, int16 dataCount, float (*data

// 0x4d9e50
float CAEAudioUtility::AudioLog10(float p) {
return 0.00001f <= p ? std::log10f(p) : -5.0f;
return p >= 0.00001f
? std::log10f(p)
: -5.0f;
}

// REFACTORED
// 0x4d9e80
uint64 CAEAudioUtility::GetCurrentTimeInMS() {
using namespace std::chrono;
auto nowMs = time_point_cast<milliseconds>(high_resolution_clock::now());
auto value = duration_cast<milliseconds>(nowMs.time_since_epoch());
return static_cast<uint64>(value.count());
const auto nowMs = time_point_cast<milliseconds>(high_resolution_clock::now());
const auto value = duration_cast<milliseconds>(nowMs.time_since_epoch());
return static_cast<uint64>(value.count()) - startTimeMs;

//For some reason this doesn't work (original code):
//LARGE_INTEGER counter;
//QueryPerformanceCounter(&counter);
//return counter.QuadPart / Frequency.QuadPart * 1000 - startTimeMs;
}

// 0x4d9ef0
Expand Down Expand Up @@ -103,6 +111,7 @@ void CAEAudioUtility::StaticInitialise() {
m_sfLogLookup[1][1] = log10f(v);
}

VERIFY(QueryPerformanceFrequency(&Frequency));
startTimeMs = GetCurrentTimeInMS();
}

Expand Down
1 change: 0 additions & 1 deletion source/game_sa/Audio/AEAudioUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CAEAudioUtility {
}

private:
static uint64& startTimeMs;
static float (&m_sfLogLookup)[50][2];

private:
Expand Down
52 changes: 25 additions & 27 deletions source/game_sa/Audio/AESound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void CAESound::InjectHooks() {
RH_ScopedInstall(StopSound, 0x4EF1C0);
RH_ScopedInstall(SetIndividualEnvironment, 0x4EF2B0);
RH_ScopedInstall(UpdatePlayTime, 0x4EF2E0);
RH_ScopedOverloadedInstall(GetRelativePosition, "OG", 0x4EF350, void(CAESound::*)(CVector&) const);
RH_ScopedInstall(GetRelativePosition, 0x4EF350);
RH_ScopedInstall(CalculateFrequency, 0x4EF390);
RH_ScopedInstall(UpdateFrequency, 0x4EF3E0);
RH_ScopedInstall(GetRelativePlaybackFrequencyWithDoppler, 0x4EF400);
Expand All @@ -42,7 +42,7 @@ CAESound::CAESound(CAESound& sound) {
m_nSoundIdInSlot = sound.m_nSoundIdInSlot;
m_pBaseAudio = sound.m_pBaseAudio;
m_nEvent = sound.m_nEvent;
m_fMaxVolume = sound.m_fMaxVolume;
m_ClientVariable = sound.m_ClientVariable;
m_fVolume = sound.m_fVolume;
m_fSoundDistance = sound.m_fSoundDistance;
m_fSpeed = sound.m_fSpeed;
Expand Down Expand Up @@ -80,7 +80,7 @@ CAESound::CAESound(int16 bankSlotId, int16 sfxId, CAEAudioEntity* baseAudio, CVe
m_pBaseAudio = baseAudio;
m_vecPrevPosn = CVector(0.0f, 0.0f, 0.0f);
m_pPhysicalEntity = nullptr;
m_fMaxVolume = -1.0F;
m_ClientVariable = -1.0F;
m_nEvent = AE_UNDEFINED;
m_nLastFrameUpdate = 0;

Expand Down Expand Up @@ -116,7 +116,7 @@ CAESound& CAESound::operator=(const CAESound& sound) {
m_nSoundIdInSlot = sound.m_nSoundIdInSlot;
m_pBaseAudio = sound.m_pBaseAudio;
m_nEvent = sound.m_nEvent;
m_fMaxVolume = sound.m_fMaxVolume;
m_ClientVariable = sound.m_ClientVariable;
m_fVolume = sound.m_fVolume;
m_fSoundDistance = sound.m_fSoundDistance;
m_fSpeed = sound.m_fSpeed;
Expand Down Expand Up @@ -193,11 +193,10 @@ void CAESound::UpdatePlayTime(int16 soundLength, int16 loopStartTime, int16 play
}

// 0x4EF350
void CAESound::GetRelativePosition(CVector& out) const {
if (!GetFrontEnd()) {
CAEAudioEnvironment::GetPositionRelativeToCamera(&out, &m_vecCurrPosn);
}
out = m_vecCurrPosn;
CVector CAESound::GetRelativePosition() const {
return GetFrontEnd()
? CAEAudioEnvironment::GetPositionRelativeToCamera(m_vecCurrPosn)
: m_vecCurrPosn;
}

// 0x4EF390
Expand Down Expand Up @@ -288,43 +287,42 @@ void CAESound::CalculateVolume() {
if (GetFrontEnd())
m_fFinalVolume = m_fVolume - m_fSoundHeadRoom;
else {
CVector relativePos;
CAEAudioEnvironment::GetPositionRelativeToCamera(&relativePos, &m_vecCurrPosn);
const auto fDist = relativePos.Magnitude() / m_fSoundDistance;
const auto fAttenuation = CAEAudioEnvironment::GetDistanceAttenuation(fDist);
m_fFinalVolume = CAEAudioEnvironment::GetDirectionalMikeAttenuation(relativePos) + fAttenuation + m_fVolume - m_fSoundHeadRoom;
const auto relPos = CAEAudioEnvironment::GetPositionRelativeToCamera(m_vecCurrPosn);
const auto att = CAEAudioEnvironment::GetDistanceAttenuation(relPos.Magnitude() / m_fSoundDistance);
m_fFinalVolume = CAEAudioEnvironment::GetDirectionalMikeAttenuation(relPos) + att + m_fVolume - m_fSoundHeadRoom;
}
}

// 0x4EFE50
void CAESound::Initialise(int16 bankSlotId, int16 sfxId, CAEAudioEntity* baseAudio, CVector posn, float volume, float maxDistance, float speed, float timeScale,
uint8 ignoredServiceCycles, eSoundEnvironment environmentFlags, float speedVariability, int16 currPlayPosn)
void CAESound::Initialise(
int16 bankSlotId, int16 soundID, CAEAudioEntity* audioEntity, CVector pos, float volume, float rollOffFactor, float relativeFrequency, float doppler,
uint8 frameDelay, uint32 flags, float frequencyVariance, int16 playTime)
{
UnregisterWithPhysicalEntity();

m_nSoundIdInSlot = sfxId;
m_nSoundIdInSlot = soundID;
m_nBankSlotId = bankSlotId;
m_pBaseAudio = baseAudio;
m_pBaseAudio = audioEntity;
m_fVolume = volume;
m_fSoundDistance = maxDistance;
m_fSpeed = speed;
m_fSpeedVariability = speedVariability;
m_fSoundDistance = rollOffFactor;
m_fSpeed = relativeFrequency;
m_fSpeedVariability = frequencyVariance;
m_vecPrevPosn .Set(0.0F, 0.0F, 0.0F);
m_nEvent = AE_UNDEFINED;
m_fMaxVolume = -1.0F;
m_ClientVariable = -1.0F;
m_nLastFrameUpdate = 0;

SetPosition(posn);
SetPosition(pos);

m_fTimeScale = timeScale;
m_fTimeScale = doppler;
m_nSoundLength = -1;
m_nHasStarted = 0;
m_nPlayingState = eSoundState::SOUND_ACTIVE;
m_fSoundHeadRoom = 0.0F;
m_nIgnoredServiceCycles = ignoredServiceCycles;
m_nEnvironmentFlags = environmentFlags;
m_nIgnoredServiceCycles = frameDelay;
m_nEnvironmentFlags = flags;
m_nIsUsed = 1;
m_nCurrentPlayPosition = currPlayPosn;
m_nCurrentPlayPosition = playTime;
m_fFinalVolume = -100.0F;
m_fFrequency = 1.0F;
}
Expand Down
31 changes: 19 additions & 12 deletions source/game_sa/Audio/AESound.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
class CAEAudioEntity;
class CEntity;

using tSoundID = int16;

enum eSoundEnvironment : uint16 {
SOUND_DEFAULT = 0x0,
SOUND_FRONT_END = 0x1,
Expand Down Expand Up @@ -39,8 +41,8 @@ class CAESound {
int16 m_nSoundIdInSlot;
CAEAudioEntity* m_pBaseAudio;
CEntity* m_pPhysicalEntity;
eAudioEvents m_nEvent;
float m_fMaxVolume;
int32 m_nEvent; // Not necessarily `eAudioEvents`, for ex. see `CAEWeaponAudioEntity`
float m_ClientVariable;
float m_fVolume;
float m_fSoundDistance;
float m_fSpeed;
Expand Down Expand Up @@ -98,14 +100,20 @@ class CAESound {

CAESound& operator=(const CAESound& sound);

void Initialise(int16 bankSlotId, int16 sfxId, CAEAudioEntity* baseAudio, CVector posn, float volume,
float maxDistance = 1.0f,
float speed = 1.0f,
float timeScale = 1.0f,
uint8 ignoredServiceCycles = 0,
eSoundEnvironment environmentFlags = static_cast<eSoundEnvironment>(0),
float speedVariability = 0,
int16 currPlayPosn = 0);
void Initialise(
int16 bankSlotId,
int16 soundID,
CAEAudioEntity* audioEntity,
CVector pos,
float volume,
float rollOffFactor = 1.f,
float relativeFrequency = 1.f, // Speed
float doppler = 1.f,
uint8 frameDelay = 0,
uint32 flags = 0,
float frequencyVariance = 0.f,
int16 playTime = 0
);

void UnregisterWithPhysicalEntity();
void StopSound();
Expand All @@ -124,8 +132,7 @@ class CAESound {
bool GetForcedFront() const { return m_bForcedFront; }
void SetIndividualEnvironment(uint16 envFlag, uint16 bEnabled); // pass eSoundEnvironment as envFlag
void UpdatePlayTime(int16 soundLength, int16 loopStartTime, int16 playProgress);
void GetRelativePosition(CVector& out) const;
CVector GetRelativePosition() const { CVector out; GetRelativePosition(out); return out; } // NOTSA
CVector GetRelativePosition() const;
void CalculateFrequency();
void UpdateFrequency();
float GetRelativePlaybackFrequencyWithDoppler();
Expand Down
5 changes: 4 additions & 1 deletion source/game_sa/Audio/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ void CAudioEngine::InjectHooks() {
bool CAudioEngine::Initialise() {
CLoadingScreen::Pause();

// NOTSA: Initialize AudioUtility before `AEAudioHardware` to avoid crash (Division by zero in `GetCurrentTimeInMS`)
CAEAudioUtility::StaticInitialise();

if (!AEAudioHardware.Initialise()) {
NOTSA_LOG_ERR("Failed to initialise Audio Hardware");
return false;
Expand Down Expand Up @@ -138,7 +141,7 @@ bool CAudioEngine::Initialise() {

m_FrontendAE.Initialise();
CAudioEngine::SetEffectsFaderScalingFactor(0.0f);
CAEAudioUtility::StaticInitialise();
//CAEAudioUtility::StaticInitialise(); // Initialized above
CAEPedAudioEntity::StaticInitialise();
CAEPedSpeechAudioEntity::StaticInitialise();
CAEVehicleAudioEntity::StaticInitialise();
Expand Down
96 changes: 96 additions & 0 deletions source/game_sa/Audio/Enums/SoundIDs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#pragma once

using tSoundID = int16;

enum eGenrlWeaponSoundID : tSoundID { // GENRL_WEAPONS
SND_GENRL_WEAPONS_UNK = -1,
SND_GENRL_WEAPONS_9MM1SHOT_L = 0x0,
SND_GENRL_WEAPONS_9MM1SHOT_R = 0x1,
SND_GENRL_WEAPONS_9MM1TAIL = 0x2,
SND_GENRL_WEAPONS_AK_SHOT_L = 0x3,
SND_GENRL_WEAPONS_AK_SHOT_R = 0x4,
SND_GENRL_WEAPONS_AK_TAIL_L = 0x5,
SND_GENRL_WEAPONS_EAGLE_SHOT_L = 0x6,
SND_GENRL_WEAPONS_EAGLE_SHOT_R = 0x7,
SND_GENRL_WEAPONS_EAGLE_TAIL_L = 0x8,
SND_GENRL_WEAPONS_FIRE_EXT = 0x9,
SND_GENRL_WEAPONS_GAS_LOOP = 0xA,
SND_GENRL_WEAPONS_MINIGUN_SHOT_L = 0xB,
SND_GENRL_WEAPONS_MINIGUN_SHOT_R = 0xC,
SND_GENRL_WEAPONS_MINIGUN_TAIL = 0xD,
SND_GENRL_WEAPONS_MINIGUNEMPTY = 0xE,
SND_GENRL_WEAPONS_MINIGUNHIGHS = 0xF,
SND_GENRL_WEAPONS_MINIGUNLOWS = 0x10,
SND_GENRL_WEAPONS_MP5SHOT_L = 0x11,
SND_GENRL_WEAPONS_MP5SHOT_R = 0x12,
SND_GENRL_WEAPONS_PARACHUTE_WIND_LOOP_A = 0x13,
SND_GENRL_WEAPONS_PARACHUTE_WIND_LOOP_B = 0x14,
SND_GENRL_WEAPONS_SHOTGUN_SHOT_L = 0x15,
SND_GENRL_WEAPONS_SHOTGUN_SHOT_R = 0x16,
SND_GENRL_WEAPONS_SHOTGUN_TAIL_R = 0x17,
SND_GENRL_WEAPONS_SILENCED_SHOT_L = 0x18,
SND_GENRL_WEAPONS_SILENCED_SHOT_R = 0x19,
SND_GENRL_WEAPONS_SNIPER_SHOT_L = 0x1A,
SND_GENRL_WEAPONS_SNIPER_SHOT_R = 0x1B,
SND_GENRL_WEAPONS_SPRAY_PAINT = 0x1C,
SND_GENRL_WEAPONS_9MM1DRY = 0x1D,
SND_GENRL_WEAPONS_9MM1LOWS = 0x1E,
SND_GENRL_WEAPONS_AK_A = 0x1F,
SND_GENRL_WEAPONS_AK_B = 0x20,
SND_GENRL_WEAPONS_AK_DRYFIRE = 0x21,
SND_GENRL_WEAPONS_BASEBALL_BAT = 0x22,
SND_GENRL_WEAPONS_BAT_STRIKE = 0x23,
SND_GENRL_WEAPONS_BODY_PUNCH1 = 0x24,
SND_GENRL_WEAPONS_BODY_PUNCH2 = 0x25,
SND_GENRL_WEAPONS_BODY_PUNCH3 = 0x26,
SND_GENRL_WEAPONS_BODY_PUNCH4 = 0x27,
SND_GENRL_WEAPONS_BOX_FACE1 = 0x28,
SND_GENRL_WEAPONS_BOX_FACE2 = 0x29,
SND_GENRL_WEAPONS_BOX_FACE3 = 0x2A,
SND_GENRL_WEAPONS_BOX_FACE4 = 0x2B,
SND_GENRL_WEAPONS_BRASS_KNUCKLES = 0x2C,
SND_GENRL_WEAPONS_CAMERA = 0x2D,
SND_GENRL_WEAPONS_CANE_STRIKE = 0x2E,
SND_GENRL_WEAPONS_CANE_SWISH = 0x2F,
SND_GENRL_WEAPONS_CLUB_STRIKE = 0x30,
SND_GENRL_WEAPONS_DETONATOR_BEEP = 0x31,
SND_GENRL_WEAPONS_DILDO = 0x32,
SND_GENRL_WEAPONS_EAGLE_B = 0x33,
SND_GENRL_WEAPONS_EAGLE_DRYFIRE = 0x34,
SND_GENRL_WEAPONS_EAGLE_LOWS = 0x35,
SND_GENRL_WEAPONS_FLOWER_STRIKE = 0x36,
SND_GENRL_WEAPONS_HANDGUN_A = 0x37,
SND_GENRL_WEAPONS_KATANA_SWORD = 0x38,
SND_GENRL_WEAPONS_KNIFE = 0x39,
SND_GENRL_WEAPONS_KNUCKLE = 0x3A,
SND_GENRL_WEAPONS_MARTIAL_STRIKE1 = 0x3B,
SND_GENRL_WEAPONS_MARTIAL_STRIKE2 = 0x3C,
SND_GENRL_WEAPONS_MARTIAL_STRIKE3 = 0x3D,
SND_GENRL_WEAPONS_MARTIAL_STRIKE4 = 0x3E,
SND_GENRL_WEAPONS_MINIGUNOFF = 0x3F,
SND_GENRL_WEAPONS_NIGHT_VISION = 0x40,
SND_GENRL_WEAPONS_PARACHUTE_OPEN = 0x41,
SND_GENRL_WEAPONS_PISTOL_B = 0x42,
SND_GENRL_WEAPONS_POOLCUE = 0x43,
SND_GENRL_WEAPONS_ROCKET_LAUNCH = 0x44,
SND_GENRL_WEAPONS_SAWNOFF_A = 0x45,
SND_GENRL_WEAPONS_SAWNOFF_B = 0x46,
SND_GENRL_WEAPONS_SHOTGUN_A = 0x47,
SND_GENRL_WEAPONS_SHOTGUN_B = 0x48,
SND_GENRL_WEAPONS_SHOTGUN_DRYFIRE = 0x49,
SND_GENRL_WEAPONS_SHOTGUN_LOWS = 0x4A,
SND_GENRL_WEAPONS_SHOVEL = 0x4B,
SND_GENRL_WEAPONS_SILENCED_DRYFIRE = 0x4C,
SND_GENRL_WEAPONS_SILENCED_LOWS = 0x4D,
SND_GENRL_WEAPONS_SMACK_1 = 0x4E,
SND_GENRL_WEAPONS_SMACK_2 = 0x4F,
SND_GENRL_WEAPONS_SMACK_3 = 0x50,
SND_GENRL_WEAPONS_STAB = 0x51,
SND_GENRL_WEAPONS_STOMP1 = 0x52,
SND_GENRL_WEAPONS_TRIGGER = 0x53,
SND_GENRL_WEAPONS_UZI_A = 0x54,
SND_GENRL_WEAPONS_UZI_B = 0x55,
SND_GENRL_WEAPONS_WEAPON_SWIPE = 0x56,
SND_GENRL_WEAPONS_WEAPON_SWIPE_FIST = 0x57,
SND_GENRL_WEAPONS_WEAPON_SWIPE_METAL = 0x58,
};
4 changes: 2 additions & 2 deletions source/game_sa/Audio/entities/AECollisionAudioEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void CAECollisionAudioEntity::ReportGlassCollisionEvent(eAudioEvents glassSoundT

if (time) {
auto& snd = m_tempSound;
snd.m_fMaxVolume = (float)(time + CTimer::GetTimeInMS());
snd.m_ClientVariable = (float)(time + CTimer::GetTimeInMS());
snd.m_nEvent = glassSoundType;
snd.m_bRequestUpdates = true;
}
Expand Down Expand Up @@ -248,7 +248,7 @@ void CAECollisionAudioEntity::ReportWaterSplash(CVector posn, float volume) {
SOUND_REQUEST_UPDATES
);
m_tempSound.m_nEvent = AE_FRONTEND_BACK;
m_tempSound.m_fMaxVolume = static_cast<float>(CTimer::GetTimeInMS() + 166);
m_tempSound.m_ClientVariable = static_cast<float>(CTimer::GetTimeInMS() + 166);
}

// 0x4DAE40
Expand Down
6 changes: 2 additions & 4 deletions source/game_sa/Audio/entities/AEExplosionAudioEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ void CAEExplosionAudioEntity::AddAudioEvent(eAudioEvents audioEvent, CVector& po
speed_b = gfExplosionFrequencyVariations[m_Speed] * sqrt(sqrt(2.0f));
}

CVector relPos;
CAEAudioEnvironment::GetPositionRelativeToCamera(&relPos, &posn);
auto vol1 = CAEAudioEnvironment::GetDistanceAttenuation(relPos.Magnitude() * (1.0f / 12.0f)) + vol0 - 3.0f;
auto vol1 = CAEAudioEnvironment::GetDistanceAttenuation(CAEAudioEnvironment::GetPositionRelativeToCamera(posn).Magnitude() * (1.0f / 12.0f)) + vol0 - 3.0f;
Pirulax marked this conversation as resolved.
Show resolved Hide resolved
auto flags = static_cast<eSoundEnvironment>(SOUND_FORCED_FRONT | SOUND_ROLLED_OFF | SOUND_REQUEST_UPDATES | SOUND_FRONT_END);

sound.Initialise(4, 1, this, { -1.0f, 0.0f, 0.0f }, vol1, 12.0f, speed_a, 1.0f, 0, flags, 0.0f, 0);
Expand All @@ -78,4 +76,4 @@ void CAEExplosionAudioEntity::InjectHooks() {
RH_ScopedInstall(StaticInitialise, 0x5B9A60);
RH_ScopedInstall(AddAudioEvent, 0x4DCBE0);
RH_ScopedVMTInstall(UpdateParameters, 0x4DCB90);
}
}
Loading
Loading