Skip to content

Commit

Permalink
refactor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
orsi committed Jun 3, 2020
1 parent a5d81c2 commit 3a2819d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions script/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var AudioEngine = {
FADE_TIME: 1,
AUDIO_BUFFER_CACHE: {},
_audioPreloaded: false,
audioContext: null,
master: null,
tracks: {
Expand All @@ -16,6 +17,9 @@ var AudioEngine = {
currentBackgroundAudio: null,
currentEventAudio: null,
init: function (options) {
AudioEngine.initAudioContext();
},
initAudioContext: function () {
// for legacy browsers
AudioEngine.audioContext = new (window.AudioContext || window.webkitAudioContext);

Expand All @@ -27,7 +31,7 @@ var AudioEngine = {
AudioEngine.createChannels();
}
},
createChannels() {
createChannels: function () {
// create master
AudioEngine.master = AudioEngine.audioContext.createGain();
AudioEngine.master.gain.setValueAtTime(1.0, AudioEngine.audioContext.currentTime);
Expand Down Expand Up @@ -56,8 +60,8 @@ var AudioEngine = {
},
_getMissingAudioBuffer: function () {
var buffer = AudioEngine.audioContext.createBuffer(
1,
AudioEngine.audioContext.sampleRate,
1,
AudioEngine.audioContext.sampleRate,
AudioEngine.audioContext.sampleRate
);
// Fill the buffer
Expand Down Expand Up @@ -163,7 +167,7 @@ var AudioEngine = {
AudioEngine._playSound(buffer);
});
},
loadAudioFile(src) {
loadAudioFile: function (src) {
if (src.indexOf('http') === -1) {
src = window.location + src;
}
Expand Down

0 comments on commit 3a2819d

Please sign in to comment.