Fixes to MusicManager

This commit is contained in:
Sergeanur 2020-09-19 16:39:31 +03:00
parent 7efc153dc9
commit db2c34923d
2 changed files with 32 additions and 34 deletions

View file

@ -213,7 +213,7 @@ public:
float GetReflectionsDistance(int32 idx) const { return m_afReflectionsDistances[idx]; } float GetReflectionsDistance(int32 idx) const { return m_afReflectionsDistances[idx]; }
int32 GetRandomNumber(int32 idx) const { return m_anRandomTable[idx]; } int32 GetRandomNumber(int32 idx) const { return m_anRandomTable[idx]; }
int32 GetRandomNumberInRange(int32 idx, int32 low, int32 high) const { return (m_anRandomTable[idx] % (high - low + 1)) + low; } int32 GetRandomNumberInRange(int32 idx, int32 low, int32 high) const { return (m_anRandomTable[idx] % (high - low + 1)) + low; }
bool IsMissionAudioSamplePlaying() const { return m_sMissionAudio.m_nPlayStatus == 1; } bool ShouldDuckMissionAudio() const { return m_sMissionAudio.m_nPlayStatus == 1; }
// "Should" be in alphabetic order, except "getXTalkSfx" // "Should" be in alphabetic order, except "getXTalkSfx"
void AddDetailsToRequestedOrderList(uint8 sample); void AddDetailsToRequestedOrderList(uint8 sample);

View file

