Skip to content

Commit 9516e6b

Browse files
committed
Merge branch 'master' of https://github.com/photonstorm/phaser
2 parents 08047bb + f48c808 commit 9516e6b

3 files changed

Lines changed: 47 additions & 41 deletions

File tree

v3/src/sound/BaseSound.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ var BaseSound = new Class({
2424
*
2525
* @property {ISoundConfig} config
2626
*/
27-
this.config = {
28-
/**
29-
* A value representing the duration, in seconds.
30-
* It could be total sound duration or a marker duration.
31-
*
32-
* @type {number}
33-
*/
34-
duration: 0
35-
};
27+
this.config = {};
3628
/**
3729
* Reference to the currently used config.
3830
* It could be default config or marker config.
@@ -90,6 +82,21 @@ var BaseSound = new Class({
9082
*/
9183
this.pan = 0;
9284
this.config = Extend(this.config, config);
85+
/**
86+
* A value representing the duration, in seconds.
87+
* It could be total sound duration or a marker duration.
88+
*
89+
* @readonly
90+
* @property {number} duration
91+
*/
92+
this.duration = 0;
93+
/**
94+
* Duration of the entire sound.
95+
*
96+
* @readonly
97+
* @property {number}
98+
*/
99+
this.totalDuration = 0;
93100
/**
94101
* Flag indicating if sound is currently playing.
95102
*
@@ -109,13 +116,12 @@ var BaseSound = new Class({
109116
*/
110117
this.markers = {};
111118
/**
112-
* Name of the currently played marker.
113-
* If no marker is played, but instead the whole sound
114-
* the value is an empty string - ''.
119+
* Currently playing marker.
120+
* 'null' if whole sound is playing.
115121
*
116-
* @property {string} currentMarker
122+
* @property {ISoundMarker} currentMarker
117123
*/
118-
this.currentMarker = '';
124+
this.currentMarker = null;
119125
/**
120126
* [description]
121127
*
@@ -137,26 +143,28 @@ var BaseSound = new Class({
137143
removeMarker: function (markerName) {
138144
return false;
139145
},
140-
play: function (marker, config) {
141-
if (marker === void 0) { marker = ''; }
142-
if (typeof marker === 'object') {
143-
config = marker;
144-
marker = '';
146+
play: function (markerName, config) {
147+
if (markerName === void 0) { markerName = ''; }
148+
if (typeof markerName === 'object') {
149+
config = markerName;
150+
markerName = '';
145151
}
146-
if (typeof marker !== 'string') {
152+
if (typeof markerName !== 'string') {
147153
console.error('Sound marker name has to be a string!');
148154
return null;
149155
}
150-
if (!marker) {
156+
if (!markerName) {
151157
this.currentConfig = this.config;
158+
this.duration = this.totalDuration;
152159
}
153160
else {
154-
if (!this.markers[marker]) {
155-
console.error('No marker with name \'' + marker + '\' found for sound \'' + this.key + '\'!');
161+
if (!this.markers[markerName]) {
162+
console.error('No marker with name \'' + markerName + '\' found for sound \'' + this.key + '\'!');
156163
return null;
157164
}
158-
this.currentMarker = marker;
159-
this.currentConfig = this.markers[marker].config;
165+
this.currentMarker = this.markers[markerName];
166+
this.currentConfig = this.currentMarker.config;
167+
this.duration = this.currentMarker.duration;
160168
}
161169
this.currentConfig = Extend(this.currentConfig, config);
162170
this.isPlaying = true;

v3/src/sound/webaudio/WebAudioSound.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var BaseSound = require('../BaseSound');
66
var WebAudioSound = new Class({
77
Extends: BaseSound,
88
initialize: function WebAudioSound(manager, key, config) {
9+
if (config === void 0) { config = {}; }
910
/**
1011
* [description]
1112
*
@@ -48,22 +49,19 @@ var WebAudioSound = new Class({
4849
* @property {number} pausedTime
4950
*/
5051
this.pausedTime = 0;
51-
// TODO add duration and total duration
5252
this.muteNode.connect(this.volumeNode);
5353
this.volumeNode.connect(manager.destination);
54-
if (config === void 0) {
55-
config = {};
56-
}
57-
config.duration = this.audioBuffer.duration;
5854
BaseSound.call(this, manager, key, config);
55+
this.duration = this.audioBuffer.duration;
56+
this.totalDuration = this.audioBuffer.duration;
5957
},
60-
play: function (marker, config) {
61-
if (!BaseSound.prototype.play.call(this, marker, config)) {
58+
play: function (markerName, config) {
59+
if (!BaseSound.prototype.play.call(this, markerName, config)) {
6260
return null;
6361
}
6462
this.stopAndRemoveBufferSource();
6563
// TODO include config offset and marker start
66-
this.createAndStartBufferSource(0, this.currentConfig.duration);
64+
this.createAndStartBufferSource(0, this.duration);
6765
this.startTime = this.manager.context.currentTime;
6866
this.pausedTime = 0;
6967
return this;
@@ -81,7 +79,7 @@ var WebAudioSound = new Class({
8179
return false;
8280
}
8381
var offset = this.pausedTime; // TODO include marker start time
84-
var duration = this.currentConfig.duration - this.pausedTime;
82+
var duration = this.duration - this.pausedTime;
8583
this.createAndStartBufferSource(offset, duration);
8684
this.startTime = this.manager.context.currentTime - this.pausedTime;
8785
this.pausedTime = 0;
@@ -103,6 +101,7 @@ var WebAudioSound = new Class({
103101
* @param {number} offset
104102
* @param {number} duration
105103
*/
104+
// TODO add when param
106105
createAndStartBufferSource: function (offset, duration) {
107106
this.source = this.manager.context.createBufferSource();
108107
this.source.buffer = this.audioBuffer;
@@ -137,7 +136,7 @@ Object.defineProperty(WebAudioSound.prototype, 'mute', {
137136
},
138137
set: function (value) {
139138
this.currentConfig.mute = value;
140-
this.muteNode.gain.value = value ? 0 : 1;
139+
this.muteNode.gain.setValueAtTime(value ? 0 : 1, 0);
141140
}
142141
});
143142
/**
@@ -150,7 +149,7 @@ Object.defineProperty(WebAudioSound.prototype, 'volume', {
150149
},
151150
set: function (value) {
152151
this.currentConfig.volume = value;
153-
this.volumeNode.gain.value = value;
152+
this.volumeNode.gain.setValueAtTime(value, 0);
154153
}
155154
});
156155
/**
@@ -164,7 +163,7 @@ Object.defineProperty(WebAudioSound.prototype, 'rate', {
164163
set: function (value) {
165164
this.currentConfig.rate = value;
166165
if (this.source) {
167-
this.source.playbackRate.value = value * this.manager.rate;
166+
this.source.playbackRate.setValueAtTime(value * this.manager.rate, 0);
168167
}
169168
}
170169
});
@@ -179,8 +178,7 @@ Object.defineProperty(WebAudioSound.prototype, 'detune', {
179178
set: function (value) {
180179
this.currentConfig.detune = value;
181180
if (this.source && this.source.detune) {
182-
this.source.detune.value =
183-
Math.max(-1200, Math.min(value + this.manager.detune, 1200));
181+
this.source.detune.setValueAtTime(Math.max(-1200, Math.min(value + this.manager.detune, 1200)), 0);
184182
}
185183
}
186184
});

v3/src/sound/webaudio/WebAudioSoundManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Object.defineProperty(WebAudioSoundManager.prototype, 'mute', {
9595
return this.masterMuteNode.gain.value === 0;
9696
},
9797
set: function (value) {
98-
this.masterMuteNode.gain.value = value ? 0 : 1;
98+
this.masterMuteNode.gain.setValueAtTime(value ? 0 : 1, 0);
9999
}
100100
});
101101
/**
@@ -107,7 +107,7 @@ Object.defineProperty(WebAudioSoundManager.prototype, 'volume', {
107107
return this.masterVolumeNode.gain.value;
108108
},
109109
set: function (value) {
110-
this.masterVolumeNode.gain.value = value;
110+
this.masterVolumeNode.gain.setValueAtTime(value, 0);
111111
}
112112
});
113113
/**

0 commit comments

Comments
 (0)