@@ -6,6 +6,7 @@ var BaseSound = require('../BaseSound');
66var 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} ) ;
0 commit comments