diff --git a/CMakeLists.txt b/CMakeLists.txt index 468d13c..0901db2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ else() endif() project(XPMP2 - VERSION 3.0.0 + VERSION 3.0.1 DESCRIPTION "Multiplayer library for X-Plane 11 and 12") # Provide compile macros from the above project version definition @@ -120,13 +120,9 @@ else() if(MSVC) # Fast code, symbols into separate .pdb file, no global optimization (as it produces huge files) add_compile_options(/Zi /O2 /GL-) - elseif(APPLE) - add_compile_options(-O3 -fPIC) - elseif (UNIX OR MINGW) - # Use position-independent code and highest optimization level (FPS!). + else() + # Use position-independent code and highest optimization level add_compile_options(-O3 -fPIC) - # Strip symbols during linking - add_link_options(-s) endif() endif() diff --git a/src/Sound.cpp b/src/Sound.cpp index 5ba72a5..1b930eb 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -98,11 +98,9 @@ constexpr int EXP_COMP_SKIP_CYCLES = 10; ///< In how many cycles to s constexpr int FMOD_NUM_VIRT_CHANNELS = 1000; ///< Number of virtual channels during initialization constexpr float FMOD_3D_MAX_DIST = 10000.0f; ///< Value used for 3D max distance, which doesn't have much of a function for the inverse roll-off model used here constexpr float FMOD_LOW_PASS_GAIN = 0.2f; ///< Gain used when activating Low Pass filter -constexpr int FMOD_NEW_SOUNDS_PER_FRAME = 1; ///< How many new sounds do we allow per frame (to reduce risk of cracks)? static FMOD_SYSTEM* gpFmodSystem = nullptr; ///< FMOD system static unsigned int gFmodVer = 0; ///< FMOD version -static int gbFmodSoundsThisFrame = 0; ///< How many sounds did we create this frame already? /// Use pre-v2 FMOD version structures? inline bool UseOldFmod() { return gFmodVer < 0x00020000; } @@ -456,7 +454,8 @@ FMOD_CHANNEL* Aircraft::SoundPlay (const std::string& sndName, float vol) // Have FMOD create the sound try { SoundFile& snd = mapSound.at(sndName); - FMOD_CHANNEL* pChn = snd.play(); + // start paused to avoid cracking, will be unpaused only in the next call to Aircraft::SoundUpdate() + FMOD_CHANNEL* pChn = snd.play(nullptr, true); if (pChn) { chnList.push_back(pChn); // add to managed list of sounds FMOD_LOG(FMOD_Channel_Set3DMinMaxDistance(pChn, (float)sndMinDist, FMOD_3D_MAX_DIST)); @@ -468,7 +467,6 @@ FMOD_CHANNEL* Aircraft::SoundPlay (const std::string& sndName, float vol) if (bChnMuted) { // if currently muted, then mute FMOD_LOG(FMOD_Channel_SetMute(pChn, true)); } - FMOD_LOG(FMOD_Channel_SetPaused(pChn, false)); // un-pause } return pChn; } @@ -620,18 +618,15 @@ void Aircraft::SoundUpdate () float vol = std::clamp((fVal - def.valMin) / (def.valMax - def.valMin), 0.0f, 1.0f); // If there hasn't been a sound triggered do so now if (!sndCh.pChn) { - // Are we allowed to add more sounds? - if (++gbFmodSoundsThisFrame <= FMOD_NEW_SOUNDS_PER_FRAME) { - // Get Sound's name and volume adjustment - const std::string sndName = SoundGetName(eSndEvent, sndCh.volAdj); - if (!sndName.empty()) { - vol *= sndCh.volAdj; - sndCh.pChn = SoundPlay(sndName, vol); - if (sndCh.pChn) { - LOG_MATCHING(logINFO, "Aircraft %08X (%s): Looping sound '%s' at volume %.2f for '%s'", - modeS_id, GetFlightId().c_str(), - sndName.c_str(), vol, SoundEventTxt(eSndEvent)); - } + // Get Sound's name and volume adjustment + const std::string sndName = SoundGetName(eSndEvent, sndCh.volAdj); + if (!sndName.empty()) { + vol *= sndCh.volAdj; + sndCh.pChn = SoundPlay(sndName, vol); + if (sndCh.pChn) { + LOG_MATCHING(logINFO, "Aircraft %08X (%s): Looping sound '%s' at volume %.2f for '%s'", + modeS_id, GetFlightId().c_str(), + sndName.c_str(), vol, SoundEventTxt(eSndEvent)); } } } else { @@ -661,9 +656,7 @@ void Aircraft::SoundUpdate () { sndCh.lastDRVal = fVal; // Remember this current value // If there hasn't been a sound triggered do so now - if (!sndCh.pChn && - // And we are allowed to add more this frame - ++gbFmodSoundsThisFrame <= FMOD_NEW_SOUNDS_PER_FRAME) + if (!sndCh.pChn) { const std::string sndName = SoundGetName(eSndEvent, sndCh.volAdj); if (!sndName.empty()) { @@ -726,6 +719,12 @@ void Aircraft::SoundUpdate () if (pSnd && pSnd->hasConeInfo()) pSnd->setConeOrientation(*iter, *this); } + // Unpause the channel if still paused (always starts paused to avoid cracking) + FMOD_BOOL bPaused = false; + FMOD_LOG(FMOD_Channel_GetPaused(*iter, &bPaused)); + if (bPaused) { + FMOD_LOG(FMOD_Channel_SetPaused(*iter, false)); + } // Next sound channel iter++; } @@ -812,8 +811,7 @@ bool SoundInit () // Prepare for this frame's updates, which are about to start void SoundUpdatesBegin() { - // Reset counter of allowed new sounds - gbFmodSoundsThisFrame = 0; + // Currently, there's nothing in here } // Tell FMOD that all updates are done @@ -980,4 +978,4 @@ const char* XPMPSoundEnumerate (const char* prevName, const char** ppFilePath) } } -#endif // INCLUDE_FMOD_SOUND \ No newline at end of file +#endif // INCLUDE_FMOD_SOUND