@@ -117,9 +117,6 @@ define(function (require) {
117
117
// time that playback was started, in millis
118
118
this . startMillis = null ;
119
119
120
- this . amplitude = new p5 . Amplitude ( ) ;
121
- this . output . connect ( this . amplitude . input ) ;
122
-
123
120
// stereo panning
124
121
this . panPosition = 0.0 ;
125
122
this . panner = new p5 . Panner ( this . output , p5sound . input , 2 ) ;
@@ -344,6 +341,9 @@ define(function (require) {
344
341
345
342
// make a new source and counter. They are automatically assigned playbackRate and buffer
346
343
this . bufferSourceNode = this . _initSourceNode ( ) ;
344
+
345
+ // garbage collect counterNode and create a new one
346
+ if ( this . _counterNode ) this . _counterNode = undefined ;
347
347
this . _counterNode = this . _initCounterNode ( ) ;
348
348
349
349
if ( _cueStart ) {
@@ -401,9 +401,9 @@ define(function (require) {
401
401
this . bufferSourceNode . _arrayIndex = this . bufferSourceNodes . length - 1 ;
402
402
403
403
// delete this.bufferSourceNode from the sources array when it is done playing:
404
- this . bufferSourceNode . onended = function ( e ) {
404
+ var clearOnEnd = function ( e ) {
405
405
this . _playing = false ;
406
-
406
+ this . removeEventListener ( 'ended' , clearOnEnd , false ) ;
407
407
// call the onended callback
408
408
self . _onended ( self ) ;
409
409
@@ -416,7 +416,9 @@ define(function (require) {
416
416
if ( self . bufferSourceNodes . length === 0 ) {
417
417
self . _playing = false ;
418
418
}
419
- }
419
+ } ;
420
+
421
+ this . bufferSourceNode . onended = clearOnEnd ;
420
422
}
421
423
// If soundFile hasn't loaded the buffer yet, throw an error
422
424
else {
@@ -1063,6 +1065,11 @@ define(function (require) {
1063
1065
1064
1066
p5 . SoundFile . prototype . dispose = function ( ) {
1065
1067
var now = p5sound . audiocontext . currentTime ;
1068
+
1069
+ // remove reference to soundfile
1070
+ var index = p5sound . soundArray . indexOf ( this ) ;
1071
+ p5sound . soundArray . splice ( index , 1 ) ;
1072
+
1066
1073
this . stop ( now ) ;
1067
1074
if ( this . buffer && this . bufferSourceNode ) {
1068
1075
for ( var i = 0 ; i < this . bufferSourceNodes . length - 1 ; i ++ ) {
@@ -1124,21 +1131,9 @@ define(function (require) {
1124
1131
} ;
1125
1132
1126
1133
/**
1127
- * Read the Amplitude (volume level) of a p5.SoundFile. The
1128
- * p5.SoundFile class contains its own instance of the Amplitude
1129
- * class to help make it easy to get a SoundFile's volume level.
1130
- * Accepts an optional smoothing value (0.0 < 1.0).
1131
- *
1132
- * @method getLevel
1133
- * @param {Number } [smoothing] Smoothing is 0.0 by default.
1134
- * Smooths values based on previous values.
1135
- * @return {Number } Volume level (between 0.0 and 1.0)
1136
1134
*/
1137
1135
p5 . SoundFile . prototype . getLevel = function ( smoothing ) {
1138
- if ( smoothing ) {
1139
- this . amplitude . smoothing = smoothing ;
1140
- }
1141
- return this . amplitude . getLevel ( ) ;
1136
+ console . warn ( 'p5.SoundFile.getLevel has been removed from the library. Use p5.Amplitude instead' )
1142
1137
} ;
1143
1138
1144
1139
/**
@@ -1200,6 +1195,7 @@ define(function (require) {
1200
1195
// dispose of scope node if it already exists
1201
1196
if ( self . _scopeNode ) {
1202
1197
self . _scopeNode . disconnect ( ) ;
1198
+ self . _scopeNode . onaudioprocess = undefined ;
1203
1199
self . _scopeNode = null ;
1204
1200
}
1205
1201
@@ -1580,7 +1576,8 @@ define(function (require) {
1580
1576
* @param {Number } id ID of the cue, as returned by addCue
1581
1577
*/
1582
1578
p5 . SoundFile . prototype . removeCue = function ( id ) {
1583
- for ( var i = 0 ; i < this . _cues . length ; i ++ ) {
1579
+ var cueLength = this . _cues . length ;
1580
+ for ( var i = 0 ; i < cueLength ; i ++ ) {
1584
1581
var cue = this . _cues [ i ] ;
1585
1582
if ( cue . id === id ) {
1586
1583
this . cues . splice ( i , 1 ) ;
@@ -1608,16 +1605,17 @@ define(function (require) {
1608
1605
// have been scheduled using addCue(callback, time).
1609
1606
p5 . SoundFile . prototype . _onTimeUpdate = function ( position ) {
1610
1607
var playbackTime = position / this . buffer . sampleRate ;
1608
+ var cueLength = this . _cues . length ;
1611
1609
1612
- for ( var i = 0 ; i < this . _cues . length ; i ++ ) {
1613
- var callbackTime = this . _cues [ i ] . time ;
1614
- var val = this . _cues [ i ] . val ;
1615
-
1610
+ for ( var i = 0 ; i < cueLength ; i ++ ) {
1611
+ var cue = this . _cues [ i ] ;
1612
+ var callbackTime = cue . time ;
1613
+ var val = cue . val ;
1616
1614
1617
1615
if ( this . _prevTime < callbackTime && callbackTime <= playbackTime ) {
1618
1616
1619
1617
// pass the scheduled callbackTime as parameter to the callback
1620
- this . _cues [ i ] . callback ( val ) ;
1618
+ cue . callback ( val ) ;
1621
1619
}
1622
1620
1623
1621
}
0 commit comments