diff options
Diffstat (limited to 'src/audio')
-rw-r--r-- | src/audio/AudioManager.cpp | 131 | ||||
-rw-r--r-- | src/audio/AudioManager.h | 12 |
2 files changed, 92 insertions, 51 deletions
diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index 6a37e462..f823cf19 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -518,11 +518,11 @@ cAudioManager::AgeCrimes() } void -cAudioManager::CalculateDistance(bool *ptr, float dist) +cAudioManager::CalculateDistance(bool &distCalculated, float dist) { - if(*ptr == false) { + if(!distCalculated) { m_sQueueSample.m_fDistance = Sqrt(dist); - *ptr = true; + distCalculated = true; } } @@ -3181,7 +3181,7 @@ cAudioManager::ProcessAirBrakes(cVehicleParams *params) (automobile->m_fVelocityChangeForAudio > -0.025f || params->m_fVelocityChange <= 0.025f)) return 1; - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); rand = m_anRandomTable[0] % 10 + 70; m_sQueueSample.m_bVolume = ComputeVolume(rand, 30.0f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { @@ -3273,7 +3273,7 @@ cAudioManager::ProcessBoatEngine(cVehicleParams *params) if(params->m_fDistance < 2500.f) { boat = (CBoat *)params->m_pVehicle; if(params->m_nIndex == REEFER) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); m_sQueueSample.m_bVolume = ComputeVolume(80, 50.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_counter = 39; @@ -3379,7 +3379,7 @@ cAudioManager::ProcessBoatEngine(cVehicleParams *params) m_sQueueSample.m_nSampleIndex = SFX_POLICE_BOAT_ACCEL; } } - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 50.f, m_sQueueSample.m_fDistance); if(!m_sQueueSample.m_bVolume) return 1; m_sQueueSample.m_nFrequency += (m_sQueueSample.m_nEntityIndex << 16) % 1000; @@ -3418,7 +3418,7 @@ cAudioManager::ProcessBoatMovingOverWater(cVehicleParams *params) velocityChange = min(0.75f, velocityChange); multiplier = (velocityChange - 0.0005f) * 1.3342f; - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); vol = (30.f * multiplier); m_sQueueSample.m_bVolume = ComputeVolume(vol, 50.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { @@ -3448,13 +3448,13 @@ void cAudioManager::ProcessBridge() { float dist; - bool something = false; + bool distCalculated = false; if(CBridge::pLiftRoad) { m_sQueueSample.m_vecPos = CBridge::pLiftRoad->GetPosition(); dist = GetDistanceSquared(&m_sQueueSample.m_vecPos); if(dist < 202500.0f) { - CalculateDistance(&something, dist); + CalculateDistance(distCalculated, dist); switch(CBridge::State) { case STATE_BRIDGE_LOCKED: case STATE_LIFT_PART_IS_UP: @@ -3584,7 +3584,7 @@ cAudioManager::ProcessCarBombTick(cVehicleParams *params) if(params->m_fDistance >= 1600.f) return 0; automobile = (CAutomobile *)params->m_pVehicle; if(automobile->bEngineOn && automobile->m_bombType == CARBOMB_TIMEDACTIVE) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); m_sQueueSample.m_bVolume = ComputeVolume(60, 40.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_counter = 35; @@ -3750,7 +3750,7 @@ cAudioManager::ProcessEngineDamage(cVehicleParams *params) m_sQueueSample.field_16 = 7; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_CAR_ON_FIRE); } - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); m_sQueueSample.m_bVolume = ComputeVolume(emittingVolume, 40.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_counter = 28; @@ -3933,12 +3933,12 @@ void cAudioManager::ProcessFireHydrant() { float distSquared; - bool something = false; + bool distCalculated = false; m_sQueueSample.m_vecPos = *(CVector *)((size_t)m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_pEntity + 52); distSquared = GetDistanceSquared(&m_sQueueSample.m_vecPos); if(distSquared < 1225.f) { - CalculateDistance(&something, distSquared); + CalculateDistance(distCalculated, distSquared); m_sQueueSample.m_bVolume = ComputeVolume(40, 35.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_counter = 0; @@ -4155,7 +4155,7 @@ cAudioManager::ProcessHelicopter(cVehicleParams *params) if(gHeliSfxRanges[0].m_fMaxDistance * gHeliSfxRanges[0].m_fMaxDistance <= params->m_fDistance) return 0; - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); heli = (CHeli *)params->m_pVehicle; for(uint32 i = 0; i < 3; i++) { MaxDist = gHeliSfxRanges[i].m_fMaxDistance; @@ -4254,7 +4254,7 @@ cAudioManager::ProcessJumbo(cVehicleParams *params) float position; if(params->m_fDistance < 193600.0f) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); plane = (CPlane *)params->m_pVehicle; DoJumboVolOffset(); position = PlanePathPosition[plane->m_nPlaneId]; @@ -5214,7 +5214,7 @@ cAudioManager::ProcessModelCarEngine(cVehicleParams *params) else emittingVol = 90; if(emittingVol) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 30.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { @@ -5537,7 +5537,7 @@ cAudioManager::ProcessPedHeadphones(cPedParams *params) if(params->m_fDistance < 49.f) { ped = params->m_pPed; if(!ped->bIsAimingGun || ped->m_bodyPartBleeding != 2) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); if(ped->bInVehicle && ped->m_nPedState == PED_DRIVING) { emittingVol = 10; veh = ped->m_pMyVehicle; @@ -6492,7 +6492,6 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * float relativeVelocityChange; float accelerationMultipler; uint8 wheelInUseCounter; - uint8 i; float time; int baseFreq; uint8 vol; @@ -6540,19 +6539,15 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * velocityChange = params->m_fVelocityChange; relativeVelocityChange = 2.0f * velocityChange / transmission->fMaxVelocity; - accelerationMultipler = 0.0f; - - if(relativeVelocityChange > 1.0f) accelerationMultipler = relativeVelocityChange; - + accelerationMultipler = min(min(1.f, relativeVelocityChange), 0.f); gasPedalAudio = accelerationMultipler; currentGear = params->m_pVehicle->m_nCurrentGear; + if(transmission->nDriveType == '4') { wheelInUseCounter = 0; - i = 0; - do { + for (uint8 i = 0; i < 4; i++){ if(automobile->m_aWheelState[i]) ++wheelInUseCounter; - ++i; - } while(i < 4); + } if(wheelInUseCounter > 2) lostTraction = 1; } else if(transmission->nDriveType == 'F') { if((automobile->m_aWheelState[0] || automobile->m_aWheelState[2]) && @@ -6623,7 +6618,8 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile * if(!nCruising) { if(accelerateState < 150 || !automobile->m_nWheelsOnGround || automobile->bIsHandbrakeOn || lostTraction || - currentGear < 2u && velocityChange - automobile->m_fVelocityChangeForAudio >= 0.01f) { + currentGear < 2 && + velocityChange - automobile->m_fVelocityChangeForAudio < 0.01f) { // here could be used abs if(!automobile->m_nWheelsOnGround || automobile->bIsHandbrakeOn || lostTraction) { if(!automobile->m_nWheelsOnGround && automobile->m_nDriveWheelsOnGround || (automobile->bIsHandbrakeOn && !bHandbrakeOnLastFrame || @@ -6995,7 +6991,7 @@ cAudioManager::ProcessRainOnVehicle(cVehicleParams *params) veh = params->m_pVehicle; if(veh->m_bRainAudioCounter >= 2) { veh->m_bRainAudioCounter = 0; - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); emittingVol = 30.f * CWeather::Rain; m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 22.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { @@ -7044,7 +7040,7 @@ cAudioManager::ProcessReverseGear(cVehicleParams *params) if(params->m_fDistance >= 900.f) return 0; veh = params->m_pVehicle; if(veh->bEngineOn && (veh->m_fGasPedal < 0.0f || !veh->m_nCurrentGear)) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); automobile = (CAutomobile *)params->m_pVehicle; if(automobile->m_nWheelsOnGround) { modificator = params->m_fVelocityChange / params->m_pTransmission->fMaxReverseVelocity; @@ -7262,7 +7258,7 @@ cAudioManager::ProcessTrainNoise(cVehicleParams *params) if(params->m_fDistance >= 90000.f) return 0; if(params->m_fVelocityChange > 0.0f) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); train = (CTrain *)params->m_pVehicle; speedMultipler = min(1.0f, train->m_fSpeed * 250.f / 51.f); emittingVol = (75.f * speedMultipler); @@ -7327,7 +7323,7 @@ cAudioManager::ProcessVehicle(CVehicle *veh) cVehicleParams params; m_sQueueSample.m_vecPos = veh->GetPosition(); - params.m_bDistancECalculated = 0; + params.m_bDistanceCalculated = false; params.m_fDistance = GetDistanceSquared(&m_sQueueSample.m_vecPos); params.m_pVehicle = veh; params.m_pTransmission = nil; @@ -7420,7 +7416,7 @@ cAudioManager::ProcessVehicleDoors(cVehicleParams *params) if(params->m_fDistance >= 1600.f) return 0; automobile = (CAutomobile *)params->m_pVehicle; - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); for(int32 i = 0; i < 6; i++) { if(automobile->Damage.GetDoorStatus(i) == 2) { doorState = automobile->Doors[i].m_nDoorState; @@ -7476,7 +7472,7 @@ cAudioManager::ProcessVehicleHorn(cVehicleParams *params) automobile->m_modelIndex != MI_MRWHOOP) { if(automobile->m_nCarHornTimer) { if(!params->m_pVehicle->m_status) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); m_sQueueSample.m_bVolume = ComputeVolume(80, 40.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_counter = 4; @@ -7508,7 +7504,7 @@ cAudioManager::ProcessVehicleHorn(cVehicleParams *params) automobile->field_22D = (LOBYTE(m_nTimeOfRecentCrime) + LOBYTE(m_sQueueSample.m_nEntityIndex)) & 7; if(hornPatternsArray[automobile->field_22D][44 - automobile->m_nCarHornTimer]) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); m_sQueueSample.m_bVolume = ComputeVolume(80, 40.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_counter = 4; @@ -7554,7 +7550,7 @@ cAudioManager::ProcessVehicleReverseWarning(cVehicleParams *params) if(params->m_fDistance >= 2500.f) return 0; if(veh->bEngineOn && veh->m_fGasPedal < 0.0f) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); m_sQueueSample.m_bVolume = ComputeVolume(60, 50.f, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_counter = 12; @@ -7596,7 +7592,7 @@ cAudioManager::ProcessVehicleRoadNoise(cVehicleParams *params) if(params->m_pVehicle->m_vecMoveSpeed.z) { velocity = Abs(params->m_fVelocityChange); if(velocity > 0.0f) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); emittingVol = 30.f * min(1.f, velocity / (0.5f * params->m_pTransmission->fMaxVelocity)); m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 95.f, m_sQueueSample.m_fDistance); @@ -7636,11 +7632,55 @@ cAudioManager::ProcessVehicleRoadNoise(cVehicleParams *params) return 1; } -WRAPPER void -cAudioManager::ProcessVehicleSirenOrAlarm(void *) +cAudioManager::ProcessVehicleSirenOrAlarm(cVehicleParams *params) { - EAXJMP(0x56C420); + if(params->m_fDistance < 12100.f) { + CVehicle *veh = params->m_pVehicle; + if(veh->m_bSirenOrAlarm == 0 && veh->m_nAlarmState <= 0) return; + + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); + m_sQueueSample.m_bVolume = ComputeVolume(80, 110.f, m_sQueueSample.m_fDistance); + if(m_sQueueSample.m_bVolume) { + m_sQueueSample.m_counter = 5; + if(UsesSiren(params->m_nIndex)) { + if(params->m_pVehicle->m_status == STATUS_ABANDONED) return; + if(veh->m_nCarHornTimer && params->m_nIndex != FIRETRUK) { + m_sQueueSample.m_nSampleIndex = SFX_SIREN_FAST; + if(params->m_nIndex == FBICAR) + m_sQueueSample.m_nFrequency = 16113; + else + m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(SFX_SIREN_FAST); + m_sQueueSample.m_counter = 60; + } else { + m_sQueueSample.m_nSampleIndex = + CarSounds[params->m_nIndex].m_nSirenOrAlarmSample; + m_sQueueSample.m_nFrequency = + CarSounds[params->m_nIndex].m_nSirenOrAlarmFrequency; + } + } else { + m_sQueueSample.m_nSampleIndex = CarSounds[params->m_nIndex].m_nSirenOrAlarmSample; + m_sQueueSample.m_nFrequency = CarSounds[params->m_nIndex].m_nSirenOrAlarmFrequency; + } + m_sQueueSample.m_bBankIndex = 0; + m_sQueueSample.m_bIsDistant = 0; + m_sQueueSample.field_16 = 1; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_bEmittingVolume = 80; + m_sQueueSample.m_nLoopStart = + SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.field_48 = 7.0f; + m_sQueueSample.m_fSoundIntensity = 110.0f; + m_sQueueSample.field_56 = 0; + m_sQueueSample.field_76 = 5; + m_sQueueSample.m_bReverbFlag = 1; + m_sQueueSample.m_bRequireReflection = 0; + AddSampleToRequestedQueue(); + return; + } + } } void @@ -7655,7 +7695,7 @@ cAudioManager::ProcessVehicleSkidding(cVehicleParams *params) if(params->m_fDistance >= 1600.f) return; automobile = (CAutomobile *)params->m_pVehicle; if(!automobile->m_nWheelsOnGround) return; - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); for(int32 i = 0; i < 4; i++) { if(!automobile->m_aWheelState[i] || automobile->Damage.GetWheelStatus(i) == WHEEL_STATUS_MISSING) continue; @@ -7844,7 +7884,7 @@ cAudioManager::ProcessWetRoadNoise(cVehicleParams *params) if(params->m_pVehicle->m_vecMoveSpeed.z) { velChange = Abs(params->m_fVelocityChange); if(velChange > 0.f) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); relativeVelocity = min(1.0f, velChange / (0.5f * params->m_pTransmission->fMaxVelocity)); emittingVol = 23.0f * relativeVelocity * CWeather::WetRoads; @@ -8873,14 +8913,14 @@ cAudioManager::SetupPedComments(cPedParams *params, uint32 sound) soundIntensity = 50.f; if(params->m_fDistance < maxDist) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); if(sound != SOUND_PAGER) { switch(sound) { case SOUND_AMMUNATION_WELCOME_1: case SOUND_AMMUNATION_WELCOME_2: case SOUND_AMMUNATION_WELCOME_3: emittingVol = maxVolume; break; default: - if(CWorld::GetIsLineOfSightClear(TheCamera.GetGameCamPosition(), + if(CWorld::GetIsLineOfSightClear(TheCamera.GetPosition(), m_sQueueSample.m_vecPos, 1, 0, 0, 0, 0, 0, 0)) { emittingVol = maxVolume; @@ -8934,14 +8974,14 @@ cAudioManager::SetupPedComments(cPedParams *params, uint32 sound) } if(params->m_fDistance < maxDist) { - CalculateDistance((bool *)params, params->m_fDistance); + CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); if(sound != SOUND_PAGER) { switch(sound) { case SOUND_AMMUNATION_WELCOME_1: case SOUND_AMMUNATION_WELCOME_2: case SOUND_AMMUNATION_WELCOME_3: emittingVol = maxVolume; break; default: - if(CWorld::GetIsLineOfSightClear(TheCamera.GetGameCamPosition(), + if(CWorld::GetIsLineOfSightClear(TheCamera.GetPosition(), m_sQueueSample.m_vecPos, 1, 0, 0, 0, 0, 0, 0)) { emittingVol = maxVolume; @@ -9595,6 +9635,7 @@ InjectHook(0x56C770, &cAudioManager::ProcessVehicleDoors, PATCH_JUMP); InjectHook(0x56C200, &cAudioManager::ProcessVehicleHorn, PATCH_JUMP); InjectHook(0x56C640, &cAudioManager::ProcessVehicleReverseWarning, PATCH_JUMP); InjectHook(0x56A230, &cAudioManager::ProcessVehicleRoadNoise, PATCH_JUMP); +InjectHook(0x56C420, &cAudioManager::ProcessVehicleSirenOrAlarm, PATCH_JUMP); InjectHook(0x56BCB0, &cAudioManager::ProcessVehicleSkidding, PATCH_JUMP); InjectHook(0x575F30, &cAudioManager::ProcessWaterCannon, PATCH_JUMP); InjectHook(0x578370, &cAudioManager::ProcessWeather, PATCH_JUMP); diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index 19809286..7df6dcbe 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -440,11 +440,11 @@ public: void AddSampleToRequestedQueue(); /// ok void AgeCrimes(); /// ok - void CalculateDistance(bool *ptr, float dist); /// ok - bool CheckForAnAudioFileOnCD() const; /// ok - void ClearActiveSamples(); /// ok - void ClearMissionAudio(); /// ok - void ClearRequestedQueue(); /// ok + void CalculateDistance(bool &condition, float dist); /// ok + bool CheckForAnAudioFileOnCD() const; /// ok + void ClearActiveSamples(); /// ok + void ClearMissionAudio(); /// ok + void ClearRequestedQueue(); /// ok int32 ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, float speedMultiplier) const; /// ok int32 ComputePan(float, CVector *); /// ok @@ -640,7 +640,7 @@ public: void ProcessVehicleOneShots(void *); // todo bool ProcessVehicleReverseWarning(cVehicleParams *params); /// ok bool ProcessVehicleRoadNoise(cVehicleParams *params); /// ok - void ProcessVehicleSirenOrAlarm(void *); // todo + void ProcessVehicleSirenOrAlarm(cVehicleParams *params); /// ok void ProcessVehicleSkidding(cVehicleParams *params); /// ok void ProcessWaterCannon(int32); /// ok void ProcessWeather(int32 id); /// ok |