From d17d437de319ca4c388dc724cffea91702d3a699 Mon Sep 17 00:00:00 2001 From: withmorten Date: Mon, 28 Jun 2021 13:57:05 +0200 Subject: rename clamp macro to Clamp to fix compilation with g++11 (and clamp2 for consistency sake) --- src/audio/AudioLogic.cpp | 22 +++++++++++----------- src/audio/AudioManager.cpp | 8 ++++---- src/audio/oal/stream.cpp | 10 +++++----- src/audio/sampman_miles.cpp | 2 +- src/audio/sampman_oal.cpp | 4 ++-- 5 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/audio') diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp index e4340bdc..3ec40437 100644 --- a/src/audio/AudioLogic.cpp +++ b/src/audio/AudioLogic.cpp @@ -989,8 +989,8 @@ cAudioManager::ProcessModelVehicle(cVehicleParams& params) freq = 25000; } if (isPlayerVeh) { - volume = clamp2(volume, prevVolume, 7); - freq = clamp2(freq, prevFreq, 800); + volume = Clamp2(volume, prevVolume, 7); + freq = Clamp2(freq, prevFreq, 800); } if (volume > 0) { CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); @@ -1038,8 +1038,8 @@ cAudioManager::ProcessModelVehicle(cVehicleParams& params) freq = Min(22000, (8000 * acceletateState / 255 + 14000) * 3.0f * Abs(params.m_fVelocityChange)); } if (isPlayerVeh && !vehSlowdown) { - volume = clamp2(volume, prevVolume, 7); - freq = clamp2(freq, prevFreq, 800); + volume = Clamp2(volume, prevVolume, 7); + freq = Clamp2(freq, prevFreq, 800); } if (!vehSlowdown) #ifdef THIS_IS_STUPID @@ -1118,7 +1118,7 @@ cAudioManager::ProcessModelHeliVehicle(cVehicleParams& params) } if (acceletateState < brakeState) acceletateState = brakeState; - freq = clamp2(5 * acceletateState + 22050, prevFreq, 30); + freq = Clamp2(5 * acceletateState + 22050, prevFreq, 30); CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); m_sQueueSample.m_nVolume = ComputeVolume(70, SOUND_INTENSITY, m_sQueueSample.m_fDistance); if (m_sQueueSample.m_nVolume != 0) { @@ -1658,8 +1658,8 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh bHandbrakeOnLastFrame = FALSE; } if (CReplay::IsPlayingBack()) { - accelerateState = (255.0f * clamp(params.m_pVehicle->m_fGasPedal, 0.0f, 1.0f)); - brakeState = (255.0f * clamp(params.m_pVehicle->m_fBrakePedal, 0.0f, 1.0f)); + accelerateState = (255.0f * Clamp(params.m_pVehicle->m_fGasPedal, 0.0f, 1.0f)); + brakeState = (255.0f * Clamp(params.m_pVehicle->m_fBrakePedal, 0.0f, 1.0f)); } else { accelerateState = Pads[0].GetAccelerate(); brakeState = Pads[0].GetBrake(); @@ -1810,7 +1810,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh } } relativeVelocityChange = 2.0f * params.m_fVelocityChange / params.m_pTransmission->fMaxVelocity; - accelerationMultipler = clamp(relativeVelocityChange, 0.0f, 1.0f); + accelerationMultipler = Clamp(relativeVelocityChange, 0.0f, 1.0f); gasPedalAudio = accelerationMultipler; switch (engineSoundType) { case SFX_BANK_MOPED: @@ -3585,7 +3585,7 @@ cAudioManager::ProcessCarHeli(cVehicleParams& params) m_sQueueSample.m_nFrequency = 14287 + Min(1.0f, freqModifier) * 3713; if (propellerSpeed < 1.0f) m_sQueueSample.m_nFrequency = (propellerSpeed + 1.0f) * (m_sQueueSample.m_nFrequency / 2.0f); - m_sQueueSample.m_nFrequency = clamp2(m_sQueueSample.m_nFrequency, freqFrontPrev, 197); + m_sQueueSample.m_nFrequency = Clamp2(m_sQueueSample.m_nFrequency, freqFrontPrev, 197); freqFrontPrev = m_sQueueSample.m_nFrequency; m_sQueueSample.m_bIs2D = FALSE; @@ -3641,7 +3641,7 @@ cAudioManager::ProcessCarHeli(cVehicleParams& params) if (propellerSpeed < 1.0f) m_sQueueSample.m_nFrequency = (propellerSpeed + 1) * (m_sQueueSample.m_nFrequency / 2); - m_sQueueSample.m_nFrequency = clamp2(m_sQueueSample.m_nFrequency, freqPropellerPrev, 98); + m_sQueueSample.m_nFrequency = Clamp2(m_sQueueSample.m_nFrequency, freqPropellerPrev, 98); freqPropellerPrev = m_sQueueSample.m_nFrequency; } else { m_sQueueSample.m_nSampleIndex = SFX_CAR_HELI_MAI2; @@ -3710,7 +3710,7 @@ cAudioManager::ProcessCarHeli(cVehicleParams& params) m_sQueueSample.m_nFrequency = 14287 + Min(1.0f, freqModifier) * 3713; if (propellerSpeed < 1.0f) m_sQueueSample.m_nFrequency = (propellerSpeed + 1) * (m_sQueueSample.m_nFrequency / 2.0f); - m_sQueueSample.m_nFrequency = clamp2(m_sQueueSample.m_nFrequency, freqSkimmerPrev, 197); + m_sQueueSample.m_nFrequency = Clamp2(m_sQueueSample.m_nFrequency, freqSkimmerPrev, 197); freqSkimmerPrev = m_sQueueSample.m_nFrequency; m_sQueueSample.m_nSampleIndex = SFX_SEAPLANE_PRO4; diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index aa6a0653..360a2275 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -331,7 +331,7 @@ cAudioManager::Get3DProviderName(uint8 id) const if (!m_bIsInitialised) return nil; #ifdef AUDIO_OAL - id = clamp(id, 0, SampleManager.GetNum3DProvidersAvailable() - 1); + id = Clamp(id, 0, SampleManager.GetNum3DProvidersAvailable() - 1); #else // We don't want that either since it will crash the game, but skipping for now if (id >= SampleManager.GetNum3DProvidersAvailable()) @@ -531,7 +531,7 @@ cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, if (dist != 0.0f) { float speedOfSource = (dist / m_nTimeSpent) * speedMultiplier; if (m_fSpeedOfSound > Abs(speedOfSource)) { - speedOfSource = clamp2(speedOfSource, 0.0f, 1.5f); + speedOfSource = Clamp2(speedOfSource, 0.0f, 1.5f); newFreq = (oldFreq * m_fSpeedOfSound) / (speedOfSource + m_fSpeedOfSound); } } @@ -895,11 +895,11 @@ cAudioManager::ProcessActiveQueues() sample.m_fSpeedMultiplier); if (sample.m_nFrequency != m_asActiveSamples[j].m_nFrequency) { - m_asActiveSamples[j].m_nFrequency = clamp2((int32)sample.m_nFrequency, (int32)m_asActiveSamples[j].m_nFrequency, 6000); + m_asActiveSamples[j].m_nFrequency = Clamp2((int32)sample.m_nFrequency, (int32)m_asActiveSamples[j].m_nFrequency, 6000); SampleManager.SetChannelFrequency(j, m_asActiveSamples[j].m_nFrequency); } if (sample.m_nEmittingVolume != m_asActiveSamples[j].m_nEmittingVolume) { - vol = clamp2((int8)sample.m_nEmittingVolume, (int8)m_asActiveSamples[j].m_nEmittingVolume, 10); + vol = Clamp2((int8)sample.m_nEmittingVolume, (int8)m_asActiveSamples[j].m_nEmittingVolume, 10); if (field_4) { emittingVol = 2 * Min(63, vol); diff --git a/src/audio/oal/stream.cpp b/src/audio/oal/stream.cpp index ab266681..7fc36acd 100644 --- a/src/audio/oal/stream.cpp +++ b/src/audio/oal/stream.cpp @@ -162,7 +162,7 @@ public: else StepIndex--; - StepIndex = clamp(StepIndex, 0, 88); + StepIndex = Clamp(StepIndex, 0, 88); int delta = step >> 3; if (adpcm & 1) delta += step >> 2; @@ -171,7 +171,7 @@ public: if (adpcm & 8) delta = -delta; int newSample = Sample + delta; - Sample = clamp(newSample, -32768, 32767); + Sample = Clamp(newSample, -32768, 32767); return Sample; } }; @@ -716,7 +716,7 @@ public: static short quantize(double sample) { int a = int(sample + 0.5); - return short(clamp(a, -32768, 32767)); + return short(Clamp(a, -32768, 32767)); } void Decode(void* _inbuf, int16* _outbuf, size_t size) @@ -1448,10 +1448,10 @@ void CStream::SetVolume(uint32 nVol) void CStream::SetPan(uint8 nPan) { - m_nPan = clamp((int8)nPan - 63, 0, 63); + m_nPan = Clamp((int8)nPan - 63, 0, 63); SetPosition(0, (m_nPan - 63) / 64.0f, 0.0f, Sqrt(1.0f - SQR((m_nPan - 63) / 64.0f))); - m_nPan = clamp((int8)nPan + 64, 64, 127); + m_nPan = Clamp((int8)nPan + 64, 64, 127); SetPosition(1, (m_nPan - 63) / 64.0f, 0.0f, Sqrt(1.0f - SQR((m_nPan - 63) / 64.0f))); m_nPan = nPan; diff --git a/src/audio/sampman_miles.cpp b/src/audio/sampman_miles.cpp index 8191cbf7..e8c28dc4 100644 --- a/src/audio/sampman_miles.cpp +++ b/src/audio/sampman_miles.cpp @@ -1659,7 +1659,7 @@ cSampleManager::UpdateReverb(void) #undef CALCULATE_RATIO #undef MIN_DIST - fRatio = clamp(fRatio, 0.0f, 0.6f); + fRatio = Clamp(fRatio, 0.0f, 0.6f); if ( fRatio == _fPrevEaxRatioDestination ) return FALSE; diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp index 2c7d4cec..fa262c98 100644 --- a/src/audio/sampman_oal.cpp +++ b/src/audio/sampman_oal.cpp @@ -356,7 +356,7 @@ int8 cSampleManager::SetCurrent3DProvider(uint8 nProvider) { int savedprovider = curprovider; - nProvider = clamp(nProvider, 0, m_nNumberOfProviders - 1); + nProvider = Clamp(nProvider, 0, m_nNumberOfProviders - 1); if ( set_new_provider(nProvider) ) return curprovider; @@ -1449,7 +1449,7 @@ bool8 cSampleManager::UpdateReverb(void) #undef CALCULATE_RATIO #undef MIN_DIST - fRatio = clamp(fRatio, 0.0f, 0.6f); + fRatio = Clamp(fRatio, 0.0f, 0.6f); if ( fRatio == _fPrevEaxRatioDestination ) return FALSE; -- cgit v1.2.3 From fdbd414299172fb9e95e6166f6ad95e7844339f0 Mon Sep 17 00:00:00 2001 From: erorcun Date: Mon, 28 Jun 2021 17:11:12 +0300 Subject: Fix MP3 finding stack crash --- src/audio/sampman_oal.cpp | 140 +++++++++++++++------------------------------- 1 file changed, 46 insertions(+), 94 deletions(-) (limited to 'src/audio') diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp index fa262c98..5d6b0dc3 100644 --- a/src/audio/sampman_oal.cpp +++ b/src/audio/sampman_oal.cpp @@ -479,18 +479,32 @@ _FindMP3s(void) bool8 bInitFirstEntry; HANDLE hFind; char path[MAX_PATH]; - char filepath[MAX_PATH*2]; int total_ms; WIN32_FIND_DATA fd; + char filepath[MAX_PATH + sizeof(fd.cFileName)]; if (getcwd(_mp3DirectoryPath, MAX_PATH) == NULL) { perror("getcwd: "); return; } + + if (strlen(_mp3DirectoryPath) + 1 > MAX_PATH - 10) { + // This is not gonna end well + printf("MP3 folder path is too long, no place left for file names. MP3 finding aborted.\n"); + return; + } OutputDebugString("Finding MP3s..."); strcpy(path, _mp3DirectoryPath); strcat(path, "\\MP3\\"); + +#if !defined(_WIN32) + char *actualPath = casepath(path); + if (actualPath) { + strcpy(path, actualPath); + free(actualPath); + } +#endif strcpy(_mp3DirectoryPath, path); OutputDebugString(_mp3DirectoryPath); @@ -503,92 +517,32 @@ _FindMP3s(void) { return; } - - strcpy(filepath, _mp3DirectoryPath); - strcat(filepath, fd.cFileName); - - size_t filepathlen = strlen(filepath); - - if ( filepathlen <= 0) - { - FindClose(hFind); - return; - } - if ( _ResolveLink(filepath, filepath) ) - { - OutputDebugString("Resolving Link"); - OutputDebugString(filepath); - bShortcut = TRUE; - } else - bShortcut = FALSE; - - if (aStream[0] && aStream[0]->Open(filepath)) - { - total_ms = aStream[0]->GetLengthMS(); - aStream[0]->Close(); + bShortcut = FALSE; + bInitFirstEntry = TRUE; - OutputDebugString(fd.cFileName); - - _pMP3List = new tMP3Entry; - - if ( _pMP3List == NULL ) - { - FindClose(hFind); - return; - } - - nNumMP3s = 1; - - strcpy(_pMP3List->aFilename, fd.cFileName); - - _pMP3List->nTrackLength = total_ms; - - _pMP3List->pNext = NULL; - - pList = _pMP3List; - - if ( bShortcut ) - { - _pMP3List->pLinkPath = new char[MAX_PATH*2]; - strcpy(_pMP3List->pLinkPath, filepath); - } - else - { - _pMP3List->pLinkPath = NULL; - } + do + { + strcpy(filepath, _mp3DirectoryPath); + strcat(filepath, fd.cFileName); + + if (!strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, "..")) + continue; - bInitFirstEntry = FALSE; - } - else - { - strcat(filepath, " - NOT A VALID MP3"); - - OutputDebugString(filepath); + size_t filepathlen = strlen(filepath); - bInitFirstEntry = TRUE; - } - - while ( TRUE ) - { - if ( !FindNextFile(hFind, &fd) ) - break; - if ( bInitFirstEntry ) { - strcpy(filepath, _mp3DirectoryPath); - strcat(filepath, fd.cFileName); - - size_t filepathlen = strlen(filepath); - - if ( filepathlen > 0 ) + if (filepathlen > 0) { - if ( _ResolveLink(filepath, filepath) ) + if (_ResolveLink(filepath, filepath)) { OutputDebugString("Resolving Link"); OutputDebugString(filepath); bShortcut = TRUE; - } else { + } + else + { bShortcut = FALSE; if (filepathlen > MAX_PATH) { continue; @@ -600,29 +554,29 @@ _FindMP3s(void) aStream[0]->Close(); OutputDebugString(fd.cFileName); - + _pMP3List = new tMP3Entry; - - if ( _pMP3List == NULL) + + if (_pMP3List == NULL) break; - + nNumMP3s = 1; - + strcpy(_pMP3List->aFilename, fd.cFileName); - + _pMP3List->nTrackLength = total_ms; _pMP3List->pNext = NULL; - - if ( bShortcut ) + + if (bShortcut) { - _pMP3List->pLinkPath = new char [MAX_PATH*2]; + _pMP3List->pLinkPath = new char[MAX_PATH + sizeof(fd.cFileName)]; strcpy(_pMP3List->pLinkPath, filepath); } else { _pMP3List->pLinkPath = NULL; } - + pList = _pMP3List; bInitFirstEntry = FALSE; @@ -633,14 +587,11 @@ _FindMP3s(void) OutputDebugString(filepath); } } + else + break; } else { - strcpy(filepath, _mp3DirectoryPath); - strcat(filepath, fd.cFileName); - - size_t filepathlen = strlen(filepath); - if ( filepathlen > 0 ) { if ( _ResolveLink(filepath, filepath) ) @@ -648,7 +599,8 @@ _FindMP3s(void) OutputDebugString("Resolving Link"); OutputDebugString(filepath); bShortcut = TRUE; - } else + } + else bShortcut = FALSE; if (aStream[0] && aStream[0]->Open(filepath)) @@ -673,7 +625,7 @@ _FindMP3s(void) if ( bShortcut ) { - e->pLinkPath = new char [MAX_PATH*2]; + e->pLinkPath = new char [MAX_PATH + sizeof(fd.cFileName)]; strcpy(e->pLinkPath, filepath); } else @@ -692,7 +644,7 @@ _FindMP3s(void) } } } - } + } while (FindNextFile(hFind, &fd)); FindClose(hFind); } -- cgit v1.2.3 From 9f0daee186dc815cbf4e8a68871d375bd4752737 Mon Sep 17 00:00:00 2001 From: erorcun Date: Wed, 30 Jun 2021 03:31:10 +0300 Subject: Sanitizer fixes --- src/audio/sampman_oal.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/audio') diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp index 5d6b0dc3..6740f08f 100644 --- a/src/audio/sampman_oal.cpp +++ b/src/audio/sampman_oal.cpp @@ -1250,14 +1250,14 @@ cSampleManager::IsPedCommentLoaded(uint32 nComment) { ASSERT( nComment < TOTAL_AUDIO_SAMPLES ); - int8 slot; - for ( int32 i = 0; i < _TODOCONST(3); i++ ) { - slot = nCurrentPedSlot - i - 1; #ifdef FIX_BUGS + int8 slot = (int8)nCurrentPedSlot - i - 1; if (slot < 0) slot += ARRAY_SIZE(nPedSlotSfx); +#else + uint8 slot = nCurrentPedSlot - i - 1; #endif if ( nComment == nPedSlotSfx[slot] ) return TRUE; @@ -1270,14 +1270,14 @@ cSampleManager::IsPedCommentLoaded(uint32 nComment) int32 cSampleManager::_GetPedCommentSlot(uint32 nComment) { - int8 slot; - for (int32 i = 0; i < _TODOCONST(3); i++) { - slot = nCurrentPedSlot - i - 1; #ifdef FIX_BUGS + int8 slot = (int8)nCurrentPedSlot - i - 1; if (slot < 0) slot += ARRAY_SIZE(nPedSlotSfx); +#else + uint8 slot = nCurrentPedSlot - i - 1; #endif if (nComment == nPedSlotSfx[slot]) return slot; -- cgit v1.2.3 From b1c9340fd39ecc7a101472f8eeb611ad67809073 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Wed, 30 Jun 2021 21:16:48 +0300 Subject: Fix unused code --- src/audio/AudioLogic.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/audio') diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp index 3ec40437..5ee5ddd1 100644 --- a/src/audio/AudioLogic.cpp +++ b/src/audio/AudioLogic.cpp @@ -9976,8 +9976,10 @@ cAudioManager::ProcessMissionAudioSlot(uint8 slot) if (!m_nUserPause) { if (nCheckPlayingDelay[slot]) { --nCheckPlayingDelay[slot]; - } else if (GetMissionScriptPoliceAudioPlayingStatus() == PLAY_STATUS_FINISHED || m_sMissionAudio.m_nMissionAudioCounter[slot]-- == 0) { + } 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; SampleManager.StopStreamedFile(slot + 1); m_sMissionAudio.m_nMissionAudioCounter[slot] = 0; -- cgit v1.2.3 From a73a2c91793c329a1039032871a1cbf7bda61bd9 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Wed, 30 Jun 2021 21:21:45 +0300 Subject: Pause radio when game is paused --- src/audio/MusicManager.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/audio') diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp index 5a176005..13fba08c 100644 --- a/src/audio/MusicManager.cpp +++ b/src/audio/MusicManager.cpp @@ -310,7 +310,16 @@ cMusicManager::ChangeMusicMode(uint8 mode) switch (mode) { - case MUSICMODE_FRONTEND: m_nUpcomingMusicMode = MUSICMODE_FRONTEND; break; + case MUSICMODE_FRONTEND: + m_nUpcomingMusicMode = MUSICMODE_FRONTEND; + +#ifdef PAUSE_RADIO_IN_FRONTEND + // rewind those streams we weren't listening right now + for( uint32 i = STREAMED_SOUND_RADIO_WILD; i < STREAMED_SOUND_CUTSCENE_ASS_1; i++ ) + m_aTracks[i].m_nPosition = GetTrackStartPos(i); +#endif + + break; case MUSICMODE_GAME: m_nUpcomingMusicMode = MUSICMODE_GAME; break; case MUSICMODE_CUTSCENE: m_nUpcomingMusicMode = MUSICMODE_CUTSCENE; @@ -414,6 +423,12 @@ cMusicManager::ServiceFrontEndMode() { static bool8 bRadioStatsRecorded = FALSE; +#ifdef PAUSE_RADIO_IN_FRONTEND + // pause radio + for (uint32 i = STREAMED_SOUND_RADIO_WILD; i < STREAMED_SOUND_CUTSCENE_ASS_1; i++) + m_aTracks[i].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); +#endif + if (m_bAnnouncementInProgress) { SampleManager.StopStreamedFile(); if (SampleManager.IsStreamPlaying()) -- cgit v1.2.3