Skip to content

Commit 9fffd57

Browse files
Moved sound source not null check from properties' setter methods to setRate method
1 parent db06b3d commit 9fffd57

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

v3/src/sound/webaudio/WebAudioSound.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ var WebAudioSound = new Class({
155155
* @private
156156
*/
157157
setRate: function () {
158-
var cent = 1.0005777895065548; // Math.pow(2, 1/1200);
159-
var totalDetune = Math.max(-1200, Math.min(this.currentConfig.detune + this.manager.detune, 1200));
160-
var detuneRate = Math.pow(cent, totalDetune);
161-
var totalRate = this.currentConfig.rate * this.manager.rate * detuneRate;
162-
this.source.playbackRate.setValueAtTime(totalRate, 0);
158+
if (this.source) {
159+
var cent = 1.0005777895065548; // Math.pow(2, 1/1200);
160+
var totalDetune = Math.max(-1200, Math.min(this.currentConfig.detune + this.manager.detune, 1200));
161+
var detuneRate = Math.pow(cent, totalDetune);
162+
var totalRate = this.currentConfig.rate * this.manager.rate * detuneRate;
163+
this.source.playbackRate.setValueAtTime(totalRate, 0);
164+
}
163165
}
164166
});
165167
/**
@@ -198,9 +200,7 @@ Object.defineProperty(WebAudioSound.prototype, 'rate', {
198200
},
199201
set: function (value) {
200202
this.currentConfig.rate = value;
201-
if (this.source) {
202-
this.setRate();
203-
}
203+
this.setRate();
204204
}
205205
});
206206
/**
@@ -213,9 +213,7 @@ Object.defineProperty(WebAudioSound.prototype, 'detune', {
213213
},
214214
set: function (value) {
215215
this.currentConfig.detune = value;
216-
if (this.source && this.source.detune) {
217-
this.setRate();
218-
}
216+
this.setRate();
219217
}
220218
});
221219
module.exports = WebAudioSound;

0 commit comments

Comments
 (0)