From 0ac2be00934ce3789d87ce4efb8b991f308de521 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Sat, 3 Oct 2020 16:17:24 +0200 Subject: [PATCH 1/3] Fix unsigned comparison in CStreaming::MakeSpaceFor(int32 size) --- src/core/Streaming.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index 507815fa..4e12ab6d 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -2436,12 +2436,17 @@ CStreaming::DeleteRwObjectsNotInFrustumInSectorList(CPtrList &list, size_t mem) void CStreaming::MakeSpaceFor(int32 size) { - // BUG: ms_memoryAvailable can be uninitialized - // the code still happens to work in that case because ms_memoryAvailable is unsigned - // but it's not nice.... - +#ifdef FIX_BUGS +#define MB (1024 * 1024) + if(ms_memoryAvailable == 0) { + extern size_t _dwMemAvailPhys; + ms_memoryAvailable = (_dwMemAvailPhys - 10 * MB) / 2; + if(ms_memoryAvailable < 50 * MB) ms_memoryAvailable = 50 * MB; + } +#undef MB +#endif while(ms_memoryUsed >= ms_memoryAvailable - size) - if(!RemoveLeastUsedModel()){ + if(!RemoveLeastUsedModel()) { DeleteRwObjectsBehindCamera(ms_memoryAvailable - size); return; } From 1a0b71bd47fc181ea7e8042e0faa35eb7f94cac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 5 Oct 2020 13:59:40 +0300 Subject: [PATCH 2/3] Fix Audio --- src/audio/oal/stream.cpp | 12 ++++++------ src/audio/oal/stream.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/audio/oal/stream.cpp b/src/audio/oal/stream.cpp index eeaaafb0..c4f1b67c 100644 --- a/src/audio/oal/stream.cpp +++ b/src/audio/oal/stream.cpp @@ -155,13 +155,13 @@ public: void Seek(uint32 milliseconds) { if ( !IsOpened() ) return; - mpg123_seek(m_pMH, ms2samples(milliseconds)*GetSampleSize(), SEEK_SET); + mpg123_seek(m_pMH, ms2samples(milliseconds), SEEK_SET); } uint32 Tell() { if ( !IsOpened() ) return 0; - return samples2ms(mpg123_tell(m_pMH)/GetSampleSize()); + return samples2ms(mpg123_tell(m_pMH)); } uint32 Decode(void *buffer) @@ -247,13 +247,13 @@ public: void Seek(uint32 milliseconds) { if ( !IsOpened() ) return; - op_pcm_seek(m_FileH, ms2samples(milliseconds) * GetSampleSize()); + op_pcm_seek(m_FileH, ms2samples(milliseconds) / GetChannels()); } uint32 Tell() { if ( !IsOpened() ) return 0; - return samples2ms(op_pcm_tell(m_FileH)/GetSampleSize()); + return samples2ms(op_pcm_tell(m_FileH) * GetChannels()); } uint32 Decode(void *buffer) @@ -461,8 +461,8 @@ uint32 CStream::GetPosMS() alGetSourcei(m_alSource, AL_BYTE_OFFSET, &offset); return m_pSoundFile->Tell() - - m_pSoundFile->samples2ms(m_pSoundFile->GetBufferSamples() * (NUM_STREAMBUFFERS-1)) - + m_pSoundFile->samples2ms(offset/m_pSoundFile->GetSampleSize()); + - m_pSoundFile->samples2ms(m_pSoundFile->GetBufferSamples() * (NUM_STREAMBUFFERS-1)) / m_pSoundFile->GetChannels() + + m_pSoundFile->samples2ms(offset/m_pSoundFile->GetSampleSize()) / m_pSoundFile->GetChannels(); } uint32 CStream::GetLengthMS() diff --git a/src/audio/oal/stream.h b/src/audio/oal/stream.h index 456c080a..2476abcc 100644 --- a/src/audio/oal/stream.h +++ b/src/audio/oal/stream.h @@ -24,12 +24,12 @@ public: uint32 ms2samples(uint32 ms) { - return float(ms) / 1000.0f * float(GetChannels()) * float(GetSampleRate()); + return float(ms) / 1000.0f * float(GetSampleRate()); } uint32 samples2ms(uint32 sm) { - return float(sm) * 1000.0f / float(GetChannels()) / float(GetSampleRate()); + return float(sm) * 1000.0f / float(GetSampleRate()); } uint32 GetBufferSamples() @@ -108,4 +108,4 @@ public: void ProviderTerm(); }; -#endif \ No newline at end of file +#endif From ee27cae7325e69a4f0d29698c01f686fd2ca6c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 5 Oct 2020 01:25:56 +0300 Subject: [PATCH 3/3] Fix Linux audio path --- src/audio/sampman_oal.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp index b10aa1ff..9f3156cb 100644 --- a/src/audio/sampman_oal.cpp +++ b/src/audio/sampman_oal.cpp @@ -27,6 +27,7 @@ #include "MusicManager.h" #include "Frontend.h" #include "Timer.h" +#include "crossplatform.h" #ifdef AUDIO_OPUS #include #endif @@ -1423,11 +1424,11 @@ cSampleManager::InitialiseSampleBanks(void) { int32 nBank = SFX_BANK_0; - fpSampleDescHandle = fopen(SampleBankDescFilename, "rb"); + fpSampleDescHandle = fcaseopen(SampleBankDescFilename, "rb"); if ( fpSampleDescHandle == NULL ) return false; #ifndef AUDIO_OPUS - fpSampleDataHandle = fopen(SampleBankDataFilename, "rb"); + fpSampleDataHandle = fcaseopen(SampleBankDataFilename, "rb"); if ( fpSampleDataHandle == NULL ) { fclose(fpSampleDescHandle);