@@ -91,6 +91,15 @@ var WebAudioSound = new Class({
9191 */
9292 this . volumeNode = manager . context . createGain ( ) ;
9393
94+ /**
95+ * Panner node responsible for controlling this sound's pan.
96+ *
97+ * @name Phaser.Sound.WebAudioSound#pannerNode
98+ * @type {StereoPannerNode }
99+ * @private
100+ */
101+ this . pannerNode = manager . context . createStereoPanner ( ) ;
102+
94103 /**
95104 * The time at which the sound should have started playback from the beginning.
96105 * Based on BaseAudioContext.currentTime value.
@@ -165,7 +174,9 @@ var WebAudioSound = new Class({
165174
166175 this . muteNode . connect ( this . volumeNode ) ;
167176
168- this . volumeNode . connect ( manager . destination ) ;
177+ this . volumeNode . connect ( this . pannerNode ) ;
178+
179+ this . pannerNode . connect ( manager . destination ) ;
169180
170181 this . duration = this . audioBuffer . duration ;
171182
@@ -493,6 +504,8 @@ var WebAudioSound = new Class({
493504 this . muteNode = null ;
494505 this . volumeNode . disconnect ( ) ;
495506 this . volumeNode = null ;
507+ this . pannerNode . disconnect ( ) ;
508+ this . pannerNode = null ;
496509 this . rateUpdates . length = 0 ;
497510 this . rateUpdates = null ;
498511 } ,
@@ -892,6 +905,49 @@ var WebAudioSound = new Class({
892905 {
893906 this . loop = value ;
894907
908+ return this ;
909+ } ,
910+
911+ /**
912+ * Gets or sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan).
913+ *
914+ * @name Phaser.Sound.WebAudioSound#pan
915+ * @type {number }
916+ * @default 0
917+ * @fires Phaser.Sound.Events#PAN
918+ * @since 3.0.0
919+ */
920+ pan : {
921+
922+ get : function ( )
923+ {
924+ return this . pannerNode . pan . value ;
925+ } ,
926+
927+ set : function ( value )
928+ {
929+ this . currentConfig . pan = value ;
930+ this . pannerNode . pan . setValueAtTime ( value , this . manager . context . currentTime ) ;
931+
932+ this . emit ( Events . PAN , this , value ) ;
933+ }
934+ } ,
935+
936+ /**
937+ * Sets the pan of this Sound.
938+ *
939+ * @method Phaser.Sound.WebAudioSound#setPan
940+ * @fires Phaser.Sound.Events#PAN
941+ * @since 3.4.0
942+ *
943+ * @param {number } value - The pan of the sound.
944+ *
945+ * @return {Phaser.Sound.WebAudioSound } This Sound instance.
946+ */
947+ setPan : function ( value )
948+ {
949+ this . pan = value ;
950+
895951 return this ;
896952 }
897953
0 commit comments