babylon.soundtrack.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var SoundTrack = (function () {
  4. function SoundTrack(scene, options) {
  5. this.id = -1;
  6. this._isMainTrack = false;
  7. this._scene = scene;
  8. this._audioEngine = scene.getEngine().getAudioEngine();
  9. this.soundCollection = new Array();
  10. if (this._audioEngine.canUseWebAudio) {
  11. this._trackGain = this._audioEngine.audioContext.createGain();
  12. //this._trackConvolver = this._audioEngine.audioContext.createConvolver();
  13. //this._trackConvolver.connect(this._trackGain);
  14. this._trackGain.connect(this._audioEngine.masterGain);
  15. if (options) {
  16. if (options.volume) {
  17. this._trackGain.gain.value = options.volume;
  18. }
  19. if (options.mainTrack) {
  20. this._isMainTrack = options.mainTrack;
  21. }
  22. }
  23. }
  24. if (!this._isMainTrack) {
  25. this._scene.soundTracks.push(this);
  26. this.id = this._scene.soundTracks.length - 1;
  27. }
  28. }
  29. SoundTrack.prototype.AddSound = function (sound) {
  30. sound.connectToSoundTrackAudioNode(this._trackGain);
  31. if (sound.soundTrackId) {
  32. if (sound.soundTrackId === -1) {
  33. this._scene.mainSoundTrack.RemoveSound(sound);
  34. } else {
  35. this._scene.soundTracks[sound.soundTrackId].RemoveSound(sound);
  36. }
  37. }
  38. this.soundCollection.push(sound);
  39. sound.soundTrackId = this.id;
  40. };
  41. SoundTrack.prototype.RemoveSound = function (sound) {
  42. var index = this.soundCollection.indexOf(sound);
  43. if (index !== -1) {
  44. this.soundCollection.splice(index, 1);
  45. }
  46. };
  47. SoundTrack.prototype.setVolume = function (newVolume) {
  48. if (this._audioEngine.canUseWebAudio) {
  49. this._trackGain.gain.value = newVolume;
  50. }
  51. };
  52. return SoundTrack;
  53. })();
  54. BABYLON.SoundTrack = SoundTrack;
  55. })(BABYLON || (BABYLON = {}));
  56. //# sourceMappingURL=babylon.soundtrack.js.map