@ -434,6 +434,7 @@ cMusicManager::ServiceGameMode()
{ {
bool bRadioOff = false; bool bRadioOff = false;
static int8 nFramesSinceCutsceneEnded = -1; static int8 nFramesSinceCutsceneEnded = -1;
uint8 volume;
m_bPreviousPlayerInCar = m_bPlayerInCar; m_bPreviousPlayerInCar = m_bPlayerInCar;
m_bPlayerInCar = PlayerInCar(); m_bPlayerInCar = PlayerInCar();
@ -520,25 +521,25 @@ cMusicManager::ServiceGameMode()
} }
if (CTimer::GetIsSlowMotionActive()) { if (CTimer::GetIsSlowMotionActive()) {
if (TheCamera.pTargetEntity != nil) { if (TheCamera.pTargetEntity != nil) {
float dist = (TheCamera.pTargetEntity->GetPosition() - TheCamera.GetPosition()).MagnitudeSqr(); float DistToTargetSq = (TheCamera.pTargetEntity->GetPosition() - TheCamera.GetPosition()).MagnitudeSqr();
if (dist >= 3025.0f) { if (DistToTargetSq >= SQR(55.0f)) {
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0); SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
} else if (dist >= 100.0f) { } else if (DistToTargetSq >= SQR(10.0f)) {
int8 volume = ((45.0f - (Sqrt(dist) - 10.0f)) / 45.0f * 100.0f); volume = ((45.0f - (Sqrt(DistToTargetSq) - 10.0f)) / 45.0f * 100.0f);
int8 pan; uint8 pan;
if (AudioManager.IsMissionAudioSamplePlaying()) if (AudioManager.ShouldDuckMissionAudio())
volume /= 4; volume /= 4;
if (volume != 0) { if (volume > 0) {
CVector trVec; CVector panVec;
AudioManager.TranslateEntity(&TheCamera.pTargetEntity->GetPosition(), &trVec); AudioManager.TranslateEntity(&TheCamera.pTargetEntity->GetPosition(), &panVec);
pan = AudioManager.ComputePan(55.0f, &trVec); pan = AudioManager.ComputePan(55.0f, &panVec);
} else { } else {
pan = 0; pan = 0;
} }
if (gRetuneCounter) if (gRetuneCounter)
volume /= 4; volume /= 4;
SampleManager.SetStreamedVolumeAndPan(volume, pan, 0, 0); SampleManager.SetStreamedVolumeAndPan(volume, pan, 0, 0);
} else if (AudioManager.IsMissionAudioSamplePlaying()) { } else if (AudioManager.ShouldDuckMissionAudio()) {
SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0); SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0);
} else if (gRetuneCounter) { } else if (gRetuneCounter) {
SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0); SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0);
@ -546,26 +547,24 @@ cMusicManager::ServiceGameMode()
SampleManager.SetStreamedVolumeAndPan(100, 63, 0, 0); SampleManager.SetStreamedVolumeAndPan(100, 63, 0, 0);
} }
} }
} else if (AudioManager.IsMissionAudioSamplePlaying()) { } else if (AudioManager.ShouldDuckMissionAudio()) {
SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0); SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0);
nFramesSinceCutsceneEnded = 0; nFramesSinceCutsceneEnded = 0;
} else { } else {
int8 volume;
if (nFramesSinceCutsceneEnded == -1) { if (nFramesSinceCutsceneEnded == -1) {
volume = 100; volume = 100;
} else if (nFramesSinceCutsceneEnded >= 20) { } else if (nFramesSinceCutsceneEnded < 20) {
if (nFramesSinceCutsceneEnded >= 40) {
nFramesSinceCutsceneEnded = -1;
volume = 100;
} else {
volume = 3 * (nFramesSinceCutsceneEnded - 20) + 25;
nFramesSinceCutsceneEnded++;
}
} else {
nFramesSinceCutsceneEnded++; nFramesSinceCutsceneEnded++;
volume = 25; volume = 25;
} else if (nFramesSinceCutsceneEnded < 40) {
volume = 3 * (nFramesSinceCutsceneEnded - 20) + 25;
nFramesSinceCutsceneEnded++;
} else {
nFramesSinceCutsceneEnded = -1;
volume = 100;
} }
if (gRetuneCounter) volume /= 4; if (gRetuneCounter != 0)
volume /= 4;
SampleManager.SetStreamedVolumeAndPan(volume, 63, 0, 0); SampleManager.SetStreamedVolumeAndPan(volume, 63, 0, 0);
} }
return; return;
@ -698,16 +697,15 @@ cMusicManager::StopCutSceneMusic(void)
uint32 uint32
cMusicManager::GetTrackStartPos(uint8 track) cMusicManager::GetTrackStartPos(uint8 track)
{ {
uint32 result; uint32 pos = m_aTracks[track].m_nPosition;
uint32 timer = m_aTracks[track].m_nLastPosCheckTimer; if (CTimer::GetTimeInMillisecondsPauseMode() > m_aTracks[track].m_nLastPosCheckTimer)
if (CTimer::GetTimeInMillisecondsPauseMode() <= timer) { pos += Min(CTimer::GetTimeInMillisecondsPauseMode() - m_aTracks[track].m_nLastPosCheckTimer, 90000);
result = m_aTracks[track].m_nPosition; else
m_aTracks[track].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); m_aTracks[track].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
} else
result = Min(CTimer::GetTimeInMillisecondsPauseMode() - timer, 90000) + m_aTracks[track].m_nPosition;
if (result > m_aTracks[track].m_nLength) result %= m_aTracks[track].m_nLength; if (pos > m_aTracks[track].m_nLength)
return result; pos %= m_aTracks[track].m_nLength;
return pos;
} }
@ -832,7 +830,7 @@ cMusicManager::ServiceAnnouncement()
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0); SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
if (SampleManager.StartStreamedFile(m_nAnnouncement, 0, 0)) { if (SampleManager.StartStreamedFile(m_nAnnouncement, 0, 0)) {
SampleManager.SetStreamedVolumeAndPan(AudioManager.IsMissionAudioSamplePlaying() ? 25 : 100, 63, 0, 0); SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, 0, 0);
m_bAnnouncementInProgress = true; m_bAnnouncementInProgress = true;
m_nPreviousStreamedSound = m_nCurrentStreamedSound; m_nPreviousStreamedSound = m_nCurrentStreamedSound;
m_nCurrentStreamedSound = m_nAnnouncement; m_nCurrentStreamedSound = m_nAnnouncement;
@ -905,7 +903,7 @@ cMusicManager::ChangeRadioChannel()
return false; return false;
if (!SampleManager.StartStreamedFile(m_nCurrentStreamedSound, GetTrackStartPos(m_nCurrentStreamedSound), 0)) if (!SampleManager.StartStreamedFile(m_nCurrentStreamedSound, GetTrackStartPos(m_nCurrentStreamedSound), 0))
return false; return false;
SampleManager.SetStreamedVolumeAndPan(AudioManager.IsMissionAudioSamplePlaying() ? 25 : 100, 63, 0, 0); SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, 0, 0);
} }
return true; return true;
} }