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.
Changed AudioMan network handling to accomodate position instead of attenuation, as well as attenuation start distance and immobile properties.
Changed SetSoundAttenuation to SetSoundPosition and changed PlaySound to accomodate a Vector for position instead of a float for attenuation
Rewrote some comments and renamed some variables
Added FMOD_VECTOR handling and unit vectors for the up and forwards directions
Removed unneeded software format setting. Made PlayMusic use FMOD_3D and FMOD_3D_HEADRELATIVE flags.
Made PlaySound check if the SoundContainer's sounds are up to date and, if not, update them for safety. Removed loop setting here since it's handled by sounds.
Added attenuation min distance and immobile to AudioMan::PlaySound(filePath) so they can get set.
if (m_IsInMultiplayerMode) { RegisterSoundEvent(-1, SOUND_SET_ATTENUATION, pSoundContainer->GetPlayingChannels(), &pSoundContainer->GetSelectedSoundHashes(), attenuation); }
230
-
231
-
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)
235
+
if (m_IsInMultiplayerMode) { RegisterSoundEvent(-1, SOUND_SET_POSITION, soundContainer->GetPlayingChannels(), &soundContainer->GetSelectedSoundHashes(), position); }
for (std::unordered_set<unsignedshortint>::iterator channelIterator = channels->begin(); channelIterator != channels->end(); ++channelIterator) {
238
242
result = m_AudioSystem->getChannel((*channelIterator), &soundChannel);
239
-
result = result == FMOD_OK ? soundChannel->setVolume(1 - attenuation) : result;
243
+
result = result == FMOD_OK ? soundChannel->set3DAttributes(&GetAsFMODVector(position), NULL) : result;
240
244
if (result != FMOD_OK) {
241
-
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)));
245
+
g_ConsoleMan.PrintString("ERROR: Could not set sound position for the sound being played on channel " + std::to_string(*channelIterator) + " for SoundContainer " + soundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
SoundContainer *AudioMan::PlaySound(constchar *filePath, float attenuation, int player, int loops, int priority, double pitchOrAffectedByGlobalPitch) {
406
+
SoundContainer *AudioMan::PlaySound(constchar *filePath, const Vector &position, int player, int loops, int priority, double pitchOrAffectedByGlobalPitch, float attenuationStartDistance, bool immobile) {
403
407
if (!filePath) {
404
408
g_ConsoleMan.PrintString("Error: Null filepath passed to AudioMan::PlaySound!");
boolAudioMan::PlaySound(SoundContainer *pSoundContainer, float attenuation, int player, int priority, double pitch) {
426
-
if (!m_AudioEnabled || !pSoundContainer) {
429
+
boolAudioMan::PlaySound(SoundContainer *soundContainer, const Vector &position, int player, int priority, double pitch) {
430
+
if (!m_AudioEnabled || !soundContainer) {
427
431
returnfalse;
428
432
}
429
433
430
-
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)
pitch = Limit(pSoundContainer->IsAffectedByGlobalPitch() ? m_GlobalPitch : pitch, 8, 0.125); //Limit pitch change to 8 octaves up or down, and set it to global pitch if applicable
433
-
434
-
FMOD::Channel *channel;
435
434
FMOD_RESULT result = FMOD_OK;
436
-
int channelIndex;
437
-
if (!pSoundContainer->SelectNextSounds()) {
438
-
g_ConsoleMan.PrintString("Unable to select new sounds to play for SoundContainer " + pSoundContainer->GetPresetName() + ". No sounds will be played.");
435
+
436
+
if (!soundContainer->AllSoundPropertiesUpToDate()) {
437
+
result = soundContainer->UpdateSoundProperties();
438
+
if (result != FMOD_OK) {
439
+
g_ConsoleMan.PrintString("ERROR: Could not update sound properties for SoundContainer " + soundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
440
+
returnfalse;
441
+
}
442
+
}
443
+
444
+
if (!soundContainer->SelectNextSounds()) {
445
+
g_ConsoleMan.PrintString("Unable to select new sounds to play for SoundContainer " + soundContainer->GetPresetName());
446
+
returnfalse;
439
447
}
440
448
441
-
for (FMOD::Sound *sound : pSoundContainer->GetSelectedSoundObjects()) {
pitch = Limit(soundContainer->IsAffectedByGlobalPitch() ? m_GlobalPitch : pitch, 8, 0.125); //Limit pitch change to 8 octaves up or down, and set it to global pitch if applicable
451
+
452
+
FMOD::Channel *channel;
453
+
int channelIndex;
454
+
for (FMOD::Sound *sound : soundContainer->GetSelectedSoundObjects()) {
442
455
result = result == FMOD_OK ? m_AudioSystem->playSound(sound, m_SoundChannelGroup, true, &channel) : result;
443
456
result = result == FMOD_OK ? channel->getIndex(&channelIndex) : result;
444
-
result = result == FMOD_OK ? channel->setUserData(pSoundContainer) : result;
457
+
result = result == FMOD_OK ? channel->setUserData(soundContainer) : result;
445
458
result = result == FMOD_OK ? channel->setCallback(SoundChannelEndedCallback) : result;
446
-
result = result == FMOD_OK ? channel->setVolume(1 - attenuation) : result;
447
-
result = result == FMOD_OK ? channel->setLoopCount(pSoundContainer->GetLoopSetting()) : result;
459
+
result = result == FMOD_OK ? channel->set3DAttributes(&GetAsFMODVector(position), NULL) : result;
460
+
result = result == FMOD_OK ? channel->set3DLevel(g_SettingsMan.SoundPanningEffectStrength()) : result;
448
461
result = result == FMOD_OK ? channel->setPriority(priority) : result;
449
462
result = result == FMOD_OK ? channel->setPitch(pitch) : result;
450
463
}
451
464
452
465
if (result != FMOD_OK) {
453
-
g_ConsoleMan.PrintString("ERROR: Could not play sounds from SoundContainer " + pSoundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
466
+
g_ConsoleMan.PrintString("ERROR: Could not play sounds from SoundContainer " + soundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
454
467
returnfalse;
455
468
}
456
469
457
470
result = channel->setPaused(false);
458
471
if (result != FMOD_OK) {
459
-
g_ConsoleMan.PrintString("ERROR: Failed to start playing sounds from SoundContainer " + pSoundContainer->GetPresetName() + " after setting it up: " + std::string(FMOD_ErrorString(result)));
472
+
g_ConsoleMan.PrintString("ERROR: Failed to start playing sounds from SoundContainer " + soundContainer->GetPresetName() + " after setting it up: " + std::string(FMOD_ErrorString(result)));
460
473
}
461
474
462
-
pSoundContainer->AddPlayingChannel(channelIndex);
475
+
soundContainer->AddPlayingChannel(channelIndex);
463
476
464
477
// Now that the sound is playing we can register an event with the SoundContainer's channels, which can be used by clients to identify the sound being played.
for (std::unordered_set<unsignedshortint>::iterator channelIterator = channels->begin(); channelIterator != channels->end(); ++channelIterator) {
521
536
result = m_AudioSystem->getChannel((*channelIterator), &soundChannel);
522
537
result = result == FMOD_OK ? soundChannel->getDSPClock(nullptr, &parentClock) : result;
523
538
result = result == FMOD_OK ? soundChannel->getVolume(¤tVolume) : result;
524
539
result = result == FMOD_OK ? soundChannel->addFadePoint(parentClock, currentVolume) : result;
525
540
result = result == FMOD_OK ? soundChannel->addFadePoint(parentClock + fadeOutTimeAsSamples, 0) : result;
526
541
if (result != FMOD_OK) {
527
-
g_ConsoleMan.PrintString("ERROR: Could not fade out sounds in SoundContainer " + pSoundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
542
+
g_ConsoleMan.PrintString("ERROR: Could not fade out sounds in SoundContainer " + soundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
0 commit comments