diff options
author | Sergeanur <s.anureev@yandex.ua> | 2021-08-25 08:07:41 +0200 |
---|---|---|
committer | Sergeanur <s.anureev@yandex.ua> | 2021-08-25 08:07:41 +0200 |
commit | 800ab9296056ceeb384985cb223566c981813919 (patch) | |
tree | 53e8190b7bb84a7b960abcec3044ce7cc2d73fbf /src | |
parent | modelinfo bits (diff) | |
parent | Audio: refactoring, type fixes, renaming cAudioManager fields (diff) | |
download | re3-800ab9296056ceeb384985cb223566c981813919.tar re3-800ab9296056ceeb384985cb223566c981813919.tar.gz re3-800ab9296056ceeb384985cb223566c981813919.tar.bz2 re3-800ab9296056ceeb384985cb223566c981813919.tar.lz re3-800ab9296056ceeb384985cb223566c981813919.tar.xz re3-800ab9296056ceeb384985cb223566c981813919.tar.zst re3-800ab9296056ceeb384985cb223566c981813919.zip |
Diffstat (limited to '')
-rw-r--r-- | src/audio/AudioCollision.cpp | 2 | ||||
-rw-r--r-- | src/audio/AudioLogic.cpp | 294 | ||||
-rw-r--r-- | src/audio/AudioManager.cpp | 319 | ||||
-rw-r--r-- | src/audio/AudioManager.h | 27 | ||||
-rw-r--r-- | src/audio/MusicManager.cpp | 12 | ||||
-rw-r--r-- | src/audio/MusicManager.h | 2 | ||||
-rw-r--r-- | src/audio/PolRadio.cpp | 12 | ||||
-rw-r--r-- | src/core/Cam.cpp | 2 | ||||
-rw-r--r-- | src/core/config.h | 6 | ||||
-rw-r--r-- | src/peds/PedIK.cpp | 4 | ||||
-rw-r--r-- | src/peds/PlayerPed.cpp | 11 | ||||
-rw-r--r-- | src/vehicles/Automobile.cpp | 2 |
12 files changed, 425 insertions, 268 deletions
diff --git a/src/audio/AudioCollision.cpp b/src/audio/AudioCollision.cpp index 147db001..4b37d83b 100644 --- a/src/audio/AudioCollision.cpp +++ b/src/audio/AudioCollision.cpp @@ -18,7 +18,7 @@ cAudioManager::ReportCollision(CEntity *entity1, CEntity *entity2, uint8 surface CVector v1; CVector v2; - if(!m_bIsInitialised || m_nCollisionEntity < 0 || m_nUserPause || + if(!m_bIsInitialised || m_nCollisionEntity < 0 || m_bIsPaused || (velocity < 0.0016f && collisionPower < 0.01f)) return; diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp index d215724c..aa69a949 100644 --- a/src/audio/AudioLogic.cpp +++ b/src/audio/AudioLogic.cpp @@ -226,9 +226,9 @@ cAudioManager::PostTerminateGameSpecificShutdown() void cAudioManager::ResetAudioLogicTimers(uint32 timer) { - for (int32 i = 0; i < m_nAudioEntitiesTotal; i++) { - if (m_asAudioEntities[m_anAudioEntityIndices[i]].m_nType == AUDIOTYPE_PHYSICAL) { - CPed *ped = (CPed *)m_asAudioEntities[m_anAudioEntityIndices[i]].m_pEntity; + for (uint32 i = 0; i < m_nAudioEntitiesCount; i++) { + if (m_asAudioEntities[m_aAudioEntityOrderList[i]].m_nType == AUDIOTYPE_PHYSICAL) { + CPed *ped = (CPed *)m_asAudioEntities[m_aAudioEntityOrderList[i]].m_pEntity; if (ped->IsPed()) { ped->m_lastSoundStart = timer; ped->m_soundStart = timer + m_anRandomTable[0] % 3000; @@ -296,8 +296,8 @@ cAudioManager::ProcessSpecial() CPlayerPed *playerPed; CVehicle *remoteVehicle; - if (m_nUserPause) { - if (!m_nPreviousUserPause) { + if (m_bIsPaused) { + if (!m_bWasPaused) { SampleManager.SetEffectsFadeVolume(MAX_VOLUME); SampleManager.SetMusicFadeVolume(MAX_VOLUME); } @@ -322,45 +322,45 @@ cAudioManager::ProcessEntity(int32 id) m_sQueueSample.m_nEntityIndex = id; switch (m_asAudioEntities[id].m_nType) { case AUDIOTYPE_PHYSICAL: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessPhysical(id); } break; case AUDIOTYPE_EXPLOSION: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessExplosions(id); } break; case AUDIOTYPE_FIRE: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessFires(id); } break; case AUDIOTYPE_WEATHER: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); if(CGame::currArea == AREA_MAIN_MAP || CGame::currArea == AREA_EVERYWHERE) ProcessWeather(id); } break; /* case AUDIOTYPE_CRANE: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessCrane(); } break;*/ case AUDIOTYPE_SCRIPTOBJECT: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessScriptObject(id); } break; #ifdef GTA_BRIDGE case AUDIOTYPE_BRIDGE: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessBridge(); } @@ -371,35 +371,35 @@ cAudioManager::ProcessEntity(int32 id) ProcessFrontEnd(); break; case AUDIOTYPE_PROJECTILE: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessProjectiles(); } break; case AUDIOTYPE_GARAGE: - if (!m_nUserPause) + if (!m_bIsPaused) ProcessGarages(); break; case AUDIOTYPE_FIREHYDRANT: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessFireHydrant(); } break; case AUDIOTYPE_WATERCANNON: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessWaterCannon(id); } break; case AUDIOTYPE_ESCALATOR: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessEscalators(); } break; case AUDIOTYPE_EXTRA_SOUNDS: - if (!m_nUserPause) { + if (!m_bIsPaused) { SET_SOUND_REVERB(TRUE); ProcessExtraSounds(); } @@ -683,7 +683,7 @@ const eSfxSample aEngineSounds[][2] = { }; bool8 bPlayerJustEnteredCar; -const bool8 hornPatternsArray[8][44] = { +const bool8 HornPattern[8][44] = { {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}, {FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, @@ -1723,11 +1723,11 @@ cAudioManager::ProcessVehicleEngine(cVehicleParams& params) switch (transmission->nDriveType) { case '4': if (params.m_VehicleType == VEHICLE_TYPE_BIKE) { - for (int i = 0; i < 2; i++) + for (uint8 i = 0; i < 2; i++) if (wheelState[i] == WHEEL_STATE_SPINNING) traction += 0.1f; } else { - for (int i = 0; i < 4; i++) + for (uint8 i = 0; i < 4; i++) if (wheelState[i] == WHEEL_STATE_SPINNING) traction += 0.05f; } @@ -2010,7 +2010,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh static uint8 CurrentPretendGear = 1; static bool8 bLostTractionLastFrame = FALSE; static bool8 bHandbrakeOnLastFrame = FALSE; - static int32 nCruising = 0; + static uint32 nCruising = 0; static bool8 bAccelSampleStopped = TRUE; bool8 lostTraction = FALSE; @@ -2084,7 +2084,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh wheelInUseCounter = 0; for (uint8 i = 0; i < 4; i++) { if (wheelState[i] != WHEEL_STATE_NORMAL) - ++wheelInUseCounter; + wheelInUseCounter++; } if (wheelInUseCounter > 2) lostTraction = TRUE; @@ -2191,7 +2191,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh gasPedalAudio = accelerationMultipler; /*switch (engineSoundType) { case SFX_BANK_MOPED: - ++soundOffset; + soundOffset++; break; case SFX_BANK_HONDA250: soundOffset += 2; @@ -2251,38 +2251,54 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh AddPlayerCarSample(vol, freq, aEngineSounds[engineSoundType - CAR_SFX_BANKS_OFFSET][0], SFX_BANK_0, 52, TRUE); CurrentPretendGear = Max(1, currentGear); - } - else { - if (nCruising == 0){ + } else { + if (nCruising > 0) { +PlayCruising: + bAccelSampleStopped = TRUE; + SampleManager.StopChannel(nChannel); + if (!isMoped && (accelerateState < 150 || wheelsOnGround == 0 || brakeState > 0 || params.m_pVehicle->bIsHandbrakeOn + || lostTraction || currentGear < params.m_pTransmission->nNumberOfGears - 1)) { + nCruising = 0; + } else { + if (accelerateState >= 220 && params.m_fVelocityChange + 0.001f >= velocityChangeForAudio) { + if (nCruising < 800) + nCruising++; + } else if (nCruising > 3) + nCruising--; + freq = 27 * nCruising + freqModifier + 22050; + if (engineSoundType == SFX_BANK_TRUCK) + freq >>= 1; + AddPlayerCarSample(120, freq, soundOffset + SFX_CAR_AFTER_ACCEL_1, engineSoundType, 64, TRUE); + } + } else { stuckInSand = params.m_VehicleType == VEHICLE_TYPE_CAR && ((CAutomobile*)params.m_pVehicle)->bStuckInSand; if (accelerateState < 150 || wheelsOnGround == 0 || params.m_pVehicle->bIsHandbrakeOn || lostTraction || (currentGear < 2 && params.m_fVelocityChange - velocityChangeForAudio < 0.01f) || brakeState > 0) { - - if (((wheelsOnGround && !params.m_pVehicle->bIsHandbrakeOn && !lostTraction ) || stuckInSand) && brakeState <= 0) { - baseFreq = (8000.0f * accelerationMultipler) + 16000; - vol = (25.0f * accelerationMultipler) + 60; - *gasPedalAudioPtr = accelerationMultipler; - } else { + if (((wheelsOnGround == 0 || params.m_pVehicle->bIsHandbrakeOn || lostTraction) && !stuckInSand) || brakeState > 0) { if (wheelsOnGround == 0 && wheelsOnGroundPrev != 0 || (params.m_pVehicle->bIsHandbrakeOn && !bHandbrakeOnLastFrame || lostTraction && !bLostTractionLastFrame) && wheelsOnGround != 0) { *gasPedalAudioPtr *= 0.6f; } freqModifier = 0; - if (engineSoundType != SFX_BANK_GOLF_CART && engineSoundType != SFX_BANK_CAR_CHAINSAW) - baseFreq = (25000.0f * *gasPedalAudioPtr) + 14000; + if (engineSoundType == SFX_BANK_GOLF_CART || engineSoundType == SFX_BANK_CAR_CHAINSAW) + baseFreq = (15000 * *gasPedalAudioPtr) + 14000; else - baseFreq = (15000.0f * *gasPedalAudioPtr) + 14000; + baseFreq = (25000 * *gasPedalAudioPtr) + 14000; vol = (25.0f * *gasPedalAudioPtr) + 60; + } else { + baseFreq = (8000 * accelerationMultipler) + 16000; + vol = (25.0f * accelerationMultipler) + 60; + *gasPedalAudioPtr = accelerationMultipler; } freq = freqModifier + baseFreq; if (engineSoundType == SFX_BANK_TRUCK) - freq /= 2; + freq >>= 1; if (channelUsed) { SampleManager.StopChannel(nChannel); bAccelSampleStopped = TRUE; } if (params.m_pVehicle->bIsDrowning) - vol /= 4; + vol >>= 2; AddPlayerCarSample(vol, freq, aEngineSounds[engineSoundType - CAR_SFX_BANKS_OFFSET][1], SFX_BANK_0, 2, TRUE); } else { TranslateEntity(&m_sQueueSample.m_vecPos, &pos); @@ -2295,16 +2311,18 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh processedAccelSampleStopped = TRUE; bAccelSampleStopped = FALSE; } + if (!channelUsed) { if (!processedAccelSampleStopped) { if (CurrentPretendGear < params.m_pTransmission->nNumberOfGears - 1) - ++CurrentPretendGear; + CurrentPretendGear++; else { nCruising = 1; params.m_pVehicle->bAudioChangingGear = TRUE; goto PlayCruising; } } + gearSoundStartTime = CTimer::GetTimeInMilliseconds(); params.m_pVehicle->bAudioChangingGear = TRUE; #ifdef GTA_PS2 @@ -2312,7 +2330,9 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh #else if (!SampleManager.InitialiseChannel(CHANNEL_PLAYER_VEHICLE_ENGINE, soundOffset + SFX_CAR_ACCEL_1, SFX_BANK_0)) return; +#endif SampleManager.SetChannelLoopCount(CHANNEL_PLAYER_VEHICLE_ENGINE, 1); +#ifndef GTA_PS2 SampleManager.SetChannelLoopPoints(CHANNEL_PLAYER_VEHICLE_ENGINE, 0, -1); #endif } @@ -2327,8 +2347,12 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh #endif freq = GearFreqAdj[CurrentPretendGear] + freqModifier + 22050; if (engineSoundType == SFX_BANK_TRUCK) - freq /= 2; + freq >>= 1; +#ifdef USE_TIME_SCALE_FOR_AUDIO + SampleManager.SetChannelFrequency(nChannel, freq * CTimer::GetTimeScale()); +#else SampleManager.SetChannelFrequency(nChannel, freq); +#endif if (!channelUsed) { #ifdef AUDIO_REVERB SampleManager.SetChannelReverbFlag(nChannel, m_bDynamicAcousticModelingStatus != FALSE); @@ -2336,30 +2360,11 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh SampleManager.StartChannel(nChannel); } } - } else { -PlayCruising: - bAccelSampleStopped = TRUE; - SampleManager.StopChannel(nChannel); - if (!isMoped && (accelerateState < 150 || wheelsOnGround == 0 || brakeState > 0 || params.m_pVehicle->bIsHandbrakeOn - || lostTraction || currentGear < params.m_pTransmission->nNumberOfGears - 1)) { - nCruising = 0; - } else { - if (accelerateState >= 220 && params.m_fVelocityChange + 0.001f >= velocityChangeForAudio) { - if (nCruising < 800) - ++nCruising; - } else if (nCruising > 3) { - --nCruising; - } - freq = 27 * nCruising + freqModifier + 22050; - if (engineSoundType == SFX_BANK_TRUCK) - freq /= 2; - AddPlayerCarSample(120, freq, soundOffset + SFX_CAR_AFTER_ACCEL_1, engineSoundType, 64, TRUE); - } } } LastAccel = accelerateState; - bHandbrakeOnLastFrame = params.m_pVehicle->bIsHandbrakeOn; + bHandbrakeOnLastFrame = !!params.m_pVehicle->bIsHandbrakeOn; bLostTractionLastFrame = lostTraction; } @@ -2406,7 +2411,7 @@ cAudioManager::ProcessVehicleSkidding(cVehicleParams& params) return TRUE; CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); - for (int32 i = 0; i < numWheels; i++) { + for (uint8 i = 0; i < numWheels; i++) { if (wheelStateArr[i] == WHEEL_STATE_NORMAL) continue; transmission = params.m_pTransmission; @@ -2555,7 +2560,7 @@ cAudioManager::ProcessVehicleHorn(cVehicleParams& params) if (veh->m_nCarHornTimer == 44) veh->m_nCarHornPattern = (m_FrameCounter + m_sQueueSample.m_nEntityIndex) & 7; - if (!hornPatternsArray[veh->m_nCarHornPattern][44 - veh->m_nCarHornTimer]) + if (!HornPattern[veh->m_nCarHornPattern][44 - veh->m_nCarHornTimer]) return TRUE; } @@ -2730,7 +2735,7 @@ cAudioManager::ProcessVehicleDoors(cVehicleParams& params) automobile = (CAutomobile *)params.m_pVehicle; CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); - for (int32 i = 0; i < ARRAY_SIZE(automobile->Doors); i++) { + for (uint8 i = 0; i < ARRAY_SIZE(automobile->Doors); i++) { if (automobile->Damage.GetDoorStatus(i) == DOOR_STATUS_SWINGING) { doorState = automobile->Doors[i].m_nDoorState; if (doorState == DOORST_OPEN || doorState == DOORST_CLOSED) { @@ -3449,7 +3454,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) m_sQueueSample.m_nPriority = 1; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_MaxDistance = SOUND_INTENSITY; - ++CrunchOffset; + CrunchOffset++; maxDist = SQR(SOUND_INTENSITY); emittingVol = m_anRandomTable[4] % 20 + 55; CrunchOffset %= 2; @@ -4321,7 +4326,7 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound; narrowSoundRange = TRUE; - ++iSound; + iSound++; m_sQueueSample.m_nPriority = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_MaxDistance = 30.0f; @@ -4966,7 +4971,7 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound; stereo = TRUE; - ++iSound; + iSound++; m_sQueueSample.m_nFrequency = m_anRandomTable[1] % 1000 + 17000; if (param2 == 0) m_sQueueSample.m_nFrequency = (3 * m_sQueueSample.m_nFrequency) / 4; @@ -5101,15 +5106,14 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) AddSampleToRequestedQueue(); if (stereo) { m_sQueueSample.m_nPan = 127; - ++m_sQueueSample.m_nSampleIndex; + m_sQueueSample.m_nSampleIndex++; if (m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_awAudioEvent[i] != SOUND_WEAPON_SHOT_FIRED || weapon->m_eWeaponType != WEAPONTYPE_FLAMETHROWER) { m_sQueueSample.m_nCounter = iSound++; if (iSound > 60) iSound = 21; - } else { - ++m_sQueueSample.m_nCounter; - } + } else + m_sQueueSample.m_nCounter++; AddSampleToRequestedQueue(); } } @@ -8030,18 +8034,16 @@ cPedComments::Add(tPedComment *com) index = m_nIndexMap[m_nActiveBank][NUM_PED_COMMENTS_SLOTS - 1]; if (m_asPedComments[m_nActiveBank][index].m_nVolume > com->m_nVolume) return; - } else { + } else index = m_nCommentsInBank[m_nActiveBank]++; - } m_asPedComments[m_nActiveBank][index] = *com; - uint32 i = 0; + uint8 i = 0; if (index != 0) { for (i = 0; i < index; i++) { - if (m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][i]].m_nVolume < m_asPedComments[m_nActiveBank][index].m_nVolume) { + if (m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][i]].m_nVolume < m_asPedComments[m_nActiveBank][index].m_nVolume) break; - } } if (i < index) @@ -8057,80 +8059,92 @@ cPedComments::Process() uint32 sampleIndex; uint8 actualUsedBank; tPedComment *comment; - bool8 prevUsed = FALSE; static uint8 counter = 0; - static int32 prevSamples[10]; + static int32 prevSamples[10] = { NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE }; - if(AudioManager.m_nUserPause) return; + if(AudioManager.m_bIsPaused) return; if(m_nCommentsInBank[m_nActiveBank]) { for(int i = 0; i < ARRAY_SIZE(prevSamples); i++) { if(m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nSampleIndex == prevSamples[(counter + 1 + i) % ARRAY_SIZE(prevSamples)]) { m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nProcess = -1; - prevUsed = TRUE; - break; + goto PedCommentAlreadyAdded; } } - if(!prevUsed) { - sampleIndex = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nSampleIndex; - if(!SampleManager.IsPedCommentLoaded(sampleIndex)) { + sampleIndex = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nSampleIndex; + switch(SampleManager.IsPedCommentLoaded(sampleIndex)) { // yes, this was a switch + case FALSE: #if defined(GTA_PC) && !defined(FIX_BUGS) - if(!m_bDelay) + if(!m_bDelay) #endif - SampleManager.LoadPedComment(sampleIndex); - } else { - AudioManager.m_sQueueSample.m_nEntityIndex = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nEntityIndex; - AudioManager.m_sQueueSample.m_nCounter = 0; - AudioManager.m_sQueueSample.m_nSampleIndex = sampleIndex; - AudioManager.m_sQueueSample.m_nBankIndex = SFX_BANK_PED_COMMENTS; - AudioManager.m_sQueueSample.m_nPriority = 3; - AudioManager.m_sQueueSample.m_nVolume = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nVolume; - AudioManager.m_sQueueSample.m_fDistance = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_fDistance; - AudioManager.m_sQueueSample.m_nLoopCount = 1; + SampleManager.LoadPedComment(sampleIndex); + break; + case TRUE: + AudioManager.m_sQueueSample.m_nEntityIndex = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nEntityIndex; + AudioManager.m_sQueueSample.m_nCounter = 0; + AudioManager.m_sQueueSample.m_nSampleIndex = sampleIndex; + AudioManager.m_sQueueSample.m_nBankIndex = SFX_BANK_PED_COMMENTS; + AudioManager.m_sQueueSample.m_nPriority = 3; + AudioManager.m_sQueueSample.m_nVolume = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nVolume; + AudioManager.m_sQueueSample.m_fDistance = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_fDistance; + AudioManager.m_sQueueSample.m_nLoopCount = 1; #ifndef GTA_PS2 - AudioManager.m_sQueueSample.m_nLoopStart = 0; - AudioManager.m_sQueueSample.m_nLoopEnd = -1; + AudioManager.m_sQueueSample.m_nLoopStart = 0; + AudioManager.m_sQueueSample.m_nLoopEnd = -1; #endif #ifdef EXTERNAL_3D_SOUND - #ifdef FIX_BUGS - AudioManager.m_sQueueSample.m_nEmittingVolume = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nEmittingVolume; - #else - AudioManager.m_sQueueSample.m_nEmittingVolume = MAX_VOLUME; - #endif // FIX_BUGS + #ifdef FIX_BUGS + AudioManager.m_sQueueSample.m_nEmittingVolume = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nEmittingVolume; + #else + AudioManager.m_sQueueSample.m_nEmittingVolume = MAX_VOLUME; + #endif // FIX_BUGS #endif // EXTERNAL_3D_SOUND - AudioManager.m_sQueueSample.m_fSpeedMultiplier = 3.0f; - AudioManager.m_sQueueSample.m_MaxDistance = 40.0f; - AudioManager.m_sQueueSample.m_bStatic = TRUE; - AudioManager.m_sQueueSample.m_vecPos = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_vecPos; +#ifdef ATTACH_RELEASING_SOUNDS_TO_ENTITIES + // let's disable doppler because if sounds funny as the sound moves + // originally position of ped comment doesn't change so this has no effect anyway + AudioManager.m_sQueueSample.m_fSpeedMultiplier = 0.0f; +#else + AudioManager.m_sQueueSample.m_fSpeedMultiplier = 3.0f; +#endif + AudioManager.m_sQueueSample.m_MaxDistance = 40.0f; + AudioManager.m_sQueueSample.m_bStatic = TRUE; + AudioManager.m_sQueueSample.m_vecPos = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_vecPos; #ifdef AUDIO_REVERB - AudioManager.m_sQueueSample.m_bReverb = TRUE; + AudioManager.m_sQueueSample.m_bReverb = TRUE; #endif // AUDIO_REVERB #ifdef AUDIO_REFLECTIONS - AudioManager.m_sQueueSample.m_bReflections = TRUE; + AudioManager.m_sQueueSample.m_bReflections = TRUE; #endif // AUDIO_REFLECTIONS - AudioManager.m_sQueueSample.m_bIs2D = FALSE; + AudioManager.m_sQueueSample.m_bIs2D = FALSE; #ifdef FIX_BUGS - if (sampleIndex >= SFX_TONI_ANGRY_BUSTED_01 && sampleIndex <= SFX_TONI_WISECRACKING_SHOOT_26) { // check if player sfx - AudioManager.m_sQueueSample.m_bIs2D = TRUE; - AudioManager.m_sQueueSample.m_nPan = 63; - } + #ifndef ATTACH_RELEASING_SOUNDS_TO_ENTITIES + else if (sampleIndex >= SFX_TONI_ANGRY_BUSTED_01 && sampleIndex <= SFX_TONI_WISECRACKING_SHOOT_26) { // check if player sfx + AudioManager.m_sQueueSample.m_bIs2D = TRUE; + AudioManager.m_sQueueSample.m_nPan = 63; + } + #endif // ATTACH_RELEASING_SOUNDS_TO_ENTITIES #endif // FIX_BUGS - AudioManager.m_sQueueSample.m_nFrequency = - SampleManager.GetSampleBaseFrequency(AudioManager.m_sQueueSample.m_nSampleIndex) + AudioManager.RandomDisplacement(750); - if(CTimer::GetIsSlowMotionActive()) AudioManager.m_sQueueSample.m_nFrequency /= 2; - m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nProcess = -1; - prevSamples[counter++] = sampleIndex; - if(counter == 10) counter = 0; - AudioManager.AddSampleToRequestedQueue(); + AudioManager.m_sQueueSample.m_nFrequency = + SampleManager.GetSampleBaseFrequency(AudioManager.m_sQueueSample.m_nSampleIndex) + AudioManager.RandomDisplacement(750); +#ifndef USE_TIME_SCALE_FOR_AUDIO + if (CTimer::GetIsSlowMotionActive()) + AudioManager.m_sQueueSample.m_nFrequency >>= 1; +#endif + m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nProcess = -1; + prevSamples[counter++] = sampleIndex; + if(counter == 10) counter = 0; + AudioManager.AddSampleToRequestedQueue(); #if defined(GTA_PC) && !defined(FIX_BUGS) - m_nDelayTimer = CTimer::GetTimeInMilliseconds(); - m_bDelay = TRUE; + m_nDelayTimer = CTimer::GetTimeInMilliseconds(); + m_bDelay = TRUE; #endif - } + break; + default: + break; } } - +PedCommentAlreadyAdded: // Switch bank if (m_nActiveBank == 0) { actualUsedBank = 0; @@ -8142,7 +8156,7 @@ cPedComments::Process() comment = m_asPedComments[actualUsedBank]; for (uint32 i = 0; i < m_nCommentsInBank[actualUsedBank]; i++) { if (m_asPedComments[actualUsedBank][m_nIndexMap[actualUsedBank][i]].m_nProcess > 0) { - --m_asPedComments[actualUsedBank][m_nIndexMap[actualUsedBank][i]].m_nProcess; + m_asPedComments[actualUsedBank][m_nIndexMap[actualUsedBank][i]].m_nProcess--; Add(&comment[m_nIndexMap[actualUsedBank][i]]); } } @@ -8331,7 +8345,7 @@ cAudioManager::ProcessWaterCannon(int32) { const float SOUND_INTENSITY = 30.0f; - for (int32 i = 0; i < NUM_WATERCANNONS; i++) { + for (uint32 i = 0; i < NUM_WATERCANNONS; i++) { if (CWaterCannons::aCannons[i].m_nId) { m_sQueueSample.m_vecPos = CWaterCannons::aCannons[0].m_avecPos[CWaterCannons::aCannons[i].m_nCur]; float distSquared = GetDistanceSquared(m_sQueueSample.m_vecPos); @@ -9156,13 +9170,13 @@ cAudioManager::ProcessFrontEnd() SET_SOUND_REFLECTION(FALSE); AddSampleToRequestedQueue(); if (stereo) { - ++m_sQueueSample.m_nSampleIndex; + m_sQueueSample.m_nSampleIndex++; m_sQueueSample.m_nCounter = iSound++; m_sQueueSample.m_nPan = 127 - m_sQueueSample.m_nPan; AddSampleToRequestedQueue(); } if (center) { - ++m_sQueueSample.m_nSampleIndex; + m_sQueueSample.m_nSampleIndex++; m_sQueueSample.m_nCounter = iSound++; m_sQueueSample.m_nPan = 63; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); @@ -9227,7 +9241,7 @@ cAudioManager::ProcessProjectiles() uint8 emittingVol; float distSquared; - for (int32 i = 0; i < NUM_PROJECTILES; i++) { + for (uint8 i = 0; i < NUM_PROJECTILES; i++) { if (CProjectileInfo::GetProjectileInfo(i)->m_bInUse) { switch (CProjectileInfo::GetProjectileInfo(i)->m_eWeaponType) { case WEAPONTYPE_TEARGAS: @@ -9371,7 +9385,11 @@ cAudioManager::ProcessGarages() static uint8 iSound = 32; - for (uint32 i = 0; i < CGarages::NumGarages; ++i) { +#ifdef FIX_BUGS + for (uint32 i = 0; i < CGarages::NumGarages; i++) { +#else + for (uint8 i = 0; i < CGarages::NumGarages; i++) { +#endif if (CGarages::aGarages[i].m_eGarageType == GARAGE_NONE) continue; entity = CGarages::aGarages[i].m_pDoor1; @@ -9436,7 +9454,7 @@ cAudioManager::ProcessGarages() break; } } - for (j = 0; j < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_AudioEvents; ++j) { + for (j = 0; j < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_AudioEvents; j++) { switch (m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_awAudioEvent[j]) { case SOUND_GARAGE_DOOR_CLOSED: case SOUND_GARAGE_DOOR_OPENED: @@ -11515,7 +11533,7 @@ const MissionAudioData MissionAudioNameSfxAssoc[] = { int32 FindMissionAudioSfx(const char *name) { - for (uint32 i = 0; MissionAudioNameSfxAssoc[i].m_pName != nil; ++i) { + for (uint32 i = 0; MissionAudioNameSfxAssoc[i].m_pName != nil; i++) { if (!CGeneral::faststricmp(MissionAudioNameSfxAssoc[i].m_pName, name)) return MissionAudioNameSfxAssoc[i].m_nId; } @@ -11527,7 +11545,7 @@ const char * cAudioManager::GetMissionAudioLoadedLabel(uint8 slot) { if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS && m_nMissionAudioSampleIndex[slot] != NO_SAMPLE) { - for (uint32 i = 0; MissionAudioNameSfxAssoc[i].m_pName != nil; ++i) { + for (uint32 i = 0; MissionAudioNameSfxAssoc[i].m_pName != nil; i++) { if (m_nMissionAudioSampleIndex[slot] == MissionAudioNameSfxAssoc[i].m_nId) return MissionAudioNameSfxAssoc[i].m_pName; } @@ -11681,7 +11699,7 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) nFramesForPretendPlaying[slot] = 0; nCheckPlayingDelay[slot] = 0; nFramesUntilFailedLoad[slot] = 0; - } else if (!m_nUserPause) { + } else if (!m_bIsPaused) { if (++nFramesForPretendPlaying[slot] < 90) { m_nMissionAudioPlayStatus[slot] = PLAY_STATUS_PLAYING; } else { @@ -11697,7 +11715,7 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) SetMissionScriptPoliceAudio(m_nMissionAudioSampleIndex[slot]); } else { SampleManager.InitialiseChannel(slot + CHANNEL_MISSION_AUDIO_1, m_nMissionAudioSampleIndex[slot], SFX_BANK_PED_COMMENTS); - if(m_nUserPause) + if (m_bIsPaused) SampleManager.SetChannelFrequency(slot + CHANNEL_MISSION_AUDIO_1, 0); else SampleManager.SetChannelFrequency(slot + CHANNEL_MISSION_AUDIO_1, SampleManager.GetSampleBaseFrequency(m_nMissionAudioSampleIndex[slot])); @@ -11740,7 +11758,7 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) break; } if (MissionScriptAudioUsesPoliceChannel(m_nMissionAudioSampleIndex[slot])) { - if (!m_nUserPause) { + if (!m_bIsPaused) { if (nCheckPlayingDelay[slot]) { --nCheckPlayingDelay[slot]; } else if ((g_bMissionAudioLoadFailed[slot] && m_nMissionAudioFramesToPlay[slot]-- == 0) || GetMissionScriptPoliceAudioPlayingStatus() == PLAY_STATUS_FINISHED) { @@ -11753,8 +11771,8 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) } } } else if (m_bIsMissionAudioPlaying[slot]) { - if(SampleManager.GetChannelUsedFlag(slot + CHANNEL_MISSION_AUDIO_1) || m_nUserPause || m_nPreviousUserPause) { - if(m_nUserPause) + if (SampleManager.GetChannelUsedFlag(slot + CHANNEL_MISSION_AUDIO_1) || m_bIsPaused || m_bWasPaused) { + if (m_bIsPaused) SampleManager.SetChannelFrequency(slot + CHANNEL_MISSION_AUDIO_1, 0); else { @@ -11784,7 +11802,7 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) m_nMissionAudioFramesToPlay[slot] = 0; } } else { - if (m_nUserPause) + if (m_bIsPaused) break; if (nCheckPlayingDelay[slot]--) { if (!SampleManager.GetChannelUsedFlag(slot + CHANNEL_MISSION_AUDIO_1)) diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index 178bbf83..d2b0aa4e 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -25,9 +25,9 @@ cAudioManager::cAudioManager() m_fSpeedOfSound = SPEED_OF_SOUND / TIME_SPENT; m_nTimeSpent = TIME_SPENT; m_nActiveSamples = NUM_CHANNELS_GENERIC; - m_nActiveSampleQueue = 1; + m_nActiveQueue = 1; ClearRequestedQueue(); - m_nActiveSampleQueue = 0; + m_nActiveQueue = 0; ClearRequestedQueue(); ClearActiveSamples(); GenerateIntegerRandomNumberTable(); @@ -36,11 +36,11 @@ cAudioManager::cAudioManager() m_bDynamicAcousticModelingStatus = TRUE; #endif - for (int i = 0; i < NUM_AUDIOENTITIES; i++) { + for (uint32 i = 0; i < NUM_AUDIOENTITIES; i++) { m_asAudioEntities[i].m_bIsUsed = FALSE; - m_anAudioEntityIndices[i] = NUM_AUDIOENTITIES; + m_aAudioEntityOrderList[i] = NUM_AUDIOENTITIES; } - m_nAudioEntitiesTotal = 0; + m_nAudioEntitiesCount = 0; m_FrameCounter = 0; m_bReduceReleasingPriority = FALSE; m_bTimerJustReset = FALSE; @@ -65,7 +65,7 @@ cAudioManager::Initialise() if (m_nActiveSamples <= 1) { Terminate(); } else { - --m_nActiveSamples; + m_nActiveSamples--; #else { m_nActiveSamples = NUM_CHANNELS_GENERIC; @@ -87,10 +87,10 @@ cAudioManager::Terminate() for (uint32 i = 0; i < NUM_AUDIOENTITIES; i++) { m_asAudioEntities[i].m_bIsUsed = FALSE; - m_anAudioEntityIndices[i] = ARRAY_SIZE(m_anAudioEntityIndices); + m_aAudioEntityOrderList[i] = ARRAY_SIZE(m_aAudioEntityOrderList); } - m_nAudioEntitiesTotal = 0; + m_nAudioEntitiesCount = 0; m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal = 0; PreTerminateGameSpecificShutdown(); @@ -116,8 +116,8 @@ cAudioManager::Service() m_bTimerJustReset = FALSE; } if (m_bIsInitialised) { - m_nPreviousUserPause = m_nUserPause; - m_nUserPause = CTimer::GetIsUserPaused(); + m_bWasPaused = m_bIsPaused; + m_bIsPaused = CTimer::GetIsUserPaused(); #ifdef AUDIO_REFLECTIONS UpdateReflections(); #endif @@ -135,8 +135,47 @@ cAudioManager::CreateEntity(eAudioType type, void *entity) return AEHANDLE_ERROR_NOENTITY; if (type >= TOTAL_AUDIO_TYPES) return AEHANDLE_ERROR_BADAUDIOTYPE; - for (uint32 i = 0; i < ARRAY_SIZE(m_asAudioEntities); i++) { + +#ifdef FIX_BUGS + // since sound could still play after entity deletion let's make sure we don't override one that is in use + // find all the free entity IDs that are being used by queued samples + int32 stillUsedEntities[NUM_CHANNELS_GENERIC * NUM_SOUND_QUEUES]; + uint32 stillUsedEntitiesCount = 0; + + for (uint8 i = 0; i < NUM_SOUND_QUEUES; i++) + for (uint8 j = 0; j < m_nRequestedCount[i]; j++) { + tSound &sound = m_aRequestedQueue[i][m_aRequestedOrderList[i][j]]; + if (sound.m_nEntityIndex < 0) continue; + if (!m_asAudioEntities[sound.m_nEntityIndex].m_bIsUsed) { + bool found = false; + for (uint8 k = 0; k < stillUsedEntitiesCount; k++) { + if (stillUsedEntities[k] == sound.m_nEntityIndex) { + found = true; + break; + } + } + if (!found) + stillUsedEntities[stillUsedEntitiesCount++] = sound.m_nEntityIndex; + } + } +#endif + + for (uint32 i = 0; i < NUM_AUDIOENTITIES; i++) { if (!m_asAudioEntities[i].m_bIsUsed) { +#ifdef FIX_BUGS + // skip if ID is still used by queued sample + bool skip = false; + for (uint8 j = 0; j < stillUsedEntitiesCount; j++) { + if (stillUsedEntities[j] == i) { + //debug("audio entity %i still used, skipping\n", i); + skip = true; + break; + } + } + if (skip) + continue; +#endif + m_asAudioEntities[i].m_bIsUsed = TRUE; m_asAudioEntities[i].m_bStatus = FALSE; m_asAudioEntities[i].m_nType = type; @@ -146,7 +185,7 @@ cAudioManager::CreateEntity(eAudioType type, void *entity) m_asAudioEntities[i].m_awAudioEvent[2] = SOUND_NO_SOUND; m_asAudioEntities[i].m_awAudioEvent[3] = SOUND_NO_SOUND; m_asAudioEntities[i].m_AudioEvents = 0; - m_anAudioEntityIndices[m_nAudioEntitiesTotal++] = i; + m_aAudioEntityOrderList[m_nAudioEntitiesCount++] = i; return i; } } @@ -158,11 +197,11 @@ cAudioManager::DestroyEntity(int32 id) { if (m_bIsInitialised && id >= 0 && id < NUM_AUDIOENTITIES && m_asAudioEntities[id].m_bIsUsed) { m_asAudioEntities[id].m_bIsUsed = FALSE; - for (int32 i = 0; i < m_nAudioEntitiesTotal; ++i) { - if (id == m_anAudioEntityIndices[i]) { + for (uint32 i = 0; i < m_nAudioEntitiesCount; ++i) { + if (id == m_aAudioEntityOrderList[i]) { if (i < NUM_AUDIOENTITIES - 1) - memmove(&m_anAudioEntityIndices[i], &m_anAudioEntityIndices[i + 1], NUM_AUDIOENTITY_EVENTS * (m_nAudioEntitiesTotal - (i + 1))); - m_anAudioEntityIndices[--m_nAudioEntitiesTotal] = NUM_AUDIOENTITIES; + memmove(&m_aAudioEntityOrderList[i], &m_aAudioEntityOrderList[i + 1], NUM_AUDIOENTITY_EVENTS * (m_nAudioEntitiesCount - (i + 1))); + m_aAudioEntityOrderList[--m_nAudioEntitiesCount] = NUM_AUDIOENTITIES; return; } } @@ -219,13 +258,13 @@ cAudioManager::PlayOneShot(int32 index, uint16 sound, float vol) if (entity.m_AudioEvents < ARRAY_SIZE(entity.m_awAudioEvent)) { entity.m_awAudioEvent[i] = sound; entity.m_afVolume[i] = vol; - ++entity.m_AudioEvents; + entity.m_AudioEvents++; } return; } if (OneShotPriority[entity.m_awAudioEvent[i]] > OneShotPriority[sound]) break; - ++i; + i++; } if (i < NUM_AUDIOENTITY_EVENTS - 1) { memmove(&entity.m_awAudioEvent[i + 1], &entity.m_awAudioEvent[i], (NUM_AUDIOENTITY_EVENTS - 1 - i) * NUM_AUDIOENTITY_EVENTS / 2); @@ -234,7 +273,7 @@ cAudioManager::PlayOneShot(int32 index, uint16 sound, float vol) entity.m_awAudioEvent[i] = sound; entity.m_afVolume[i] = vol; if (entity.m_AudioEvents < ARRAY_SIZE(entity.m_awAudioEvent)) - ++entity.m_AudioEvents; + entity.m_AudioEvents++; } } } @@ -285,14 +324,14 @@ cAudioManager::ResetTimers(uint32 time) m_bTimerJustReset = TRUE; m_nTimer = time; ClearRequestedQueue(); - if (m_nActiveSampleQueue) { - m_nActiveSampleQueue = 0; + if (m_nActiveQueue) { + m_nActiveQueue = 0; ClearRequestedQueue(); - m_nActiveSampleQueue = 1; + m_nActiveQueue = 1; } else { - m_nActiveSampleQueue = 1; + m_nActiveQueue = 1; ClearRequestedQueue(); - m_nActiveSampleQueue = 0; + m_nActiveQueue = 0; } ClearActiveSamples(); ClearMissionAudio(0); @@ -316,7 +355,7 @@ cAudioManager::DestroyAllGameCreatedEntities() cAudioScriptObject *entity; if (m_bIsInitialised) { - for (uint32 i = 0; i < ARRAY_SIZE(m_asAudioEntities); i++) { + for (uint32 i = 0; i < NUM_AUDIOENTITIES; i++) { if (m_asAudioEntities[i].m_bIsUsed) { switch (m_asAudioEntities[i].m_nType) { case AUDIOTYPE_PHYSICAL: @@ -405,20 +444,20 @@ cAudioManager::SetCurrent3DProvider(uint8 which) #else if (!m_bIsInitialised) return -1; - for (uint8 i = 0; i < m_nActiveSamples + 1; ++i) + for (uint8 i = 0; i < m_nActiveSamples + 1; i++) SampleManager.StopChannel(i); ClearRequestedQueue(); - if (m_nActiveSampleQueue == 0) - m_nActiveSampleQueue = 1; + if (m_nActiveQueue == 0) + m_nActiveQueue = 1; else - m_nActiveSampleQueue = 0; + m_nActiveQueue = 0; ClearRequestedQueue(); ClearActiveSamples(); int8 current = SampleManager.SetCurrent3DProvider(which); if (current > 0) { m_nActiveSamples = SampleManager.GetMaximumSupportedChannels(); if (m_nActiveSamples > 1) - --m_nActiveSamples; + m_nActiveSamples--; } return current; #endif @@ -494,7 +533,7 @@ cAudioManager::ServiceSoundEffects() if(CTimer::GetLogicalFramesPassed() != 0) #endif m_bReduceReleasingPriority = (m_FrameCounter++ % 5) == 0; - if (m_nUserPause && !m_nPreviousUserPause) { + if (m_bIsPaused && !m_bWasPaused) { for (uint32 i = 0; i < NUM_CHANNELS_GENERIC; i++) SampleManager.StopChannel(i); SampleManager.SetChannelFrequency(CHANNEL_POLICE_RADIO, 0); @@ -508,31 +547,31 @@ cAudioManager::ServiceSoundEffects() SampleManager.StopChannel(missionAudioChannel+1); #endif ClearRequestedQueue(); - if (m_nActiveSampleQueue) { - m_nActiveSampleQueue = 0; + if (m_nActiveQueue) { + m_nActiveQueue = 0; ClearRequestedQueue(); - m_nActiveSampleQueue = 1; + m_nActiveQueue = 1; } else { - m_nActiveSampleQueue = 1; + m_nActiveQueue = 1; ClearRequestedQueue(); - m_nActiveSampleQueue = 0; + m_nActiveQueue = 0; } ClearActiveSamples(); } - m_nActiveSampleQueue = m_nActiveSampleQueue == 1 ? 0 : 1; + m_nActiveQueue = m_nActiveQueue == 1 ? 0 : 1; #ifdef AUDIO_REVERB if(m_bIsSurround) ProcessReverb(); #endif ProcessSpecial(); ClearRequestedQueue(); InterrogateAudioEntities(); - if (!m_nUserPause) { + if (!m_bIsPaused) { m_sPedComments.Process(); //ServicePoliceRadio(); // LCS: removed ServiceCollisions(); } AddReleasingSounds(); - if (!m_nUserPause) + if (!m_bIsPaused) ProcessMissionAudio(); #ifdef EXTERNAL_3D_SOUND AdjustSamplesVolume(); @@ -541,7 +580,7 @@ cAudioManager::ServiceSoundEffects() #ifdef AUDIO_OAL SampleManager.Service(); #endif - for (int32 i = 0; i < m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal; ++i) { + for (int32 i = 0; i < m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal; i++) { cAudioScriptObject *object = (cAudioScriptObject *)m_asAudioEntities[m_sAudioScriptObjectManager.m_anScriptObjectEntityIndices[i]].m_pEntity; delete object; m_asAudioEntities[m_sAudioScriptObjectManager.m_anScriptObjectEntityIndices[i]].m_pEntity = nil; @@ -641,9 +680,9 @@ cAudioManager::RandomDisplacement(uint32 seed) void cAudioManager::InterrogateAudioEntities() { - for (int32 i = 0; i < m_nAudioEntitiesTotal; i++) { - ProcessEntity(m_anAudioEntityIndices[i]); - m_asAudioEntities[m_anAudioEntityIndices[i]].m_AudioEvents = 0; + for (uint32 i = 0; i < m_nAudioEntitiesCount; i++) { + ProcessEntity(m_aAudioEntityOrderList[i]); + m_asAudioEntities[m_aAudioEntityOrderList[i]].m_AudioEvents = 0; } } @@ -658,14 +697,13 @@ cAudioManager::AddSampleToRequestedQueue() if (m_sQueueSample.m_nSampleIndex < TOTAL_AUDIO_SAMPLES) { finalPriority = m_sQueueSample.m_nPriority * (MAX_VOLUME - m_sQueueSample.m_nVolume); - sampleIndex = m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; + sampleIndex = m_nRequestedCount[m_nActiveQueue]; if (sampleIndex >= m_nActiveSamples) { - sampleIndex = m_abSampleQueueIndexTable[m_nActiveSampleQueue][m_nActiveSamples - 1]; - if (m_asSamples[m_nActiveSampleQueue][sampleIndex].m_nFinalPriority <= finalPriority) + sampleIndex = m_aRequestedOrderList[m_nActiveQueue][m_nActiveSamples - 1]; + if (m_aRequestedQueue[m_nActiveQueue][sampleIndex].m_nFinalPriority <= finalPriority) return; - } else { - ++m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; - } + } else + m_nRequestedCount[m_nActiveQueue]++; m_sQueueSample.m_nFinalPriority = finalPriority; m_sQueueSample.m_bIsPlayingFinished = FALSE; #ifdef AUDIO_REFLECTIONS @@ -689,7 +727,7 @@ cAudioManager::AddSampleToRequestedQueue() #endif #endif - m_asSamples[m_nActiveSampleQueue][sampleIndex] = m_sQueueSample; + m_aRequestedQueue[m_nActiveQueue][sampleIndex] = m_sQueueSample; AddDetailsToRequestedOrderList(sampleIndex); #ifdef AUDIO_REFLECTIONS @@ -705,15 +743,15 @@ cAudioManager::AddDetailsToRequestedOrderList(uint8 sample) uint32 i = 0; if (sample > 0) { for (; i < sample; i++) { - if (m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]].m_nFinalPriority > - m_asSamples[m_nActiveSampleQueue][sample].m_nFinalPriority) + if (m_aRequestedQueue[m_nActiveQueue][m_aRequestedOrderList[m_nActiveQueue][i]].m_nFinalPriority > + m_aRequestedQueue[m_nActiveQueue][sample].m_nFinalPriority) break; } if (i < sample) { - memmove(&m_abSampleQueueIndexTable[m_nActiveSampleQueue][i + 1], &m_abSampleQueueIndexTable[m_nActiveSampleQueue][i], m_nActiveSamples - i - 1); + memmove(&m_aRequestedOrderList[m_nActiveQueue][i + 1], &m_aRequestedOrderList[m_nActiveQueue][i], m_nActiveSamples - i - 1); } } - m_abSampleQueueIndexTable[m_nActiveSampleQueue][i] = sample; + m_aRequestedOrderList[m_nActiveQueue][i] = sample; } #ifdef AUDIO_REFLECTIONS @@ -911,17 +949,17 @@ cAudioManager::AddReleasingSounds() bool8 toProcess[44]; #endif - int8 queue = m_nActiveSampleQueue == 0 ? 1 : 0; + uint8 queue = m_nActiveQueue == 0 ? 1 : 0; - for (int32 i = 0; i < m_SampleRequestQueuesStatus[queue]; i++) { - tSound &sample = m_asSamples[queue][m_abSampleQueueIndexTable[queue][i]]; + for (uint8 i = 0; i < m_nRequestedCount[queue]; i++) { + tSound &sample = m_aRequestedQueue[queue][m_aRequestedOrderList[queue][i]]; if (sample.m_bIsPlayingFinished) continue; toProcess[i] = FALSE; - for (int32 j = 0; j < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; j++) { - if (sample.m_nEntityIndex == m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][j]].m_nEntityIndex && - sample.m_nCounter == m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][j]].m_nCounter) { + for (uint8 j = 0; j < m_nRequestedCount[m_nActiveQueue]; j++) { + if (sample.m_nEntityIndex == m_aRequestedQueue[m_nActiveQueue][m_aRequestedOrderList[m_nActiveQueue][j]].m_nEntityIndex && + sample.m_nCounter == m_aRequestedQueue[m_nActiveQueue][m_aRequestedOrderList[m_nActiveQueue][j]].m_nCounter) { toProcess[i] = TRUE; break; } @@ -931,39 +969,92 @@ cAudioManager::AddReleasingSounds() if(sample.m_nCounter <= 255 || sample.m_nReflectionDelay == 0) // check if not delayed reflection #endif { - if (sample.m_nFramesToPlay == 0) +#ifdef ATTACH_RELEASING_SOUNDS_TO_ENTITIES + if (sample.m_nCounter <= 255 && !sample.m_bIs2D) { // check if not reflection and is a 3D sound + CEntity* entity = (CEntity*)GetEntityPointer(sample.m_nEntityIndex); + if (entity && m_asAudioEntities[sample.m_nEntityIndex].m_nType == AUDIOTYPE_PHYSICAL) { + sample.m_vecPos = entity->GetPosition(); + float oldDistance = sample.m_fDistance; + sample.m_fDistance = Sqrt(GetDistanceSquared(sample.m_vecPos)); + if (sample.m_nSampleIndex >= SAMPLEBANK_PED_START && sample.m_nSampleIndex <= SAMPLEBANK_PED_END) { // check if it's ped comment + uint8 vol; + if (CWorld::GetIsLineOfSightClear(TheCamera.GetPosition(), sample.m_vecPos, true, false, false, false, false, false)) + vol = MAX_VOLUME; + else + vol = 31; +#ifdef EXTERNAL_3D_SOUND + sample.m_nEmittingVolume = vol; +#endif + sample.m_nVolume = ComputeVolume(vol, sample.m_MaxDistance, sample.m_fDistance); + } else { + // calculate new volume with changed distance + float volumeDiff = sq((sample.m_MaxDistance - sample.m_fDistance) / (sample.m_MaxDistance - oldDistance)); + if (volumeDiff > 0.0f) { + uint8 newVolume = volumeDiff * sample.m_nVolume; + if (sample.m_nVolumeChange > 0) + sample.m_nVolumeChange = volumeDiff * sample.m_nVolumeChange; +#if defined(FIX_BUGS) && defined(EXTERNAL_3D_SOUND) + if (sample.m_nEmittingVolumeChange > 0) + sample.m_nEmittingVolumeChange = volumeDiff * sample.m_nEmittingVolumeChange; +#endif + sample.m_nVolume = Min(127, newVolume); + } + } + if (sample.m_nVolume == 0) + sample.m_nFramesToPlay = 0; + } + } +#endif +#ifdef FIX_BUGS + if (sample.m_nFramesToPlay <= 0) continue; if (sample.m_nLoopCount == 0) { if (sample.m_nVolumeChange == -1) { -#if defined(FIX_BUGS) && defined(EXTERNAL_3D_SOUND) - sample.m_nVolumeChange = sample.m_nEmittingVolume / sample.m_nFramesToPlay; -#else sample.m_nVolumeChange = sample.m_nVolume / sample.m_nFramesToPlay; -#endif if (sample.m_nVolumeChange <= 0) sample.m_nVolumeChange = 1; +#ifdef EXTERNAL_3D_SOUND + sample.m_nEmittingVolumeChange = sample.m_nEmittingVolume / sample.m_nFramesToPlay; + if (sample.m_nEmittingVolumeChange <= 0) + sample.m_nEmittingVolumeChange = 1; +#endif } -#if defined(FIX_BUGS) && defined(EXTERNAL_3D_SOUND) - if (sample.m_nEmittingVolume <= sample.m_nVolumeChange) { + if (sample.m_nVolume <= sample.m_nVolumeChange * CTimer::GetTimeStepFix()) { + sample.m_nFramesToPlay = 0; + continue; + } + sample.m_nVolume -= sample.m_nVolumeChange * CTimer::GetTimeStepFix(); +#ifdef EXTERNAL_3D_SOUND + if (sample.m_nEmittingVolume <= sample.m_nEmittingVolumeChange * CTimer::GetTimeStepFix()) { + sample.m_nFramesToPlay = 0; + continue; + } + sample.m_nEmittingVolume -= sample.m_nEmittingVolumeChange * CTimer::GetTimeStepFix(); +#endif + } + sample.m_nFramesToPlay -= CTimer::GetTimeStepFix(); + if (sample.m_nFramesToPlay < 0) + sample.m_nFramesToPlay = 0; #else + if (sample.m_nFramesToPlay == 0) + continue; + if (sample.m_nLoopCount == 0) { + if (sample.m_nVolumeChange == -1) { + sample.m_nVolumeChange = sample.m_nVolume / sample.m_nFramesToPlay; + if (sample.m_nVolumeChange <= 0) + sample.m_nVolumeChange = 1; + } if (sample.m_nVolume <= sample.m_nVolumeChange) { -#endif sample.m_nFramesToPlay = 0; continue; } -#if defined(FIX_BUGS) && defined(EXTERNAL_3D_SOUND) - sample.m_nEmittingVolume -= sample.m_nVolumeChange; -#else sample.m_nVolume -= sample.m_nVolumeChange; -#endif } -#ifdef FIX_BUGS - if(CTimer::GetLogicalFramesPassed() != 0) + sample.m_nFramesToPlay--; #endif - --sample.m_nFramesToPlay; if (m_bReduceReleasingPriority) { if (sample.m_nPriority < 20) - ++sample.m_nPriority; + sample.m_nPriority++; } sample.m_bStatic = FALSE; } @@ -997,18 +1088,28 @@ cAudioManager::ProcessActiveQueues() bool8 isPhoneCall; uint8 channelOffset = 0; - for (int32 i = 0; i < m_nActiveSamples; i++) { - m_asSamples[m_nActiveSampleQueue][i].m_bIsBeingPlayed = FALSE; +#ifdef EXTERNAL_3D_SOUND + #define WORKING_VOLUME_FIELD m_nEmittingVolume +#else + #define WORKING_VOLUME_FIELD m_nVolume +#endif + +#ifdef USE_TIME_SCALE_FOR_AUDIO + float timeScale = m_bIsPaused ? 1.0f : CTimer::GetTimeScale(); +#endif + + for (uint8 i = 0; i < m_nActiveSamples; i++) { + m_aRequestedQueue[m_nActiveQueue][i].m_bIsBeingPlayed = FALSE; m_asActiveSamples[i].m_bIsBeingPlayed = FALSE; } - for (int32 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) { - tSound &sample = m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]]; + for (uint8 i = 0; i < m_nRequestedCount[m_nActiveQueue]; i++) { + tSound &sample = m_aRequestedQueue[m_nActiveQueue][m_aRequestedOrderList[m_nActiveQueue][i]]; if (sample.m_nSampleIndex != NO_SAMPLE) { - for (int32 j = 0; j < m_nActiveSamples; j++) { + for (uint8 j = 0; j < m_nActiveSamples; j++) { if (sample.m_nEntityIndex == m_asActiveSamples[j].m_nEntityIndex && sample.m_nCounter == m_asActiveSamples[j].m_nCounter && sample.m_nSampleIndex == m_asActiveSamples[j].m_nSampleIndex) { - if (sample.m_nLoopCount) { + if (sample.m_nLoopCount > 0) { if (m_FrameCounter & 1) flag = !!(j & 1); else @@ -1029,12 +1130,12 @@ cAudioManager::ProcessActiveQueues() sample.m_nVolumeChange = -1; if (!sample.m_bStatic) { if (sample.m_bIs2D) { -#ifdef EXTERNAL_3D_SOUND - emittingVol = m_bDoubleVolume ? 2 * Min(63, sample.m_nEmittingVolume) : sample.m_nEmittingVolume; + emittingVol = m_bDoubleVolume ? 2 * Min(63, sample.WORKING_VOLUME_FIELD) : sample.WORKING_VOLUME_FIELD; +#ifdef USE_TIME_SCALE_FOR_AUDIO + SampleManager.SetChannelFrequency(j, sample.m_nFrequency * timeScale); #else - emittingVol = m_bDoubleVolume ? 2 * Min(63, sample.m_nVolume) : sample.m_nVolume; -#endif SampleManager.SetChannelFrequency(j, sample.m_nFrequency); +#endif #ifdef EXTERNAL_3D_SOUND SampleManager.SetChannelEmittingVolume(j, emittingVol); #else @@ -1049,7 +1150,11 @@ cAudioManager::ProcessActiveQueues() if (sample.m_nFrequency != m_asActiveSamples[j].m_nFrequency) { uint32 freq = Clamp2((int32)sample.m_nFrequency, (int32)m_asActiveSamples[j].m_nFrequency, 6000); m_asActiveSamples[j].m_nFrequency = freq; +#ifdef USE_TIME_SCALE_FOR_AUDIO + SampleManager.SetChannelFrequency(j, freq * timeScale); +#else SampleManager.SetChannelFrequency(j, freq); +#endif } #ifdef EXTERNAL_3D_SOUND if (sample.m_nEmittingVolume != m_asActiveSamples[j].m_nEmittingVolume) { @@ -1103,15 +1208,15 @@ cAudioManager::ProcessActiveQueues() } } } - for (int32 i = 0; i < m_nActiveSamples; i++) { + for (uint8 i = 0; i < m_nActiveSamples; i++) { if (m_asActiveSamples[i].m_nSampleIndex != NO_SAMPLE && !m_asActiveSamples[i].m_bIsBeingPlayed) { SampleManager.StopChannel(i); m_asActiveSamples[i].m_nSampleIndex = NO_SAMPLE; m_asActiveSamples[i].m_nEntityIndex = AEHANDLE_NONE; } } - for (uint8 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) { - tSound &sample = m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]]; + for (uint8 i = 0; i < m_nRequestedCount[m_nActiveQueue]; i++) { + tSound &sample = m_aRequestedQueue[m_nActiveQueue][m_aRequestedOrderList[m_nActiveQueue][i]]; if (!sample.m_bIsBeingPlayed && !sample.m_bIsPlayingFinished && m_asAudioEntities[sample.m_nEntityIndex].m_bIsUsed && sample.m_nSampleIndex < NO_SAMPLE) { #ifdef AUDIO_REFLECTIONS if (sample.m_nCounter > 255 && sample.m_nLoopCount > 0 && sample.m_nReflectionDelay > 0) { // check if reflection @@ -1137,18 +1242,18 @@ cAudioManager::ProcessActiveQueues() m_asActiveSamples[j].m_nPan = ComputePan(m_asActiveSamples[j].m_fDistance, &position); #endif } -#ifdef EXTERNAL_3D_SOUND - emittingVol = m_bDoubleVolume ? 2 * Min(63, m_asActiveSamples[j].m_nEmittingVolume) : m_asActiveSamples[j].m_nEmittingVolume; -#else - emittingVol = m_bDoubleVolume ? 2 * Min(63, m_asActiveSamples[j].m_nVolume) : m_asActiveSamples[j].m_nVolume; -#endif + emittingVol = m_bDoubleVolume ? 2 * Min(63, m_asActiveSamples[j].WORKING_VOLUME_FIELD) : m_asActiveSamples[j].WORKING_VOLUME_FIELD; #ifdef GTA_PS2 { SampleManager.InitialiseChannel(k, m_asActiveSamples[k].m_nSampleIndex, m_asActiveSamples[k].m_nBankIndex); #else if (SampleManager.InitialiseChannel(k, m_asActiveSamples[k].m_nSampleIndex, m_asActiveSamples[k].m_nBankIndex)) { #endif +#ifdef USE_TIME_SCALE_FOR_AUDIO + SampleManager.SetChannelFrequency(k, m_asActiveSamples[k].m_nFrequency * timeScale); +#else SampleManager.SetChannelFrequency(k, m_asActiveSamples[k].m_nFrequency); +#endif isPhoneCall = FALSE; for (int32 l = 0; l < MISSION_AUDIO_SLOTS; l++) { if (m_bIsMissionAudioPhoneCall[l]) { @@ -1171,8 +1276,8 @@ cAudioManager::ProcessActiveQueues() #endif #ifndef GTA_PS2 SampleManager.SetChannelLoopPoints(k, m_asActiveSamples[k].m_nLoopStart, m_asActiveSamples[k].m_nLoopEnd); - SampleManager.SetChannelLoopCount(k, m_asActiveSamples[k].m_nLoopCount); #endif + SampleManager.SetChannelLoopCount(k, m_asActiveSamples[k].m_nLoopCount); #if !defined(GTA_PS2) || defined(AUDIO_REVERB) SampleManager.SetChannelReverbFlag(k, m_asActiveSamples[k].m_bReverb); #endif @@ -1209,19 +1314,28 @@ cAudioManager::ProcessActiveQueues() } } } + #ifdef GTA_PS2 m_nChannelOffset += channelOffset; #endif m_nChannelOffset %= m_nActiveSamples; + +#ifdef USE_TIME_SCALE_FOR_AUDIO + for (uint8 i = 0; i < m_nActiveSamples; i++) { + if (m_asActiveSamples[i].m_nSampleIndex != NO_SAMPLE && m_asActiveSamples[i].m_bIsBeingPlayed) + SampleManager.SetChannelFrequency(i, m_asActiveSamples[i].m_nFrequency * timeScale); + } +#endif + +#undef WORKING_VOLUME_FIELD } void cAudioManager::ClearRequestedQueue() { - for (int32 i = 0; i < m_nActiveSamples; i++) { - m_abSampleQueueIndexTable[m_nActiveSampleQueue][i] = m_nActiveSamples; - } - m_SampleRequestQueuesStatus[m_nActiveSampleQueue] = 0; + for (uint8 i = 0; i < m_nActiveSamples; i++) + m_aRequestedOrderList[m_nActiveQueue][i] = m_nActiveSamples; + m_nRequestedCount[m_nActiveQueue] = 0; } void @@ -1275,17 +1389,16 @@ cAudioManager::LoadBankIfNecessary(uint8 bank) void cAudioManager::GenerateIntegerRandomNumberTable() { - for (int32 i = 0; i < ARRAY_SIZE(m_anRandomTable); i++) { + for (uint32 i = 0; i < ARRAY_SIZE(m_anRandomTable); i++) m_anRandomTable[i] = myrand(); - } } #ifdef EXTERNAL_3D_SOUND void cAudioManager::AdjustSamplesVolume() { - for (int i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) { - tSound *pSample = &m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]]; + for (uint8 i = 0; i < m_nRequestedCount[m_nActiveQueue]; i++) { + tSound *pSample = &m_aRequestedQueue[m_nActiveQueue][m_aRequestedOrderList[m_nActiveQueue][i]]; if (!pSample->m_bIs2D) pSample->m_nEmittingVolume = ComputeEmittingVolume(pSample->m_nEmittingVolume, pSample->m_MaxDistance, pSample->m_fDistance); diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index 4cebe118..73920d42 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -44,14 +44,21 @@ public: // 63 = L 100% R 100% // 127 = L 0% R 100% uint8 m_nFrontRearPan; // Used on PS2 for surround panning +#ifndef FIX_BUGS uint32 m_nFramesToPlay; // Number of frames the sound would be played (if it stops being queued). // This one is being set by queued sample for looping sounds, otherwise calculated inside AudioManager +#else + float m_nFramesToPlay; // Made into float for high fps fix +#endif // all fields below are internal to AudioManager calculations and aren't set by queued sample bool8 m_bIsBeingPlayed; // Set to TRUE when the sound was added or changed on current frame to avoid it being overwritten bool8 m_bIsPlayingFinished; // Not sure about the name. Set to TRUE when sampman channel becomes free uint32 m_nFinalPriority; // Actual value used to compare priority, calculated using volume and m_nPriority. Lesser value means higher priority int8 m_nVolumeChange; // How much m_nVolume should reduce per each frame. +#if defined(FIX_BUGS) && defined(EXTERNAL_3D_SOUND) + int8 m_nEmittingVolumeChange; // same as above but for m_nEmittingVolume +#endif }; VALIDATE_SIZE(tSound, 96); @@ -229,16 +236,16 @@ public: uint8 m_nChannelOffset; float m_fSpeedOfSound; bool8 m_bTimerJustReset; - int32 m_nTimer; + uint32 m_nTimer; tSound m_sQueueSample; - uint8 m_nActiveSampleQueue; - tSound m_asSamples[NUM_SOUNDS_SAMPLES_BANKS][NUM_CHANNELS_GENERIC]; - uint8 m_abSampleQueueIndexTable[NUM_SOUNDS_SAMPLES_BANKS][NUM_CHANNELS_GENERIC]; - uint8 m_SampleRequestQueuesStatus[NUM_SOUNDS_SAMPLES_BANKS]; + uint8 m_nActiveQueue; + tSound m_aRequestedQueue[NUM_SOUND_QUEUES][NUM_CHANNELS_GENERIC]; + uint8 m_aRequestedOrderList[NUM_SOUND_QUEUES][NUM_CHANNELS_GENERIC]; + uint8 m_nRequestedCount[NUM_SOUND_QUEUES]; tSound m_asActiveSamples[NUM_CHANNELS_GENERIC]; tAudioEntity m_asAudioEntities[NUM_AUDIOENTITIES]; - int32 m_anAudioEntityIndices[NUM_AUDIOENTITIES]; - int32 m_nAudioEntitiesTotal; + uint32 m_aAudioEntityOrderList[NUM_AUDIOENTITIES]; + uint32 m_nAudioEntitiesCount; #ifdef AUDIO_REFLECTIONS CVector m_avecReflectionsPos[MAX_REFLECTIONS]; float m_afReflectionsDistances[MAX_REFLECTIONS]; @@ -278,15 +285,15 @@ public: uint8 m_nMissionAudioLoadingStatus[MISSION_AUDIO_SLOTS]; uint8 m_nMissionAudioPlayStatus[MISSION_AUDIO_SLOTS]; bool8 m_bIsMissionAudioPlaying[MISSION_AUDIO_SLOTS]; - int32 m_nMissionAudioFramesToPlay[MISSION_AUDIO_SLOTS]; + int32 m_nMissionAudioFramesToPlay[MISSION_AUDIO_SLOTS]; // possibly unsigned bool8 m_bIsMissionAudioAllowedToPlay[MISSION_AUDIO_SLOTS]; bool8 m_bIsMissionAudioPhoneCall[MISSION_AUDIO_SLOTS]; uint8 m_nGlobalSfxVolumeMultiplier; // used to lower sfx volume during phone calls int32 m_anRandomTable[5]; uint8 m_nTimeSpent; - bool8 m_nUserPause; - bool8 m_nPreviousUserPause; + bool8 m_bIsPaused; + bool8 m_bWasPaused; uint32 m_FrameCounter; uint32 field_5644_lcs; diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp index c9230e02..623b6ad5 100644 --- a/src/audio/MusicManager.cpp +++ b/src/audio/MusicManager.cpp @@ -263,7 +263,7 @@ cMusicManager::GetRadioInCar(void) CVehicle* veh = AudioManager.FindVehicleOfPlayer(); if (veh != nil) { if (UsesPoliceRadio(veh) || UsesTaxiRadio(veh)) { - if (m_nRadioInCar == NO_TRACK || (CReplay::IsPlayingBack() && !AudioManager.m_nUserPause)) + if (m_nRadioInCar == NO_TRACK || (CReplay::IsPlayingBack() && !AudioManager.m_bIsPaused)) return STREAMED_SOUND_RADIO_POLICE; return m_nRadioInCar; } @@ -271,7 +271,7 @@ cMusicManager::GetRadioInCar(void) } } - if (m_nRadioInCar == NO_TRACK || (CReplay::IsPlayingBack() && !AudioManager.m_nUserPause)) + if (m_nRadioInCar == NO_TRACK || (CReplay::IsPlayingBack() && !AudioManager.m_bIsPaused)) return RADIO_OFF; return m_nRadioInCar; } @@ -353,7 +353,7 @@ cMusicManager::ChangeMusicMode(uint8 mode) } void -cMusicManager::ResetTimers(int32 time) +cMusicManager::ResetTimers(uint32 time) { m_bResetTimers = TRUE; m_nResetTime = time; @@ -374,7 +374,7 @@ cMusicManager::Service() if (!m_bMusicModeChangeStarted) m_nMusicModeToBeSet = m_nUpcomingMusicMode; if (m_nMusicModeToBeSet == m_nMusicMode) { - if (!AudioManager.m_nUserPause || AudioManager.m_nPreviousUserPause || m_nMusicMode != MUSICMODE_FRONTEND) + if (!AudioManager.m_bIsPaused || AudioManager.m_bWasPaused || m_nMusicMode != MUSICMODE_FRONTEND) { switch (m_nMusicMode) { @@ -387,7 +387,7 @@ cMusicManager::Service() m_nMusicMode = MUSICMODE_DISABLED; } else { m_bMusicModeChangeStarted = TRUE; - if (!m_bUserResumedGame && !AudioManager.m_nUserPause && AudioManager.m_nPreviousUserPause) + if (!m_bUserResumedGame && !AudioManager.m_bIsPaused && AudioManager.m_bWasPaused) m_bUserResumedGame = TRUE; if (AudioManager.m_FrameCounter % 4 == 0) { gNumRetunePresses = 0; @@ -461,7 +461,7 @@ cMusicManager::ServiceFrontEndMode() } else { if (m_nPlayingTrack == STREAMED_SOUND_RADIO_MP3_PLAYER) SampleManager.StartStreamedFile(STREAMED_SOUND_RADIO_MP3_PLAYER, 0); - else if (m_nPlayingTrack == STREAMED_SOUND_MISSION_COMPLETED && !AudioManager.m_nUserPause) + else if (m_nPlayingTrack == STREAMED_SOUND_MISSION_COMPLETED && !AudioManager.m_bIsPaused) ChangeMusicMode(MUSICMODE_GAME); } } else { diff --git a/src/audio/MusicManager.h b/src/audio/MusicManager.h index 3d2b7cee..52254b19 100644 --- a/src/audio/MusicManager.h +++ b/src/audio/MusicManager.h @@ -76,7 +76,7 @@ public: void SetRadioInCar(uint32); void SetRadioChannelByScript(uint32, int32); - void ResetTimers(int32); + void ResetTimers(uint32); void Service(); void ServiceFrontEndMode(); void ServiceGameMode(); diff --git a/src/audio/PolRadio.cpp b/src/audio/PolRadio.cpp index ed884e6e..d557cdab 100644 --- a/src/audio/PolRadio.cpp +++ b/src/audio/PolRadio.cpp @@ -125,7 +125,7 @@ cAudioManager::ServicePoliceRadio() if(!m_bIsInitialised) return; - if(!m_nUserPause) { + if(!m_bIsPaused) { bool8 crimeReport = SetupCrimeReport(); #ifdef FIX_BUGS // Crash at 0x5fe6ef if(CReplay::IsPlayingBack() || !FindPlayerPed() || !FindPlayerPed()->m_pWanted) @@ -168,14 +168,14 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel) if (!m_bIsInitialised) return; - if (m_nUserPause) { + if (m_bIsPaused) { if (SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO)) SampleManager.StopChannel(CHANNEL_POLICE_RADIO); if (g_nMissionAudioSfx != NO_SAMPLE && bMissionAudioPhysicalPlayingStatus == PLAY_STATUS_PLAYING && SampleManager.IsStreamPlaying(1)) { SampleManager.PauseStream(TRUE, 1); } } else { - if (m_nPreviousUserPause && g_nMissionAudioSfx != NO_SAMPLE && + if (m_bWasPaused && g_nMissionAudioSfx != NO_SAMPLE && bMissionAudioPhysicalPlayingStatus == PLAY_STATUS_PLAYING) { SampleManager.PauseStream(FALSE, 1); } @@ -238,11 +238,15 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel) default: freq = SampleManager.GetSampleBaseFrequency(sample); break; } PoliceChannelFreq = freq; +#ifdef USE_TIME_SCALE_FOR_AUDIO + SampleManager.SetChannelFrequency(CHANNEL_POLICE_RADIO, freq * CTimer::GetTimeScale()); +#else SampleManager.SetChannelFrequency(CHANNEL_POLICE_RADIO, freq); +#endif SampleManager.SetChannelVolume(CHANNEL_POLICE_RADIO, 100); SampleManager.SetChannelPan(CHANNEL_POLICE_RADIO, 63); -#ifndef GTA_PS2 SampleManager.SetChannelLoopCount(CHANNEL_POLICE_RADIO, 1); +#ifndef GTA_PS2 SampleManager.SetChannelLoopPoints(CHANNEL_POLICE_RADIO, 0, -1); #endif SampleManager.StartChannel(CHANNEL_POLICE_RADIO); diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index 72e1adf0..c02f6dab 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -727,7 +727,7 @@ CCam::LookRight(void) CVector TargetCoors, TargetFwd; CColPoint colPoint; - if((Mode == MODE_CAM_ON_A_STRING || Mode == MODE_BEHINDBOAT) && CamTargetEntity->IsVehicle()){ + if((Mode == MODE_CAM_ON_A_STRING || Mode == MODE_BEHINDBOAT || Mode == MODE_BEHINDCAR) && CamTargetEntity->IsVehicle()){ LookingRight = true; TargetCoors = CamTargetEntity->GetPosition(); Front = CamTargetEntity->GetPosition() - Source; diff --git a/src/core/config.h b/src/core/config.h index 47589af3..9049fec0 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -132,7 +132,7 @@ enum Config { NUM_PED_COMMENTS_BANKS = 2, NUM_PED_COMMENTS_SLOTS = 20, - NUM_SOUNDS_SAMPLES_BANKS = 2, + NUM_SOUND_QUEUES = 2, NUM_AUDIOENTITIES = 250, NUM_SCRIPT_MAX_ENTITIES = 40, @@ -459,8 +459,10 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually //#define PS2_AUDIO_PATHS // changes audio paths for cutscenes and radio to PS2 paths (needs vbdec on MSS builds) //#define AUDIO_OAL_USE_SNDFILE // use libsndfile to decode WAVs instead of our internal decoder #define AUDIO_OAL_USE_MPG123 // use mpg123 to support mp3 files -#define MULTITHREADED_AUDIO // for streams. requires C++11 or later #define PAUSE_RADIO_IN_FRONTEND // pause radio when game is paused +#define ATTACH_RELEASING_SOUNDS_TO_ENTITIES // sounds would follow ped and vehicles coordinates if not being queued otherwise +#define USE_TIME_SCALE_FOR_AUDIO // slow down/speed up sounds according to the speed of the game +#define MULTITHREADED_AUDIO // for streams. requires C++11 or later #ifdef AUDIO_OPUS #define AUDIO_OAL_USE_OPUS // enable support of opus files diff --git a/src/peds/PedIK.cpp b/src/peds/PedIK.cpp index 3bc5796b..ea3cf1aa 100644 --- a/src/peds/PedIK.cpp +++ b/src/peds/PedIK.cpp @@ -205,6 +205,8 @@ CPedIK::PointGunInDirection(float targetYaw, float targetPitch) else if (status == ANGLES_SET_EXACTLY) m_flags |= GUN_POINTED_SUCCESSFULLY; } + + // Game uses index 2 directly, which happens to be identical to BONE_spine #ifdef FIX_BUGS RwMatrix *m = GetBoneMatrix(m_ped, BONE_spine); #else @@ -213,7 +215,7 @@ CPedIK::PointGunInDirection(float targetYaw, float targetPitch) RwMatrix *m = &mats[2]; #endif RwV3d axis = { 0.0f, 0.0f, 0.0f }; - float axisangle = -CGeneral::LimitRadianAngle(Atan2(-m->up.y, -m->up.x) - m_ped->m_fRotationCur); + float axisangle = -CGeneral::LimitRadianAngle(Atan2(-m->at.y, -m->at.x) - m_ped->m_fRotationCur); axis.y = -Sin(axisangle); axis.z = Cos(axisangle); diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index 3e6509f5..4fb0ec29 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -729,10 +729,17 @@ CPlayerPed::ProcessWeaponSwitch(CPad *padUsed) for (m_nSelectedWepSlot = m_currentWeapon + 1; m_nSelectedWepSlot < TOTAL_WEAPON_SLOTS; ++m_nSelectedWepSlot) { if (HasWeaponSlot(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) { +#ifdef FIX_BUGS + goto switchDetectDone; +#else goto spentAmmoCheck; +#endif } } m_nSelectedWepSlot = 0; +#ifdef FIX_BUGS + goto switchDetectDone; +#endif } } else if (padUsed->CycleWeaponLeftJustDown()) { if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON @@ -754,6 +761,10 @@ CPlayerPed::ProcessWeaponSwitch(CPad *padUsed) --m_nSelectedWepSlot; } while (m_nSelectedWepSlot != WEAPONSLOT_UNARMED); +#ifdef FIX_BUGS + goto switchDetectDone; +#endif + } } } diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 2e91040d..61aa00b2 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -1671,7 +1671,7 @@ CAutomobile::Teleport(CVector pos) float gHeadlightRange = 25.0f; float gTaxilightRange = 1.1f; -CVector gHeadlightColour(0.86, 0.82f, 1.0f); +CVector gHeadlightColour(0.86f, 0.82f, 1.0f); CVector gTaxilightColour(1.0, 1.0f, 0.5f); void |