babylon.audioengine.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var AudioEngine = (function () {
  4. function AudioEngine() {
  5. this.audioContext = null;
  6. this.canUseWebAudio = false;
  7. try {
  8. if (typeof AudioContext !== 'undefined') {
  9. this.audioContext = new AudioContext();
  10. this.canUseWebAudio = true;
  11. }
  12. else if (typeof webkitAudioContext !== 'undefined') {
  13. this.audioContext = new webkitAudioContext();
  14. this.canUseWebAudio = true;
  15. }
  16. }
  17. catch (e) {
  18. this.canUseWebAudio = false;
  19. }
  20. // create a global volume gain node
  21. if (this.canUseWebAudio) {
  22. this.masterGain = this.audioContext.createGain();
  23. this.masterGain.gain.value = 1;
  24. this.masterGain.connect(this.audioContext.destination);
  25. }
  26. }
  27. AudioEngine.prototype.getGlobalVolume = function () {
  28. if (this.canUseWebAudio) {
  29. return this.masterGain.gain.value;
  30. }
  31. else {
  32. return -1;
  33. }
  34. };
  35. AudioEngine.prototype.setGlobalVolume = function (newVolume) {
  36. if (this.canUseWebAudio) {
  37. this.masterGain.gain.value = newVolume;
  38. }
  39. };
  40. return AudioEngine;
  41. })();
  42. BABYLON.AudioEngine = AudioEngine;
  43. })(BABYLON || (BABYLON = {}));
  44. //# sourceMappingURL=babylon.audioengine.js.map