You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 5, 2024. It is now read-only.
Fixed SoundContainer::SelectNextSound to work with changed data structuring. Also fixed cleared-to priority being low instead of normal.
Fixed sound stop callback in AudioMan breaking if the sound was reset before the callback happened (e.g. gib sounds). Made number of channels a constant instead of a settings entry, since it's dumb to have it settable.
Cleaned up various things in AudioMan - renamed distance to attenuation, Reorganized StopSound so there's an easy one for lua that stops all sounds and calls the player specific one and fixed iterator invalidation when stopping sound due to callback erasing it, fixed mutex positioning, made PlaySound iterate through all selected sound objects in a SoundContainer and added error print if it fails to select new sounds
RTEAssert(m_CurrentSound >= 0 && m_CurrentSound < soundCount, "Sample index is out of bounds!");
132
+
RTEAssert(m_SelectedSounds.size() > 0 && m_SelectedSounds[0] >= 0 && m_SelectedSounds[0] < soundCount, "Failed to select next sound, either none was selected or the selected sound was invalid.");
result = result == FMOD_OK ? channel->setUserData(NULL) : result;
34
35
35
36
if (result != FMOD_OK) {
36
37
g_ConsoleMan.PrintString("ERROR: An error occurred when Ending a sound in SoundContainer " + channelSoundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
@@ -69,7 +70,7 @@ namespace RTE {
69
70
//TODO 44.1 kHz came from data, fmod defaults to 48 kHz, see if we can just use this instead??
distance = Limit(distance, 0.95, 0); //Limit distance so it can't be closer than 0 (no attenuation) or farther than 0.95 (quiet but not quite silent)
229
+
230
+
attenuation = Limit(attenuation, 0.95, 0); //Limit attenuation so it can't be closer than 0 (full volume) or farther than 0.95 (quiet but not quite silent)
for (std::unordered_set<unsignedshortint>::iterator channelIterator = channels->begin(); channelIterator != channels->end(); ++channelIterator) {
235
237
result = m_AudioSystem->getChannel((*channelIterator), &soundChannel);
236
-
result = result == FMOD_OK ? soundChannel->setVolume(1 - distance) : result;
238
+
result = result == FMOD_OK ? soundChannel->setVolume(1 - attenuation) : result;
237
239
if (result != FMOD_OK) {
238
240
g_ConsoleMan.PrintString("ERROR: Could not set sound attenuation for the sound being played on channel " + std::to_string(*channelIterator) + " for SoundContainer " + pSoundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
FMOD_RESULT result = m_AudioSystem->playSound(pSoundContainer->SelectNextSound(), m_SoundChannelGroup, true, &channel);
434
-
result = result == FMOD_OK ? channel->getIndex(&channelIndex) : result;
435
-
result = result == FMOD_OK ? channel->setUserData(pSoundContainer) : result;
436
-
result = result == FMOD_OK ? channel->setCallback(SoundChannelEndedCallback) : result;
437
-
result = result == FMOD_OK ? channel->setLoopCount(pSoundContainer->GetLoopSetting()) : result;
438
-
result = result == FMOD_OK ? channel->setPriority(priority) : result;
436
+
if (!pSoundContainer->SelectNextSounds()) {
437
+
g_ConsoleMan.PrintString("Unable to select new sounds to play for SoundContainer " + pSoundContainer->GetPresetName() + ". No sounds will be played.");
438
+
}
439
+
440
+
for (FMOD::Sound *sound : pSoundContainer->GetSelectedSoundObjects()) {
441
+
result = result == FMOD_OK ? m_AudioSystem->playSound(sound, m_SoundChannelGroup, true, &channel) : result;
442
+
result = result == FMOD_OK ? channel->getIndex(&channelIndex) : result;
443
+
result = result == FMOD_OK ? channel->setUserData(pSoundContainer) : result;
444
+
result = result == FMOD_OK ? channel->setCallback(SoundChannelEndedCallback) : result;
445
+
result = result == FMOD_OK ? channel->setLoopCount(pSoundContainer->GetLoopSetting()) : result;
446
+
result = result == FMOD_OK ? channel->setPriority(priority) : result;
447
+
}
439
448
440
449
if (result != FMOD_OK) {
441
450
g_ConsoleMan.PrintString("ERROR: Could not play sounds from SoundContainer " + pSoundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
for (std::unordered_set<unsignedshortint>::iterator channelIterator = channels->begin(); channelIterator != channels->end();) {
476
485
result = m_AudioSystem->getChannel((*channelIterator), &soundChannel);
486
+
++channelIterator; // NOTE - stopping the sound will remove the channel, screwing things up if we don't move to the next iterator preemptively
477
487
result = result == FMOD_OK ? soundChannel->stop() : result;
478
488
if (result != FMOD_OK) {
479
-
g_ConsoleMan.PrintString("Error: Failed to stop playing channel in SoundContainer "+pSoundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
489
+
g_ConsoleMan.PrintString("Error: Failed to stop playing channel in SoundContainer " + pSoundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
/// Stops playing all sounds in a given SoundContainer for a certain player.
@@ -410,6 +410,7 @@ namespace RTE {
410
410
std::mutex g_SoundEventsListMutex[c_MaxClients]; //!< A list for locking sound events for multiplayer to avoid race conditions and other such problems.
411
411
412
412
private:
413
+
413
414
/// <summary>
414
415
/// A static callback function for FMOD to invoke when the music channel finishes playing. See fmod docs - FMOD_SYSTEM_CALLBACK for details
0 commit comments