Cleanup audio code + fixes for review

This commit is contained in:
Filip Gawin 2020-02-28 18:34:39 +01:00
parent c88c2115e2
commit 337924c794
4 changed files with 199 additions and 332 deletions

View File

@ -8,6 +8,8 @@
#include "SurfaceTable.h" #include "SurfaceTable.h"
#include "sampman.h" #include "sampman.h"
constexpr int CollisionSoundIntensity = 60;
void void
cAudioCollisionManager::AddCollisionToRequestedQueue() cAudioCollisionManager::AddCollisionToRequestedQueue()
{ {
@ -146,7 +148,8 @@ cAudioManager::SetUpLoopingCollisionSound(cAudioCollision *col, uint8 counter)
uint8 emittingVol = SetLoopingCollisionRequestedSfxFreqAndGetVol(col); uint8 emittingVol = SetLoopingCollisionRequestedSfxFreqAndGetVol(col);
if(emittingVol) { if(emittingVol) {
m_sQueueSample.m_fDistance = Sqrt(col->m_fDistance); m_sQueueSample.m_fDistance = Sqrt(col->m_fDistance);
m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 60.f, m_sQueueSample.m_fDistance); m_sQueueSample.m_bVolume =
ComputeVolume(emittingVol, CollisionSoundIntensity, m_sQueueSample.m_fDistance);
if(m_sQueueSample.m_bVolume) { if(m_sQueueSample.m_bVolume) {
m_sQueueSample.m_counter = counter; m_sQueueSample.m_counter = counter;
m_sQueueSample.m_vecPos = col->m_vecPosition; m_sQueueSample.m_vecPos = col->m_vecPosition;
@ -160,7 +163,7 @@ cAudioManager::SetUpLoopingCollisionSound(cAudioCollision *col, uint8 counter)
m_sQueueSample.m_nLoopEnd = m_sQueueSample.m_nLoopEnd =
SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex);
m_sQueueSample.field_48 = 4.0f; m_sQueueSample.field_48 = 4.0f;
m_sQueueSample.m_fSoundIntensity = 60.0f; m_sQueueSample.m_fSoundIntensity = CollisionSoundIntensity;
m_sQueueSample.field_56 = 0; m_sQueueSample.field_56 = 0;
m_sQueueSample.field_76 = 5; m_sQueueSample.field_76 = 5;
m_sQueueSample.m_bReverbFlag = true; m_sQueueSample.m_bReverbFlag = true;
@ -212,7 +215,8 @@ cAudioManager::SetUpOneShotCollisionSound(cAudioCollision *col)
emittingVol = 40.f * ratio; emittingVol = 40.f * ratio;
if(emittingVol) { if(emittingVol) {
m_sQueueSample.m_fDistance = Sqrt(col->m_fDistance); m_sQueueSample.m_fDistance = Sqrt(col->m_fDistance);
m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 60.f, m_sQueueSample.m_fDistance); m_sQueueSample.m_bVolume =
ComputeVolume(emittingVol, CollisionSoundIntensity, m_sQueueSample.m_fDistance);
if(m_sQueueSample.m_bVolume) { if(m_sQueueSample.m_bVolume) {
m_sQueueSample.m_nSampleIndex = gOneShotCol[s1]; m_sQueueSample.m_nSampleIndex = gOneShotCol[s1];
switch(m_sQueueSample.m_nSampleIndex) { switch(m_sQueueSample.m_nSampleIndex) {
@ -277,7 +281,7 @@ cAudioManager::SetUpOneShotCollisionSound(cAudioCollision *col)
m_sQueueSample.m_nLoopStart = 0; m_sQueueSample.m_nLoopStart = 0;
m_sQueueSample.m_nLoopEnd = -1; m_sQueueSample.m_nLoopEnd = -1;
m_sQueueSample.field_48 = 4.0f; m_sQueueSample.field_48 = 4.0f;
m_sQueueSample.m_fSoundIntensity = 60.0f; m_sQueueSample.m_fSoundIntensity = CollisionSoundIntensity;
m_sQueueSample.field_56 = 1; m_sQueueSample.field_56 = 1;
m_sQueueSample.m_bReverbFlag = true; m_sQueueSample.m_bReverbFlag = true;
m_sQueueSample.m_bRequireReflection = false; m_sQueueSample.m_bRequireReflection = false;
@ -356,7 +360,7 @@ void
cAudioManager::ReportCollision(CEntity *entity1, CEntity *entity2, uint8 surface1, uint8 surface2, float collisionPower, cAudioManager::ReportCollision(CEntity *entity1, CEntity *entity2, uint8 surface1, uint8 surface2, float collisionPower,
float velocity) float velocity)
{ {
float dist; float distSquared;
CVector v1; CVector v1;
CVector v2; CVector v2;
@ -373,8 +377,8 @@ cAudioManager::ReportCollision(CEntity *entity1, CEntity *entity2, uint8 surface
v2 = entity2->GetPosition(); v2 = entity2->GetPosition();
} }
CVector pos = (v1 + v2) * 0.5f; CVector pos = (v1 + v2) * 0.5f;
dist = GetDistanceSquared(&pos); distSquared = GetDistanceSquared(&pos);
if(dist < SQR(60.f)) { if(distSquared < SQR(CollisionSoundIntensity)) {
m_sCollisionManager.m_sQueue.m_pEntity1 = entity1; m_sCollisionManager.m_sQueue.m_pEntity1 = entity1;
m_sCollisionManager.m_sQueue.m_pEntity2 = entity2; m_sCollisionManager.m_sQueue.m_pEntity2 = entity2;
m_sCollisionManager.m_sQueue.m_bSurface1 = surface1; m_sCollisionManager.m_sQueue.m_bSurface1 = surface1;
@ -382,7 +386,7 @@ cAudioManager::ReportCollision(CEntity *entity1, CEntity *entity2, uint8 surface
m_sCollisionManager.m_sQueue.m_fIntensity1 = collisionPower; m_sCollisionManager.m_sQueue.m_fIntensity1 = collisionPower;
m_sCollisionManager.m_sQueue.m_fIntensity2 = velocity; m_sCollisionManager.m_sQueue.m_fIntensity2 = velocity;
m_sCollisionManager.m_sQueue.m_vecPosition = pos; m_sCollisionManager.m_sQueue.m_vecPosition = pos;
m_sCollisionManager.m_sQueue.m_fDistance = dist; m_sCollisionManager.m_sQueue.m_fDistance = distSquared;
m_sCollisionManager.AddCollisionToRequestedQueue(); m_sCollisionManager.AddCollisionToRequestedQueue();
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -53,8 +53,8 @@ enum eScriptSounds : int16
SCRIPT_SOUND_CHINATOWN_RESTAURANT_L = 43, SCRIPT_SOUND_CHINATOWN_RESTAURANT_L = 43,
SCRIPT_SOUND_CIPRIANI_RESAURANT_S = 44, SCRIPT_SOUND_CIPRIANI_RESAURANT_S = 44,
SCRIPT_SOUND_CIPRIANI_RESAURANT_L = 45, SCRIPT_SOUND_CIPRIANI_RESAURANT_L = 45,
SCRIPT_SOUND_46 = 46, SCRIPT_SOUND_46_S = 46,
SCRIPT_SOUND_47 = 47, SCRIPT_SOUND_47_L = 47,
SCRIPT_SOUND_MARCO_BISTRO_S = 48, SCRIPT_SOUND_MARCO_BISTRO_S = 48,
SCRIPT_SOUND_MARCO_BISTRO_L = 49, SCRIPT_SOUND_MARCO_BISTRO_L = 49,
SCRIPT_SOUND_AIRPORT_LOOP_S = 50, SCRIPT_SOUND_AIRPORT_LOOP_S = 50,
@ -224,9 +224,11 @@ static_assert(sizeof(tPedComment) == 28, "tPedComment: error");
class cPedComments class cPedComments
{ {
public: public:
tPedComment m_asPedComments[2][20]; static constexpr int pedCommentsBanks = 2;
uint8 indexMap[2][20]; static constexpr int pedCommentsSlots = 20;
uint8 nrOfCommentsInBank[2]; tPedComment m_asPedComments[pedCommentsBanks][pedCommentsSlots];
uint8 indexMap[pedCommentsBanks][pedCommentsSlots];
uint8 nrOfCommentsInBank[pedCommentsBanks];
uint8 activeBank; uint8 activeBank;
uint8 gap_1163[1]; uint8 gap_1163[1];
@ -607,10 +609,20 @@ public:
uint8 ComputeEmittingVolume(uint8 emittingVolume, float intensity, uint8 ComputeEmittingVolume(uint8 emittingVolume, float intensity,
float dist); /// ok float dist); /// ok
public: public:
static const int channels = ARRAY_SIZE(cAudioManager::m_asActiveSamples); static constexpr int channels = ARRAY_SIZE(cAudioManager::m_asActiveSamples);
static const int policeChannel = channels + 1; static constexpr int policeChannel = channels + 1;
static const int allChannels = channels + 2; static constexpr int allChannels = channels + 2;
static const int maxVolume = 127; static constexpr int maxVolume = 127;
static constexpr int scriptObjectIntensityS = 30;
static constexpr int scriptObjectIntensityL = 80;
static constexpr int bridgeIntensity = 400;
static constexpr int rocketLauncherIntensity = 90;
static constexpr int molotovIntensity = 30;
static constexpr int molotovVolume = 50;
static constexpr int rainOnVehicleIntensity = 22;
static constexpr int reverseGearIntensity = 30;
}; };
static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error"); static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error");

View File

@ -1,27 +1,29 @@
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
#include "main.h" #include "main.h"
#include "Pickups.h"
#include "Camera.h" #include "Camera.h"
#include "Entity.h"
#include "Timer.h"
#include "Shadows.h"
#include "Coronas.h" #include "Coronas.h"
#include "World.h"
#include "ModelIndices.h"
#include "PlayerPed.h"
#include "Object.h"
#include "Pools.h"
#include "Pad.h"
#include "Script.h"
#include "Darkel.h" #include "Darkel.h"
#include "Garages.h" #include "Entity.h"
#include "Explosion.h" #include "Explosion.h"
#include "WaterLevel.h"
#include "SpecialFX.h"
#include "PointLights.h"
#include "Sprite.h"
#include "Font.h" #include "Font.h"
#include "Garages.h"
#include "General.h"
#include "ModelIndices.h"
#include "Object.h"
#include "Pad.h"
#include "Pickups.h"
#include "PlayerPed.h"
#include "PointLights.h"
#include "Pools.h"
#include "Script.h"
#include "Shadows.h"
#include "SpecialFX.h"
#include "Sprite.h"
#include "Timer.h"
#include "WaterLevel.h"
#include "World.h"
CPickup(&CPickups::aPickUps)[NUMPICKUPS] = *(CPickup(*)[NUMPICKUPS])*(uintptr*)0x878C98; CPickup(&CPickups::aPickUps)[NUMPICKUPS] = *(CPickup(*)[NUMPICKUPS])*(uintptr*)0x878C98;
int16 CPickups::NumMessages;// = *(int16*)0x95CC98; int16 CPickups::NumMessages;// = *(int16*)0x95CC98;
@ -693,7 +695,7 @@ CPickups::DoPickUpEffects(CEntity *entity)
CVector &pos = entity->GetPosition(); CVector &pos = entity->GetPosition();
float colorModifier = ((double)(rand() & 0x1F) * 0.015f + 1.0f) * modifiedSin * 0.15f; float colorModifier = ((CGeneral::GetRandomNumber() & 0x1F) * 0.015f + 1.0f) * modifiedSin * 0.15f;
CShadows::StoreStaticShadow( CShadows::StoreStaticShadow(
(uintptr)entity, (uintptr)entity,
SHADOWTYPE_ADDITIVE, SHADOWTYPE_ADDITIVE,
@ -704,9 +706,9 @@ CPickups::DoPickUpEffects(CEntity *entity)
aWeaponReds[colorId] * colorModifier, aWeaponGreens[colorId] * colorModifier, aWeaponBlues[colorId] * colorModifier, aWeaponReds[colorId] * colorModifier, aWeaponGreens[colorId] * colorModifier, aWeaponBlues[colorId] * colorModifier,
4.0f, 1.0f, 40.0f, false, 0.0f); 4.0f, 1.0f, 40.0f, false, 0.0f);
float radius = (rand() & 0xF) * 0.1f + 3.0f; float radius = (CGeneral::GetRandomNumber() & 0xF) * 0.1f + 3.0f;
CPointLights::AddLight(CPointLights::LIGHT_POINT, pos, CVector(0.0f, 0.0f, 0.0f), radius, aWeaponReds[colorId] * modifiedSin / 256.0f, aWeaponGreens[colorId] * modifiedSin / 256.0f, aWeaponBlues[colorId] * modifiedSin / 256.0f, CPointLights::FOG_NONE, true); CPointLights::AddLight(CPointLights::LIGHT_POINT, pos, CVector(0.0f, 0.0f, 0.0f), radius, aWeaponReds[colorId] * modifiedSin / 256.0f, aWeaponGreens[colorId] * modifiedSin / 256.0f, aWeaponBlues[colorId] * modifiedSin / 256.0f, CPointLights::FOG_NONE, true);
float size = (rand() & 0xF) * 0.0005f + 0.6f; float size = (CGeneral::GetRandomNumber() & 0xF) * 0.0005f + 0.6f;
CCoronas::RegisterCorona( (uintptr)entity, CCoronas::RegisterCorona( (uintptr)entity,
aWeaponReds[colorId] * modifiedSin / 2.0f, aWeaponGreens[colorId] * modifiedSin / 2.0f, aWeaponBlues[colorId] * modifiedSin / 2.0f, aWeaponReds[colorId] * modifiedSin / 2.0f, aWeaponGreens[colorId] * modifiedSin / 2.0f, aWeaponBlues[colorId] * modifiedSin / 2.0f,
255, 255,