Skip to content

Commit

Permalink
Stopping voiceover playback when quitting / restarting mission.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrisztian89 committed Dec 30, 2024
1 parent d943589 commit c136707
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/config/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.5.5-dev:1248 (2024.12.29.)",
"version": "0.5.5-dev:1249 (2024.12.30.)",
"debugVersion": false,
"logVerbosity": 1,
"platform": "web",
Expand Down
10 changes: 9 additions & 1 deletion src/js/armada/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ define([
function resume() {
audio.resume();
}
/**
* Stops the playback of the last played non-persistent audio clips (the one started with the "long" flag
* and the one started without)
*/
function stopLastClips() {
audio.stopLastClips();
}
// -------------------------------------------------------------------------
// Initialization
_context = new AudioSettingsContext();
Expand Down Expand Up @@ -545,6 +552,7 @@ define([
initMusic: initMusic,
playMusic: playMusic,
stopMusic: stopMusic,
resume: resume
resume: resume,
stopLastClips: stopLastClips
};
});
5 changes: 3 additions & 2 deletions src/js/armada/screens/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,7 @@ define([
_newHostilesAlertTimeLeft = 0;
_newHostiles = null;
audio.playMusic(null);
audio.stopLastClips();
// HUD
_hullIntegrityDecreaseTime = 0;
_shieldDecreaseTime = 0;
Expand Down Expand Up @@ -3912,13 +3913,13 @@ define([
_playingMissionVoiceSound = false;
// playing the voice-over for this message if it exists
if (_missionVoiceSounds[messageQueue[0].id]) {
_missionVoiceSounds[messageQueue[0].id].play(resources.SoundCategory.VOICE);
_missionVoiceSounds[messageQueue[0].id].play(resources.SoundCategory.VOICE, undefined, undefined, undefined, true);
_playingMissionVoiceSound = true;
messageQueue[0].silent = true;
} else if (messageQueue[0].source) {
j = ai.getVoiceOfSpacecraft(messageQueue[0].source);
if ((j >= 0) && _missionPilotVoiceSounds[j][messageQueue[0].id]) {
_missionPilotVoiceSounds[j][messageQueue[0].id].play(resources.SoundCategory.VOICE);
_missionPilotVoiceSounds[j][messageQueue[0].id].play(resources.SoundCategory.VOICE, undefined, undefined, undefined, true);
_playingMissionVoiceSound = true;
messageQueue[0].silent = true;
}
Expand Down
26 changes: 22 additions & 4 deletions src/js/modules/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ define([
* @type SoundClip
*/
_clip,
/**
* A common sound clip that is used to play longer sounds, so that the last one (the one currently playing) can be stopped.
* @type SoundClip
*/
_longClip,
/**
* A common sound source that is used to play sounds for which no persistent sound source needs to be created (to avoid creating
* unnecessary objects)
Expand Down Expand Up @@ -727,14 +732,25 @@ define([
* @param {Number[3]} [position] The camera-space position of the sound source, in case the sound should be spatialized
* @param {Number} [rolloffFactor=1] The rolloff factor of the sound in case it is spatialized. See SoundSource for how the volume is
* calculated based on it
* @param {Boolean} [long=false] Whether the sound effect is longer, so it will be stored separately from the short ones, allowing for
* it to be stopped by calling stopLastClips() (as long as no overlapping long sound effects are played)
*/
function playSound(sampleName, soundCategory, volume, position, rolloffFactor) {
SoundClip.call(_clip, soundCategory || SoundCategory.SOUND_EFFECT, sampleName, volume, false);
function playSound(sampleName, soundCategory, volume, position, rolloffFactor, long) {
var clip = long ? _longClip : _clip;
SoundClip.call(clip, soundCategory || SoundCategory.SOUND_EFFECT, sampleName, volume, false);
if (position) {
SoundSource.call(_source, position[0], position[1], position[2], DEFAULT_PANNING_MODEL, rolloffFactor);
_clip.setSource(_source);
clip.setSource(_source);
}
_clip.play();
clip.play();
}
/**
* Stops the playback of the last played non-persistent audio clips (the one started with the "long" flag
* and the one started without)
*/
function stopLastClips() {
_clip.stopPlaying(DEFAULT_RAMP_DURATION);
_longClip.stopPlaying(DEFAULT_RAMP_DURATION);
}
/**
* Sets a master volume applied to all sound effects.
Expand Down Expand Up @@ -799,6 +815,7 @@ define([
_uiGain = _context.createGain();
_uiGain.connect(_masterGain);
_clip = new SoundClip();
_longClip = new SoundClip();
_source = new SoundSource(0, 0, 0);
if (!_context.createPanner().positionX) {
application.showError("3D audio is not properly supported by your browser!", application.ErrorSeverity.SEVERE, "This game requires 3D positional audio to work properly. Please upgrade to a browser that supports it to play!");
Expand All @@ -812,6 +829,7 @@ define([
SoundSource: SoundSource,
loadSample: loadSample,
playSound: playSound,
stopLastClips: stopLastClips,
setEffectVolume: setEffectVolume,
setMusicVolume: setMusicVolume,
setVoiceVolume: setVoiceVolume,
Expand Down
7 changes: 4 additions & 3 deletions src/js/modules/media-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,10 +1274,11 @@ define([
* @param {Number} [soundCategory=SoundCategory.SOUND_EFFECT] The volume will be affected by the master volume set for this category
* @param {Number} [volume=1]
* @param {Number[3]} [position]
* @param {Number} [rolloff]
* @param {Number} [rolloff=1]
* @param {Boolean} [long=false]
* @returns {Number} The index of the sample that got played (-1 if no sample could be played)
*/
SoundEffectResource.prototype.play = function (soundCategory, volume, position, rolloff) {
SoundEffectResource.prototype.play = function (soundCategory, volume, position, rolloff, long) {
var sample, index;
if (this.isReadyToUse() === false) {
application.showError("Cannot play sound effect '" + this.getName() + "', as it has not been loaded from file yet!");
Expand All @@ -1286,7 +1287,7 @@ define([
index = Math.floor(Math.random() * this._samples.length);
sample = this._samples[index];
if (sample) {
audio.playSound(sample, soundCategory, volume, position, rolloff);
audio.playSound(sample, soundCategory, volume, position, rolloff, long);
return index;
} else {
application.log_DEBUG("WARNING: cannot play sound sample '" + sample + "', as there was a problem while loading it.", 1);
Expand Down

0 comments on commit c136707

Please sign in to comment.