Skip to content

Commit 18ca26e

Browse files
defined volume property on WebAudioSound prototype
connected properly WebAudioSound nodes
1 parent c4f09de commit 18ca26e

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

v3/src/sound/WebAudioSound.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var WebAudioSound = new Class({
2121
* @property {GainNode} volumeNode
2222
*/
2323
this.volumeNode = manager.context.createGain();
24+
this.volumeNode.connect(manager.destination);
2425
if (config === void 0) {
2526
config = {};
2627
}
@@ -44,9 +45,21 @@ var WebAudioSound = new Class({
4445
var source = this.manager.context.createBufferSource();
4546
// TODO assign config values to buffer source
4647
source.buffer = this.audioBuffer;
47-
source.connect(this.manager.destination);
48+
source.connect(this.volumeNode);
4849
source.start();
4950
return this;
5051
}
5152
});
53+
/**
54+
* Global volume setting.
55+
* @property {number} volume
56+
*/
57+
Object.defineProperty(WebAudioSound.prototype, 'volume', {
58+
get: function () {
59+
return this.volumeNode.gain.value;
60+
},
61+
set: function (value) {
62+
this.volumeNode.gain.value = value;
63+
}
64+
});
5265
module.exports = WebAudioSound;

0 commit comments

Comments
 (0)