Skip to content

Commit

Permalink
Merge pull request #376 from NVlabs/PreplayAudio
Browse files Browse the repository at this point in the history
Pre-play audio on first load
  • Loading branch information
bboudaoud-nv committed Aug 31, 2022
2 parents b830d8f + 4622f42 commit 5f60623
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions source/FPSciApp.cpp
Expand Up @@ -720,9 +720,13 @@ void FPSciApp::updateSession(const String& id, bool forceReload) {
weapon->loadSounds();
if (!sessConfig->audio.sceneHitSound.empty()) {
m_sceneHitSound = Sound::create(System::findDataFile(sessConfig->audio.sceneHitSound));
// Play silently to pre-load the sound
m_sceneHitSound->play(0.f);
}
if (!sessConfig->audio.refTargetHitSound.empty()) {
m_refTargetHitSound = Sound::create(System::findDataFile(sessConfig->audio.refTargetHitSound));
// Play silently to pre-load the sound
m_refTargetHitSound->play(0.f);
}

// Load static HUD textures
Expand Down
4 changes: 4 additions & 0 deletions source/TargetEntity.h
Expand Up @@ -196,6 +196,8 @@ class TargetEntity : public VisibleEntity {
}
m_hitSound = soundTable[hitSoundFilename];
m_hitSoundVol = hitSoundVol;
// Play with volume 0 to pre-load
m_hitSound->play(0.f);
}
}

Expand All @@ -208,6 +210,8 @@ class TargetEntity : public VisibleEntity {
}
m_destroyedSound = soundTable[destroyedSoundFilename];
m_destroyedSoundVol = destroyedSoundVol;
// Play with volume 0 to pre-load
m_destroyedSound->play(0.f);
}
}

Expand Down
15 changes: 12 additions & 3 deletions source/Weapon.h
Expand Up @@ -220,9 +220,18 @@ class Weapon : Entity {

void loadSounds() {
// Check for play mode specific parameters
if (notNull(m_fireAudio)) { m_fireAudio->stop(); }
if(!m_config->fireSound.empty()) m_fireSound = Sound::create(System::findDataFile(m_config->fireSound), m_config->loopAudio());
else { m_fireSound = nullptr; }
if (notNull(m_fireAudio)) {
m_fireAudio->stop();
}
if (!m_config->fireSound.empty()) {
m_fireSound = Sound::create(System::findDataFile(m_config->fireSound), m_config->loopAudio());
// Play the sound with 0 volume to load it
m_fireAudio = m_fireSound->play(0.f);
m_fireAudio->stop();
}
else {
m_fireSound = nullptr;
}
}
// Plays the sound based on the weapon fire mode
void playSound(bool shotFired, bool shootButtonUp);
Expand Down

0 comments on commit 5f60623

Please sign in to comment.