diff options
author | Sergeanur <s.anureev@yandex.ua> | 2021-08-21 12:02:07 +0200 |
---|---|---|
committer | Sergeanur <s.anureev@yandex.ua> | 2021-08-21 12:02:07 +0200 |
commit | 7c80093efa18bac0598bf6481ccad479c90e47af (patch) | |
tree | 90e77d41de1559f95b068cba3b3f56c187f953d3 | |
parent | Audio: bits of PS2 code (diff) | |
download | re3-7c80093efa18bac0598bf6481ccad479c90e47af.tar re3-7c80093efa18bac0598bf6481ccad479c90e47af.tar.gz re3-7c80093efa18bac0598bf6481ccad479c90e47af.tar.bz2 re3-7c80093efa18bac0598bf6481ccad479c90e47af.tar.lz re3-7c80093efa18bac0598bf6481ccad479c90e47af.tar.xz re3-7c80093efa18bac0598bf6481ccad479c90e47af.tar.zst re3-7c80093efa18bac0598bf6481ccad479c90e47af.zip |
-rw-r--r-- | src/audio/AudioLogic.cpp | 184 | ||||
-rw-r--r-- | src/audio/AudioManager.cpp | 30 | ||||
-rw-r--r-- | src/audio/AudioManager.h | 44 | ||||
-rw-r--r-- | src/audio/PolRadio.cpp | 88 | ||||
-rw-r--r-- | src/audio/PolRadio.h | 49 |
5 files changed, 199 insertions, 196 deletions
diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp index 9d6fa51d..4accd64c 100644 --- a/src/audio/AudioLogic.cpp +++ b/src/audio/AudioLogic.cpp @@ -144,11 +144,7 @@ cAudioManager::PostInitialiseGameSpecificSetup() m_nPoliceChannelEntity = CreateEntity(AUDIOTYPE_POLICERADIO, (void *)1); if (m_nPoliceChannelEntity >= 0) SetEntityStatus(m_nPoliceChannelEntity, TRUE); -#ifdef GTA_BRIDGE - m_nBridgeEntity = CreateEntity(AUDIOTYPE_BRIDGE, (void*)1); - if (m_nBridgeEntity >= 0) - SetEntityStatus(m_nBridgeEntity, TRUE); -#endif // GTA_BRIDGE + m_nEscalatorEntity = CreateEntity(AUDIOTYPE_ESCALATOR, (void*)1); if (m_nEscalatorEntity >= 0) SetEntityStatus(m_nEscalatorEntity, TRUE); @@ -157,25 +153,23 @@ cAudioManager::PostInitialiseGameSpecificSetup() if (m_nExtraSoundsEntity >= 0) SetEntityStatus(m_nExtraSoundsEntity, TRUE); +#ifdef GTA_BRIDGE + m_nBridgeEntity = CreateEntity(AUDIOTYPE_BRIDGE, (void*)1); + if (m_nBridgeEntity >= 0) + SetEntityStatus(m_nBridgeEntity, TRUE); +#endif // GTA_BRIDGE - m_sMissionAudio.m_nSampleIndex[0] = NO_SAMPLE; - m_sMissionAudio.m_nLoadingStatus[0] = LOADING_STATUS_NOT_LOADED; - m_sMissionAudio.m_nPlayStatus[0] = PLAY_STATUS_STOPPED; - m_sMissionAudio.m_bIsPlaying[0] = FALSE; - m_sMissionAudio.m_bIsPlayed[0] = FALSE; - m_sMissionAudio.m_bPredefinedProperties[0] = TRUE; - m_sMissionAudio.m_nMissionAudioCounter[0] = 0; - m_sMissionAudio.m_bIsMobile[0] = FALSE; - field_5538 = 127; - m_sMissionAudio.m_nSampleIndex[1] = NO_SAMPLE; - m_sMissionAudio.m_nLoadingStatus[1] = LOADING_STATUS_NOT_LOADED; - m_sMissionAudio.m_nPlayStatus[1] = PLAY_STATUS_STOPPED; - m_sMissionAudio.m_bIsPlaying[1] = FALSE; - m_sMissionAudio.m_bIsPlayed[1] = FALSE; - m_sMissionAudio.m_bPredefinedProperties[1] = TRUE; - m_sMissionAudio.m_nMissionAudioCounter[1] = 0; - m_sMissionAudio.m_bIsMobile[1] = FALSE; - field_5538 = 127; + for (int i = 0; i < MISSION_AUDIO_SLOTS; i++) { + m_nMissionAudioSampleIndex[i] = NO_SAMPLE; + m_nMissionAudioLoadingStatus[i] = LOADING_STATUS_NOT_LOADED; + m_nMissionAudioPlayStatus[i] = PLAY_STATUS_STOPPED; + m_bIsMissionAudioPlaying[i] = FALSE; + m_bIsMissionAudioAllowedToPlay[i] = FALSE; + m_bIsMissionAudio2D[i] = TRUE; + m_nMissionAudioFramesToPlay[i] = 0; + m_bIsMissionAudioPhoneCall[i] = FALSE; + m_nGlobalSfxVolumeMultiplier = 127; + } ResetAudioLogicTimers(CTimer::GetTimeInMilliseconds()); m_bIsPlayerShutUp = FALSE; @@ -9812,9 +9806,9 @@ FindMissionAudioSfx(const char *name) const char * cAudioManager::GetMissionAudioLoadedLabel(uint8 slot) { - if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS && m_sMissionAudio.m_nSampleIndex[slot] != NO_SAMPLE) { + if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS && m_nMissionAudioSampleIndex[slot] != NO_SAMPLE) { for (uint32 i = 0; MissionAudioNameSfxAssoc[i].m_pName != nil; ++i) { - if (m_sMissionAudio.m_nSampleIndex[slot] == MissionAudioNameSfxAssoc[i].m_nId) + if (m_nMissionAudioSampleIndex[slot] == MissionAudioNameSfxAssoc[i].m_nId) return MissionAudioNameSfxAssoc[i].m_pName; } } @@ -9838,14 +9832,14 @@ cAudioManager::PreloadMissionAudio(uint8 slot, Const char *name) if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS) { int32 missionAudioSfx = FindMissionAudioSfx(name); if (missionAudioSfx != NO_SAMPLE) { - m_sMissionAudio.m_nSampleIndex[slot] = missionAudioSfx; - m_sMissionAudio.m_nLoadingStatus[slot] = LOADING_STATUS_NOT_LOADED; - m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_STOPPED; - m_sMissionAudio.m_bIsPlaying[slot] = FALSE; - m_sMissionAudio.m_nMissionAudioCounter[slot] = m_nTimeSpent * SampleManager.GetStreamedFileLength(missionAudioSfx) / 1000; - m_sMissionAudio.m_nMissionAudioCounter[slot] *= 4; - m_sMissionAudio.m_bIsPlayed[slot] = FALSE; - m_sMissionAudio.m_bPredefinedProperties[slot] = TRUE; + m_nMissionAudioSampleIndex[slot] = missionAudioSfx; + m_nMissionAudioLoadingStatus[slot] = LOADING_STATUS_NOT_LOADED; + m_nMissionAudioPlayStatus[slot] = PLAY_STATUS_STOPPED; + m_bIsMissionAudioPlaying[slot] = FALSE; + m_nMissionAudioFramesToPlay[slot] = m_nTimeSpent * SampleManager.GetStreamedFileLength(missionAudioSfx) / 1000; + m_nMissionAudioFramesToPlay[slot] *= 4; + m_bIsMissionAudioAllowedToPlay[slot] = FALSE; + m_bIsMissionAudio2D[slot] = TRUE; g_bMissionAudioLoadFailed[slot] = FALSE; } } @@ -9855,7 +9849,7 @@ uint8 cAudioManager::GetMissionAudioLoadingStatus(uint8 slot) { if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS) - return m_sMissionAudio.m_nLoadingStatus[slot]; + return m_nMissionAudioLoadingStatus[slot]; return LOADING_STATUS_LOADED; } @@ -9864,24 +9858,24 @@ void cAudioManager::SetMissionAudioLocation(uint8 slot, float x, float y, float z) { if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS) { - m_sMissionAudio.m_bPredefinedProperties[slot] = FALSE; - m_sMissionAudio.m_vecPos[slot] = CVector(x, y, z); + m_bIsMissionAudio2D[slot] = FALSE; + m_vecMissionAudioPosition[slot] = CVector(x, y, z); } } void cAudioManager::PlayLoadedMissionAudio(uint8 slot) { - if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS && m_sMissionAudio.m_nSampleIndex[slot] != NO_SAMPLE && m_sMissionAudio.m_nLoadingStatus[slot] == LOADING_STATUS_LOADED && - m_sMissionAudio.m_nPlayStatus[slot] == PLAY_STATUS_STOPPED) - m_sMissionAudio.m_bIsPlayed[slot] = TRUE; + if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS && m_nMissionAudioSampleIndex[slot] != NO_SAMPLE && m_nMissionAudioLoadingStatus[slot] == LOADING_STATUS_LOADED && + m_nMissionAudioPlayStatus[slot] == PLAY_STATUS_STOPPED) + m_bIsMissionAudioAllowedToPlay[slot] = TRUE; } bool8 cAudioManager::ShouldDuckMissionAudio(uint8 slot) { if (IsMissionAudioSamplePlaying(slot)) - return m_sMissionAudio.m_nSampleIndex[slot] != STREAMED_SOUND_MISSION_ROK2_01; + return m_nMissionAudioSampleIndex[slot] != STREAMED_SOUND_MISSION_ROK2_01; return FALSE; } @@ -9890,7 +9884,7 @@ cAudioManager::IsMissionAudioSamplePlaying(uint8 slot) { if (m_bIsInitialised) { if (slot < MISSION_AUDIO_SLOTS) - return m_sMissionAudio.m_nPlayStatus[slot] == PLAY_STATUS_PLAYING; + return m_nMissionAudioPlayStatus[slot] == PLAY_STATUS_PLAYING; else return TRUE; } else { @@ -9905,7 +9899,7 @@ cAudioManager::IsMissionAudioSampleFinished(uint8 slot) { if (m_bIsInitialised) { if (slot < MISSION_AUDIO_SLOTS) - return m_sMissionAudio.m_nPlayStatus[slot] == PLAY_STATUS_FINISHED; + return m_nMissionAudioPlayStatus[slot] == PLAY_STATUS_FINISHED; else return TRUE; } @@ -9919,14 +9913,14 @@ void cAudioManager::ClearMissionAudio(uint8 slot) { if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS) { - m_sMissionAudio.m_nSampleIndex[slot] = NO_SAMPLE; - m_sMissionAudio.m_nLoadingStatus[slot] = LOADING_STATUS_NOT_LOADED; - m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_STOPPED; - m_sMissionAudio.m_bIsPlaying[slot] = FALSE; - m_sMissionAudio.m_bIsPlayed[slot] = FALSE; - m_sMissionAudio.m_bPredefinedProperties[slot] = TRUE; - m_sMissionAudio.m_nMissionAudioCounter[slot] = 0; - m_sMissionAudio.m_bIsMobile[slot] = FALSE; + m_nMissionAudioSampleIndex[slot] = NO_SAMPLE; + m_nMissionAudioLoadingStatus[slot] = LOADING_STATUS_NOT_LOADED; + m_nMissionAudioPlayStatus[slot] = PLAY_STATUS_STOPPED; + m_bIsMissionAudioPlaying[slot] = FALSE; + m_bIsMissionAudioAllowedToPlay[slot] = FALSE; + m_bIsMissionAudio2D[slot] = TRUE; + m_nMissionAudioFramesToPlay[slot] = 0; + m_bIsMissionAudioPhoneCall[slot] = FALSE; SampleManager.StopStreamedFile(slot + 1); } } @@ -9944,16 +9938,16 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) static uint8 nFramesUntilFailedLoad[MISSION_AUDIO_SLOTS] = { 0, 0 }; static uint8 nFramesForPretendPlaying[MISSION_AUDIO_SLOTS] = { 0, 0 }; - if (m_sMissionAudio.m_nSampleIndex[slot] == NO_SAMPLE) return; + if (m_nMissionAudioSampleIndex[slot] == NO_SAMPLE) return; - switch (m_sMissionAudio.m_nLoadingStatus[slot]) { + switch (m_nMissionAudioLoadingStatus[slot]) { case LOADING_STATUS_NOT_LOADED: - SampleManager.PreloadStreamedFile(m_sMissionAudio.m_nSampleIndex[slot], slot + 1); - m_sMissionAudio.m_nLoadingStatus[slot] = LOADING_STATUS_LOADED; + SampleManager.PreloadStreamedFile(m_nMissionAudioSampleIndex[slot], slot + 1); + m_nMissionAudioLoadingStatus[slot] = LOADING_STATUS_LOADED; nFramesUntilFailedLoad[slot] = 0; break; case LOADING_STATUS_LOADED: - if (!m_sMissionAudio.m_bIsPlayed[slot]) + if (!m_bIsMissionAudioAllowedToPlay[slot]) return; if (g_bMissionAudioLoadFailed[slot]) { if (m_bTimerJustReset) { @@ -9964,30 +9958,30 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) nFramesUntilFailedLoad[slot] = 0; } else if (!m_nUserPause) { if (++nFramesForPretendPlaying[slot] < 90) { - m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_PLAYING; + m_nMissionAudioPlayStatus[slot] = PLAY_STATUS_PLAYING; } else { - m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_FINISHED; - m_sMissionAudio.m_nSampleIndex[slot] = NO_SAMPLE; + m_nMissionAudioPlayStatus[slot] = PLAY_STATUS_FINISHED; + m_nMissionAudioSampleIndex[slot] = NO_SAMPLE; } } break; } - switch (m_sMissionAudio.m_nPlayStatus[slot]) { + switch (m_nMissionAudioPlayStatus[slot]) { case PLAY_STATUS_STOPPED: - if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex[slot])) { - SetMissionScriptPoliceAudio(m_sMissionAudio.m_nSampleIndex[slot]); + if (MissionScriptAudioUsesPoliceChannel(m_nMissionAudioSampleIndex[slot])) { + SetMissionScriptPoliceAudio(m_nMissionAudioSampleIndex[slot]); } else { if (m_nUserPause) SampleManager.PauseStream(TRUE, slot + 1); - if (m_sMissionAudio.m_bPredefinedProperties[slot]) { - if (m_sMissionAudio.m_nSampleIndex[slot] == STREAMED_SOUND_MISSION_CAMERAL) + if (m_bIsMissionAudio2D[slot]) { + if (m_nMissionAudioSampleIndex[slot] == STREAMED_SOUND_MISSION_CAMERAL) SampleManager.SetStreamedVolumeAndPan(80, 0, TRUE, slot + 1); - else if (m_sMissionAudio.m_nSampleIndex[slot] == STREAMED_SOUND_MISSION_CAMERAR) + else if (m_nMissionAudioSampleIndex[slot] == STREAMED_SOUND_MISSION_CAMERAR) SampleManager.SetStreamedVolumeAndPan(80, 127, TRUE, slot + 1); else SampleManager.SetStreamedVolumeAndPan(80, 63, TRUE, slot + 1); } else { - distSquared = GetDistanceSquared(m_sMissionAudio.m_vecPos[slot]); + distSquared = GetDistanceSquared(m_vecMissionAudioPosition[slot]); if (distSquared >= SQR(80.0f)) { emittingVol = 0; pan = 63; @@ -9997,17 +9991,17 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) dist = Sqrt(distSquared); emittingVol = ComputeVolume(80, 80.0f, dist); } - TranslateEntity(&m_sMissionAudio.m_vecPos[slot], &vec); + TranslateEntity(&m_vecMissionAudioPosition[slot], &vec); pan = ComputePan(80.f, &vec); } SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, TRUE, slot + 1); } SampleManager.StartPreloadedStreamedFile(slot + 1); } - m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_PLAYING; + m_nMissionAudioPlayStatus[slot] = PLAY_STATUS_PLAYING; nCheckPlayingDelay[slot] = 30; - if (m_sMissionAudio.m_nSampleIndex[slot] >= STREAMED_SOUND_MISSION_MOB_01A && m_sMissionAudio.m_nSampleIndex[slot] <= STREAMED_SOUND_MISSION_MOB_99A) - m_sMissionAudio.m_bIsMobile[slot] = TRUE; + if (m_nMissionAudioSampleIndex[slot] >= STREAMED_SOUND_MISSION_MOB_01A && m_nMissionAudioSampleIndex[slot] <= STREAMED_SOUND_MISSION_MOB_99A) + m_bIsMissionAudioPhoneCall[slot] = TRUE; break; case PLAY_STATUS_PLAYING: if (m_bTimerJustReset) { @@ -10015,28 +10009,28 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) SampleManager.StopStreamedFile(slot + 1); break; } - if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex[slot])) { + if (MissionScriptAudioUsesPoliceChannel(m_nMissionAudioSampleIndex[slot])) { if (!m_nUserPause) { if (nCheckPlayingDelay[slot]) { --nCheckPlayingDelay[slot]; - } else if ((g_bMissionAudioLoadFailed[slot] && m_sMissionAudio.m_nMissionAudioCounter[slot]-- == 0) || GetMissionScriptPoliceAudioPlayingStatus() == PLAY_STATUS_FINISHED) { - m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_FINISHED; - if (m_sMissionAudio.m_nSampleIndex[slot] >= STREAMED_SOUND_MISSION_MOB_01A && m_sMissionAudio.m_nSampleIndex[slot] <= STREAMED_SOUND_MISSION_MOB_99A) - m_sMissionAudio.m_bIsMobile[slot] = FALSE; - m_sMissionAudio.m_nSampleIndex[slot] = NO_SAMPLE; + } else if ((g_bMissionAudioLoadFailed[slot] && m_nMissionAudioFramesToPlay[slot]-- == 0) || GetMissionScriptPoliceAudioPlayingStatus() == PLAY_STATUS_FINISHED) { + m_nMissionAudioPlayStatus[slot] = PLAY_STATUS_FINISHED; + if (m_nMissionAudioSampleIndex[slot] >= STREAMED_SOUND_MISSION_MOB_01A && m_nMissionAudioSampleIndex[slot] <= STREAMED_SOUND_MISSION_MOB_99A) + m_bIsMissionAudioPhoneCall[slot] = FALSE; + m_nMissionAudioSampleIndex[slot] = NO_SAMPLE; SampleManager.StopStreamedFile(slot + 1); - m_sMissionAudio.m_nMissionAudioCounter[slot] = 0; + m_nMissionAudioFramesToPlay[slot] = 0; } } - } else if (m_sMissionAudio.m_bIsPlaying[slot]) { + } else if (m_bIsMissionAudioPlaying[slot]) { if (SampleManager.IsStreamPlaying(slot + 1) || m_nUserPause || m_nPreviousUserPause) { if (m_nUserPause) SampleManager.PauseStream(TRUE, slot + 1); else { SampleManager.PauseStream(FALSE, slot + 1); - if (!m_sMissionAudio.m_bPredefinedProperties[slot]) { - distSquared = GetDistanceSquared(m_sMissionAudio.m_vecPos[slot]); + if (!m_bIsMissionAudio2D[slot]) { + distSquared = GetDistanceSquared(m_vecMissionAudioPosition[slot]); if (distSquared >= SQR(80.0f)) { emittingVol = 0; pan = 63; @@ -10046,21 +10040,21 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) dist = Sqrt(distSquared); emittingVol = ComputeVolume(127, 80.0f, dist); } - TranslateEntity(&m_sMissionAudio.m_vecPos[slot], &vec); + TranslateEntity(&m_vecMissionAudioPosition[slot], &vec); pan = ComputePan(80.f, &vec); } SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, TRUE, slot + 1); } } - } else if (m_sMissionAudio.m_nSampleIndex[slot] == STREAMED_SOUND_MISSION_ROK2_01) { - m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_STOPPED; + } else if (m_nMissionAudioSampleIndex[slot] == STREAMED_SOUND_MISSION_ROK2_01) { + m_nMissionAudioPlayStatus[slot] = PLAY_STATUS_STOPPED; } else { - m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_FINISHED; - if (m_sMissionAudio.m_nSampleIndex[slot] >= STREAMED_SOUND_MISSION_MOB_01A && m_sMissionAudio.m_nSampleIndex[slot] <= STREAMED_SOUND_MISSION_MOB_99A) - m_sMissionAudio.m_bIsMobile[slot] = FALSE; - m_sMissionAudio.m_nSampleIndex[slot] = NO_SAMPLE; + m_nMissionAudioPlayStatus[slot] = PLAY_STATUS_FINISHED; + if (m_nMissionAudioSampleIndex[slot] >= STREAMED_SOUND_MISSION_MOB_01A && m_nMissionAudioSampleIndex[slot] <= STREAMED_SOUND_MISSION_MOB_99A) + m_bIsMissionAudioPhoneCall[slot] = FALSE; + m_nMissionAudioSampleIndex[slot] = NO_SAMPLE; SampleManager.StopStreamedFile(slot + 1); - m_sMissionAudio.m_nMissionAudioCounter[slot] = 0; + m_nMissionAudioFramesToPlay[slot] = 0; } } else { if (m_nUserPause) @@ -10070,7 +10064,7 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) break; nCheckPlayingDelay[slot] = 0; } - m_sMissionAudio.m_bIsPlaying[slot] = TRUE; + m_bIsMissionAudioPlaying[slot] = TRUE; } break; default: @@ -10082,7 +10076,7 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) nFramesForPretendPlaying[slot] = 0; g_bMissionAudioLoadFailed[slot] = TRUE; nFramesUntilFailedLoad[slot] = 0; - m_sMissionAudio.m_nLoadingStatus[slot] = LOADING_STATUS_LOADED; + m_nMissionAudioLoadingStatus[slot] = LOADING_STATUS_LOADED; } break; default: @@ -10098,12 +10092,12 @@ cAudioManager::ProcessMissionAudio() for (int i = 0; i < MISSION_AUDIO_SLOTS; i++) ProcessMissionAudioSlot(i); - if (m_sMissionAudio.m_bIsMobile[0] || m_sMissionAudio.m_bIsMobile[1]) - field_5538 = 64; - else if (field_5538 < 127) { - field_5538 += 5; - if (field_5538 > 127) - field_5538 = 127; + if (m_bIsMissionAudioPhoneCall[0] || m_bIsMissionAudioPhoneCall[1]) + m_nGlobalSfxVolumeMultiplier = 64; + else if (m_nGlobalSfxVolumeMultiplier < 127) { + m_nGlobalSfxVolumeMultiplier += 5; + if (m_nGlobalSfxVolumeMultiplier > 127) + m_nGlobalSfxVolumeMultiplier = 127; } } #pragma endregion All the mission audio stuff diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index 2bb17bfb..e42712dc 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -999,7 +999,7 @@ cAudioManager::ProcessActiveQueues() uint8 emittingVol; CVector position; - bool8 missionState; + bool8 isPhoneCall; uint8 channelOffset = 0; for (int32 i = 0; i < m_nActiveSamples; i++) { @@ -1065,18 +1065,18 @@ cAudioManager::ProcessActiveQueues() #endif emittingVol = m_bDoubleVolume ? 2 * Min(63, vol) : vol; - missionState = FALSE; + isPhoneCall = FALSE; for (int32 k = 0; k < MISSION_AUDIO_SLOTS; k++) { - if (m_sMissionAudio.m_bIsMobile[k]) { - missionState = TRUE; + if (m_bIsMissionAudioPhoneCall[k]) { + isPhoneCall = TRUE; break; } } - if (missionState) { - emittingVol = (emittingVol * field_5538) / 127; + if (isPhoneCall) { + emittingVol = (emittingVol * m_nGlobalSfxVolumeMultiplier) / 127; } else { - if (field_5538 < 127) - emittingVol = (emittingVol * field_5538) / 127; + if (m_nGlobalSfxVolumeMultiplier < 127) + emittingVol = (emittingVol * m_nGlobalSfxVolumeMultiplier) / 127; } #ifdef EXTERNAL_3D_SOUND @@ -1154,19 +1154,19 @@ cAudioManager::ProcessActiveQueues() if (SampleManager.InitialiseChannel(k, m_asActiveSamples[k].m_nSampleIndex, m_asActiveSamples[k].m_nBankIndex)) { #endif SampleManager.SetChannelFrequency(k, m_asActiveSamples[k].m_nFrequency); - bool8 isMobile = FALSE; + isPhoneCall = FALSE; for (int32 l = 0; l < MISSION_AUDIO_SLOTS; l++) { - if (m_sMissionAudio.m_bIsMobile[l]) { - isMobile = TRUE; + if (m_bIsMissionAudioPhoneCall[l]) { + isPhoneCall = TRUE; break; } } - if (!isMobile || m_asActiveSamples[k].m_bIs2D) { - if (field_5538 < 127) - emittingVol *= field_5538 / 127; + if (!isPhoneCall || m_asActiveSamples[k].m_bIs2D) { + if (m_nGlobalSfxVolumeMultiplier < 127) + emittingVol = (emittingVol * m_nGlobalSfxVolumeMultiplier) / 127; vol = emittingVol; } else { - vol = (emittingVol * field_5538 / 127); + vol = (emittingVol * m_nGlobalSfxVolumeMultiplier) / 127; } #ifdef EXTERNAL_3D_SOUND SampleManager.SetChannelEmittingVolume(k, vol); diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index 6580fb12..821732df 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -119,27 +119,8 @@ public: VALIDATE_SIZE(cPedComments, 0x490); -class CEntity; - #define MISSION_AUDIO_SLOTS (2) -// So instead of doing cMissionAudio [2] they've added [2] to every field of the struct... -// Only someone with a VERY EXTRAORDINARY mind could have come up with that -class cMissionAudio -{ -public: - CVector m_vecPos[MISSION_AUDIO_SLOTS]; - bool8 m_bPredefinedProperties[MISSION_AUDIO_SLOTS]; - uint32 m_nSampleIndex[MISSION_AUDIO_SLOTS]; - uint8 m_nLoadingStatus[MISSION_AUDIO_SLOTS]; - uint8 m_nPlayStatus[MISSION_AUDIO_SLOTS]; - bool8 m_bIsPlaying[MISSION_AUDIO_SLOTS]; - int32 m_nMissionAudioCounter[MISSION_AUDIO_SLOTS]; - bool8 m_bIsPlayed[MISSION_AUDIO_SLOTS]; - bool8 m_bIsMobile[MISSION_AUDIO_SLOTS]; -}; -VALIDATE_SIZE(cMissionAudio, 0x38); - // name made up class cAudioScriptObjectManager { @@ -153,6 +134,7 @@ public: class cTransmission; +class CEntity; class CPlane; class CVehicle; class CPed; @@ -263,7 +245,7 @@ public: bool8 m_bIsPlayerShutUp; uint8 m_nPlayerMood; uint32 m_nPlayerMoodTimer; - uint8 field_rest[4]; + uint32 field_4B38_vc; bool8 m_bGenericSfx; cPedComments m_sPedComments; @@ -271,17 +253,31 @@ public: int32 m_nWaterCannonEntity; int32 m_nPoliceChannelEntity; cPoliceRadioQueue m_sPoliceRadioQueue; + cAMCrime m_aCrimes[10]; int32 m_nFrontEndEntity; int32 m_nCollisionEntity; cAudioCollisionManager m_sCollisionManager; int32 m_nProjectileEntity; + int32 m_nEscalatorEntity; + int32 m_nExtraSoundsEntity; #ifdef GTA_BRIDGE int32 m_nBridgeEntity; #endif - int32 m_nEscalatorEntity; - int32 m_nExtraSoundsEntity; - cMissionAudio m_sMissionAudio; - uint8 field_5538; // something related to phone dialogues + + // Mission audio stuff + // So instead of making an array of struct they've added [MISSION_AUDIO_SLOTS] to every field... + // Only someone with a VERY EXTRAORDINARY mind could have come up with that + CVector m_vecMissionAudioPosition[MISSION_AUDIO_SLOTS]; + bool8 m_bIsMissionAudio2D[MISSION_AUDIO_SLOTS]; + uint32 m_nMissionAudioSampleIndex[MISSION_AUDIO_SLOTS]; + uint8 m_nMissionAudioLoadingStatus[MISSION_AUDIO_SLOTS]; + uint8 m_nMissionAudioPlayStatus[MISSION_AUDIO_SLOTS]; + bool8 m_bIsMissionAudioPlaying[MISSION_AUDIO_SLOTS]; + int32 m_nMissionAudioFramesToPlay[MISSION_AUDIO_SLOTS]; + 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; diff --git a/src/audio/PolRadio.cpp b/src/audio/PolRadio.cpp index 2b45b526..da09eeb9 100644 --- a/src/audio/PolRadio.cpp +++ b/src/audio/PolRadio.cpp @@ -59,11 +59,9 @@ cAudioManager::InitialisePoliceRadioZones() void cAudioManager::InitialisePoliceRadio() { - m_sPoliceRadioQueue.policeChannelTimer = 0; - m_sPoliceRadioQueue.policeChannelTimerSeconds = 0; - m_sPoliceRadioQueue.policeChannelCounterSeconds = 0; - for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) - m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE; + m_sPoliceRadioQueue.Reset(); + for (int32 i = 0; i < ARRAY_SIZE(m_aCrimes); i++) + m_aCrimes[i].type = CRIME_NONE; #if !defined(GTA_PS2) || defined(AUDIO_REVERB) SampleManager.SetChannelReverbFlag(CHANNEL_POLICE_RADIO, FALSE); #endif @@ -179,7 +177,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel) bMissionAudioPhysicalPlayingStatus == PLAY_STATUS_PLAYING) { SampleManager.PauseStream(FALSE, 1); } - if (m_sPoliceRadioQueue.policeChannelTimer == 0) bChannelOpen = FALSE; + if (m_sPoliceRadioQueue.m_nSamplesInQueue == 0) bChannelOpen = FALSE; if (cWait) { #ifdef FIX_BUGS cWait -= CTimer::GetLogicalFramesPassed(); @@ -216,14 +214,8 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel) } if (bChannelOpen) DoPoliceRadioCrackle(); if ((g_nMissionAudioSfx == NO_SAMPLE || g_nMissionAudioPlayingStatus != PLAY_STATUS_PLAYING) && - !SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO) && m_sPoliceRadioQueue.policeChannelTimer) { - if (m_sPoliceRadioQueue.policeChannelTimer) { - sample = m_sPoliceRadioQueue.crimesSamples[m_sPoliceRadioQueue.policeChannelCounterSeconds]; - m_sPoliceRadioQueue.policeChannelTimer--; - m_sPoliceRadioQueue.policeChannelCounterSeconds = (m_sPoliceRadioQueue.policeChannelCounterSeconds + 1) % 60; - } else { - sample = NO_SAMPLE; - } + !SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO) && m_sPoliceRadioQueue.m_nSamplesInQueue != 0) { + sample = m_sPoliceRadioQueue.Remove(); if (wantedLevel == 0) { if (gSpecialSuspectLastSeenReport) { gSpecialSuspectLastSeenReport = FALSE; @@ -275,18 +267,18 @@ cAudioManager::SetupCrimeReport() if (MusicManager.m_nMusicMode == MUSICMODE_CUTSCENE) return FALSE; - if (60 - m_sPoliceRadioQueue.policeChannelTimer <= 9) { + if (60 - m_sPoliceRadioQueue.m_nSamplesInQueue <= 9) { AgeCrimes(); return TRUE; } - for (i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) { - if (m_sPoliceRadioQueue.crimes[i].type != CRIME_NONE) + for (i = 0; i < ARRAY_SIZE(m_aCrimes); i++) { + if (m_aCrimes[i].type != CRIME_NONE) break; } - if (i == ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) return FALSE; - audioZoneId = CTheZones::FindAudioZone(&m_sPoliceRadioQueue.crimes[i].position); + if (i == ARRAY_SIZE(m_aCrimes)) return FALSE; + audioZoneId = CTheZones::FindAudioZone(&m_aCrimes[i].position); if (audioZoneId >= 0 && audioZoneId < NUMAUDIOZONES) { zone = CTheZones::GetAudioZone(audioZoneId); for (int j = 0; j < NUMAUDIOZONES; j++) { @@ -295,24 +287,24 @@ cAudioManager::SetupCrimeReport() m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_MESSAGE_NOISE_1); m_sPoliceRadioQueue.Add(m_anRandomTable[0] % 3 + SFX_WEVE_GOT); m_sPoliceRadioQueue.Add(SFX_A_10); - switch (m_sPoliceRadioQueue.crimes[i].type) { + switch (m_aCrimes[i].type) { case CRIME_PED_BURNED: case CRIME_HIT_PED_NASTYWEAPON: - m_sPoliceRadioQueue.crimes[i].type = CRIME_HIT_PED; + m_aCrimes[i].type = CRIME_HIT_PED; break; case CRIME_COP_BURNED: case CRIME_HIT_COP_NASTYWEAPON: - m_sPoliceRadioQueue.crimes[i].type = CRIME_HIT_COP; + m_aCrimes[i].type = CRIME_HIT_COP; break; - case CRIME_VEHICLE_BURNED: m_sPoliceRadioQueue.crimes[i].type = CRIME_STEAL_CAR; break; - case CRIME_DESTROYED_CESSNA: m_sPoliceRadioQueue.crimes[i].type = CRIME_SHOOT_HELI; break; - case CRIME_EXPLOSION: m_sPoliceRadioQueue.crimes[i].type = CRIME_STEAL_CAR; break; // huh? + case CRIME_VEHICLE_BURNED: m_aCrimes[i].type = CRIME_STEAL_CAR; break; + case CRIME_DESTROYED_CESSNA: m_aCrimes[i].type = CRIME_SHOOT_HELI; break; + case CRIME_EXPLOSION: m_aCrimes[i].type = CRIME_STEAL_CAR; break; // huh? default: break; } #ifdef FIX_BUGS - m_sPoliceRadioQueue.Add(m_sPoliceRadioQueue.crimes[i].type + SFX_CRIME_1 - 1); + m_sPoliceRadioQueue.Add(m_aCrimes[i].type + SFX_CRIME_1 - 1); #else - m_sPoliceRadioQueue.Add(m_sPoliceRadioQueue.crimes[i].type + SFX_CRIME_1); + m_sPoliceRadioQueue.Add(m_aCrimes[i].type + SFX_CRIME_1); #endif m_sPoliceRadioQueue.Add(SFX_IN); rangeX = zone->maxx - zone->minx; @@ -322,17 +314,17 @@ cAudioManager::SetupCrimeReport() quarterX = 0.25f * rangeX; quarterY = 0.25f * rangeY; - if (m_sPoliceRadioQueue.crimes[i].position.y > halfY + quarterY) { + if (m_aCrimes[i].position.y > halfY + quarterY) { m_sPoliceRadioQueue.Add(SFX_NORTH); processed = TRUE; - } else if (m_sPoliceRadioQueue.crimes[i].position.y < halfY - quarterY) { + } else if (m_aCrimes[i].position.y < halfY - quarterY) { m_sPoliceRadioQueue.Add(SFX_SOUTH); processed = TRUE; } - if (m_sPoliceRadioQueue.crimes[i].position.x > halfX + quarterX) + if (m_aCrimes[i].position.x > halfX + quarterX) m_sPoliceRadioQueue.Add(SFX_EAST); - else if (m_sPoliceRadioQueue.crimes[i].position.x < halfX - quarterX) + else if (m_aCrimes[i].position.x < halfX - quarterX) m_sPoliceRadioQueue.Add(SFX_WEST); else if (!processed) m_sPoliceRadioQueue.Add(SFX_CENTRAL); @@ -344,7 +336,7 @@ cAudioManager::SetupCrimeReport() } } } - m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE; + m_aCrimes[i].type = CRIME_NONE; AgeCrimes(); return TRUE; } @@ -461,7 +453,7 @@ cAudioManager::SetupSuspectLastSeenReport() if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE) { veh = FindVehicleOfPlayer(); if (veh != nil) { - if (60 - m_sPoliceRadioQueue.policeChannelTimer > 9) { + if (POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue > 9) { color1 = veh->m_currentColour1; if (color1 >= ARRAY_SIZE(gCarColourTable)) { debug("\n *** UNKNOWN CAR COLOUR %d *** ", color1); @@ -647,7 +639,7 @@ cAudioManager::SetupSuspectLastSeenReport() m_sPoliceRadioQueue.Add(NO_SAMPLE); } } - } else if (60 - m_sPoliceRadioQueue.policeChannelTimer > 4) { + } else if (POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue > 4) { m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_MESSAGE_NOISE_1); m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_SUSPECT); m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_ON_FOOT); @@ -660,24 +652,24 @@ cAudioManager::SetupSuspectLastSeenReport() void cAudioManager::ReportCrime(eCrimeType type, const CVector &pos) { - int32 lastCrime = ARRAY_SIZE(m_sPoliceRadioQueue.crimes); + int32 lastCrime = ARRAY_SIZE(m_aCrimes); if (m_bIsInitialised && MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && FindPlayerPed()->m_pWanted->GetWantedLevel() > 0 && (type > CRIME_NONE || type < NUM_CRIME_TYPES) && m_FrameCounter >= gMinTimeToNextReport[type]) { - for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) { - if (m_sPoliceRadioQueue.crimes[i].type != CRIME_NONE) { - if (m_sPoliceRadioQueue.crimes[i].type == type) { - m_sPoliceRadioQueue.crimes[i].position = pos; - m_sPoliceRadioQueue.crimes[i].timer = 0; + for (int32 i = 0; i < ARRAY_SIZE(m_aCrimes); i++) { + if (m_aCrimes[i].type != CRIME_NONE) { + if (m_aCrimes[i].type == type) { + m_aCrimes[i].position = pos; + m_aCrimes[i].timer = 0; return; } } else lastCrime = i; } - if (lastCrime < ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) { - m_sPoliceRadioQueue.crimes[lastCrime].type = type; - m_sPoliceRadioQueue.crimes[lastCrime].position = pos; - m_sPoliceRadioQueue.crimes[lastCrime].timer = 0; + if (lastCrime < ARRAY_SIZE(m_aCrimes)) { + m_aCrimes[lastCrime].type = type; + m_aCrimes[lastCrime].position = pos; + m_aCrimes[lastCrime].timer = 0; gMinTimeToNextReport[type] = m_FrameCounter + 500; } } @@ -700,7 +692,7 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z) if (!m_bIsInitialised) return; - if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && 60 - m_sPoliceRadioQueue.policeChannelTimer > 9) { + if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue > 9) { audioZone = CTheZones::FindAudioZone(&vec); if (audioZone >= 0 && audioZone < NUMAUDIOZONES) { zone = CTheZones::GetAudioZone(audioZone); @@ -746,9 +738,9 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z) void cAudioManager::AgeCrimes() { - for (uint8 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) { - if (m_sPoliceRadioQueue.crimes[i].type != CRIME_NONE) { - if (++m_sPoliceRadioQueue.crimes[i].timer > 1200) m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE; + for (uint8 i = 0; i < ARRAY_SIZE(m_aCrimes); i++) { + if (m_aCrimes[i].type != CRIME_NONE) { + if (++m_aCrimes[i].timer > 1200) m_aCrimes[i].type = CRIME_NONE; } } } diff --git a/src/audio/PolRadio.h b/src/audio/PolRadio.h index d7c928e2..55b2c9f7 100644 --- a/src/audio/PolRadio.h +++ b/src/audio/PolRadio.h @@ -1,6 +1,7 @@ #pragma once #include "Crime.h" +#include "AudioSamples.h" struct cAMCrime { int32 type; @@ -17,30 +18,50 @@ struct cAMCrime { VALIDATE_SIZE(cAMCrime, 20); +#define POLICE_RADIO_QUEUE_MAX_SAMPLES 60 + class cPoliceRadioQueue { public: - int32 crimesSamples[60]; - uint8 policeChannelTimer; - uint8 policeChannelTimerSeconds; - uint8 policeChannelCounterSeconds; - cAMCrime crimes[10]; + uint32 m_aSamples[POLICE_RADIO_QUEUE_MAX_SAMPLES]; + uint8 m_nSamplesInQueue; + uint8 m_nAddOffset; + uint8 m_nRemoveOffset; cPoliceRadioQueue() { - policeChannelTimerSeconds = 0; - policeChannelCounterSeconds = 0; - policeChannelTimer = 0; + Reset(); + } + + void Reset() + { + m_nAddOffset = 0; + m_nRemoveOffset = 0; + m_nSamplesInQueue = 0; } - void Add(uint32 sample) + bool8 Add(uint32 sample) { - if (policeChannelTimer != 60) { - crimesSamples[policeChannelTimerSeconds] = sample; - policeChannelTimer++; - policeChannelTimerSeconds = (policeChannelTimerSeconds + 1) % 60; + if (m_nSamplesInQueue != POLICE_RADIO_QUEUE_MAX_SAMPLES) { + m_aSamples[m_nAddOffset] = sample; + m_nSamplesInQueue++; + m_nAddOffset = (m_nAddOffset + 1) % POLICE_RADIO_QUEUE_MAX_SAMPLES; + return TRUE; } + return FALSE; } + + uint32 Remove() + { + if (m_nSamplesInQueue != 0) { + uint32 sample = m_aSamples[m_nRemoveOffset]; + m_nSamplesInQueue--; + m_nRemoveOffset = (m_nRemoveOffset + 1) % POLICE_RADIO_QUEUE_MAX_SAMPLES; + return sample; + } + return NO_SAMPLE; + } + }; -VALIDATE_SIZE(cPoliceRadioQueue, 0x1BC); +VALIDATE_SIZE(cPoliceRadioQueue, 244); |