Skip to content

Commit 6ca004e

Browse files
committed
Cleanup: Streamline the AudioTrack primitive
1 parent c4824e1 commit 6ca004e

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

Core/API/WebAudio/AudioTrack.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ class AudioTrack {
66
// this.isPlaying = false;
77
// this.volumePercent = null;
88
this.voices = {};
9+
this.volumeGain = 1;
910
this.numVoices = 0;
11+
1012
const currentScene = C_Rendering.getActiveScene();
1113
this.soundtrack = new BABYLON.SoundTrack(currentScene);
12-
this.volumeGain = 1;
13-
this.cleanupInterval = null;
1414
}
1515
getAudioSource(soundHandleID) {
1616
if (soundHandleID === undefined) throw new RangeError(AudioTrack.ERROR_INVALID_VOICE_HANDLE + ": " + soundHandleID);
1717
return this.voices[soundHandleID];
1818
}
1919
addAudioSource(audioSource) {
20-
const soundHandleID = audioSource.getSoundHandle(); // New index at which the source will be inserted
20+
const soundHandleID = audioSource.getUniqueID(); // New index at which the source will be inserted
2121
audioSource.setVolume(this.volumeGain);
2222
// Volumes need to be synchronized or some sounds will stick out like a sore thumb
2323
this.voices[soundHandleID] = audioSource;
@@ -104,21 +104,4 @@ class AudioTrack {
104104

105105
return count;
106106
}
107-
scheduleCleanup(cleanupIntervalInMilliseconds = 5000) {
108-
if (this.hasScheduledCleanup())
109-
throw new Error(
110-
"Failed to schedule cleanup (task is already running). You may want to call stopScheduledCleanup() before re-arming the timer"
111-
);
112-
const interval = setInterval(() => this.purgeInactiveVoices(), cleanupIntervalInMilliseconds);
113-
this.cleanupInterval = interval;
114-
}
115-
hasScheduledCleanup() {
116-
return this.cleanupInterval !== null;
117-
}
118-
stopScheduledCleanup() {
119-
if (!this.hasScheduledCleanup()) return;
120-
121-
clearInterval(this.cleanupInterval);
122-
this.cleanupInterval = null;
123-
}
124107
}

0 commit comments

Comments
 (0)