-
Notifications
You must be signed in to change notification settings - Fork 827
Expand file tree
/
Copy pathAbstractSoundInstance.js
More file actions
1190 lines (1084 loc) · 35.5 KB
/
AbstractSoundInstance.js
File metadata and controls
1190 lines (1084 loc) · 35.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* AbstractSoundInstance
* Visit http://createjs.com/ for documentation, updates and examples.
*
*
* Copyright (c) 2012 gskinner.com, inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// namespace:
this.createjs = this.createjs || {};
/**
* A AbstractSoundInstance is created when any calls to the Sound API method {{#crossLink "Sound/play"}}{{/crossLink}} or
* {{#crossLink "Sound/createInstance"}}{{/crossLink}} are made. The AbstractSoundInstance is returned by the active plugin
* for control by the user.
*
* <h4>Example</h4>
*
* var myInstance = createjs.Sound.play("myAssetPath/mySrcFile.mp3");
*
* A number of additional parameters provide a quick way to determine how a sound is played. Please see the Sound
* API method {{#crossLink "Sound/play"}}{{/crossLink}} for a list of arguments.
*
* Once a AbstractSoundInstance is created, a reference can be stored that can be used to control the audio directly through
* the AbstractSoundInstance. If the reference is not stored, the AbstractSoundInstance will play out its audio (and any loops), and
* is then de-referenced from the {{#crossLink "Sound"}}{{/crossLink}} class so that it can be cleaned up. If audio
* playback has completed, a simple call to the {{#crossLink "AbstractSoundInstance/play"}}{{/crossLink}} instance method
* will rebuild the references the Sound class need to control it.
*
* var myInstance = createjs.Sound.play("myAssetPath/mySrcFile.mp3", {loop:2});
* myInstance.on("loop", handleLoop);
* function handleLoop(event) {
* myInstance.volume = myInstance.volume * 0.5;
* }
*
* Events are dispatched from the instance to notify when the sound has completed, looped, or when playback fails
*
* var myInstance = createjs.Sound.play("myAssetPath/mySrcFile.mp3");
* myInstance.on("complete", handleComplete);
* myInstance.on("loop", handleLoop);
* myInstance.on("failed", handleFailed);
*
*
* @class AbstractSoundInstance
* @param {String} src The path to and file name of the sound.
* @param {Number} startTime Audio sprite property used to apply an offset, in milliseconds.
* @param {Number} duration Audio sprite property used to set the time the clip plays for, in milliseconds.
* @param {Object} playbackResource Any resource needed by plugin to support audio playback.
* @extends EventDispatcher
* @constructor
*/
(function () {
"use strict";
// Constructor:
var AbstractSoundInstance = function (src, startTime, duration, playbackResource) {
this.EventDispatcher_constructor();
// public properties:
/**
* The source of the sound.
* @property src
* @type {String}
* @default null
*/
this.src = src;
/**
* The unique ID of the instance. This is set by {{#crossLink "Sound"}}{{/crossLink}}.
* @property uniqueId
* @type {String} | Number
* @default -1
*/
this.uniqueId = -1;
/**
* The play state of the sound. Play states are defined as constants on {{#crossLink "Sound"}}{{/crossLink}}.
* @property playState
* @type {String}
* @default null
*/
this.playState = null;
/**
* A Timeout created by {{#crossLink "Sound"}}{{/crossLink}} when this AbstractSoundInstance is played with a delay.
* This allows AbstractSoundInstance to remove the delay if stop, pause, or cleanup are called before playback begins.
* @property delayTimeoutId
* @type {timeoutVariable}
* @default null
* @protected
* @since 0.4.0
*/
this.delayTimeoutId = null;
// TODO consider moving delay into AbstractSoundInstance so it can be handled by plugins
// private properties
// Getter / Setter Properties
// OJR TODO find original reason that we didn't use defined functions. I think it was performance related
/**
* The volume of the sound, between 0 and 1.
*
* The actual output volume of a sound can be calculated using:
* <code>myInstance.volume * createjs.Sound.getVolume();</code>
*
* @property volume
* @type {Number}
* @default 1
*/
this._volume = 1;
Object.defineProperty(this, "volume", {
get: this.getVolume,
set: this.setVolume
});
/**
* The pan of the sound, between -1 (left) and 1 (right). Note that pan is not supported by HTML Audio.
*
* <br />Note in WebAudioPlugin this only gives us the "x" value of what is actually 3D audio.
*
* @property pan
* @type {Number}
* @default 0
*/
this._pan = 0;
Object.defineProperty(this, "pan", {
get: this.getPan,
set: this.setPan
});
/**
* The filter frequency of the sound, between 0 and half the sample rate. Note that filter is not supported by HTML Audio.
*
* @property filterFrequency
* @type {Number}
* @default 22050
*/
this._filterFrequency = 22050;
Object.defineProperty(this, "filterFrequency", {
get: this.getFilterFrequency,
set: this.setFilterFrequency
});
/**
* The filter quality factor of the sound, between 0.0001 and 1000. Note that filter is not supported by HTML Audio.
*
* @property filterFrequency
* @type {Number}
* @default 1
*/
this._filterQ = 1;
Object.defineProperty(this, "filterQ", {
get: this.getFilterQ,
set: this.setFilterQ
});
/**
* The filter type, one of the following: "lowpass" "highpass" bandpass". Note that filter is not supported by HTML Audio.
*
* @property filterType
* @type {String}
* @default "lowpass"
*/
this._filterType = "lowpass";
Object.defineProperty(this, "filterType", {
get: this.getFilterType,
set: this.setFilterType
});
/**
* The filter detune value in cents. Note that filter is not supported by HTML Audio.
*
* @property filterDetune
* @type {Number}
* @default 0
*/
this._filterDetune = 0;
Object.defineProperty(this, "filterDetune", {
get: this.getFilterDetune,
set: this.setFilterDetune
});
/**
* The distortion value in amount. Note that distortion is not supported by HTML Audio.
*
* @property distortionAmount
* @type {Number}
* @default 0
*/
this._distortionAmount = 0;
Object.defineProperty(this, "distortionAmount", {
get: this.getDistortionAmount,
set: this.setDistortionAmount
});
/**
* The convolver buffer to use on the convolver node. This can be an audioBuffer or a filepath, and will be handled appropriately depending on which.
* Note that convolver is not supported by HTML Audio.
*
* @property convolverBuffer
* @type {String} || {AudioBuffer}
* @default null
*/
this._convolverBuffer = null;
Object.defineProperty(this, "convolverBuffer", {
get: this.getConvolverBuffer,
set: this.setConvolverBuffer
});
/**
* Audio sprite property used to determine the starting offset.
* @property startTime
* @type {Number}
* @default 0
* @since 0.6.1
*/
this._startTime = Math.max(0, startTime || 0);
Object.defineProperty(this, "startTime", {
get: this.getStartTime,
set: this.setStartTime
});
/**
* Sets or gets the length of the audio clip, value is in milliseconds.
*
* @property duration
* @type {Number}
* @default 0
* @since 0.6.0
*/
this._duration = Math.max(0, duration || 0);
Object.defineProperty(this, "duration", {
get: this.getDuration,
set: this.setDuration
});
/**
* Object that holds plugin specific resource need for audio playback.
* This is set internally by the plugin. For example, WebAudioPlugin will set an array buffer,
* HTMLAudioPlugin will set a tag, FlashAudioPlugin will set a flash reference.
*
* @property playbackResource
* @type {Object}
* @default null
*/
this._playbackResource = null;
Object.defineProperty(this, "playbackResource", {
get: this.getPlaybackResource,
set: this.setPlaybackResource
});
if(playbackResource !== false && playbackResource !== true) { this.setPlaybackResource(playbackResource); }
/**
* The position of the playhead in milliseconds. This can be set while a sound is playing, paused, or stopped.
*
* @property position
* @type {Number}
* @default 0
* @since 0.6.0
*/
this._position = 0;
Object.defineProperty(this, "position", {
get: this.getPosition,
set: this.setPosition
});
/**
* The number of play loops remaining. Negative values will loop infinitely.
*
* @property loop
* @type {Number}
* @default 0
* @public
* @since 0.6.0
*/
this._loop = 0;
Object.defineProperty(this, "loop", {
get: this.getLoop,
set: this.setLoop
});
/**
* Mutes or unmutes the current audio instance.
*
* @property muted
* @type {Boolean}
* @default false
* @since 0.6.0
*/
this._muted = false;
Object.defineProperty(this, "muted", {
get: this.getMuted,
set: this.setMuted
});
/**
* Pauses or resumes the current audio instance.
*
* @property paused
* @type {Boolean}
*/
this._paused = false;
Object.defineProperty(this, "paused", {
get: this.getPaused,
set: this.setPaused
});
// Events
/**
* The event that is fired when playback has started successfully.
* @event succeeded
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
/**
* The event that is fired when playback is interrupted. This happens when another sound with the same
* src property is played using an interrupt value that causes this instance to stop playing.
* @event interrupted
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
/**
* The event that is fired when playback has failed. This happens when there are too many channels with the same
* src property already playing (and the interrupt value doesn't cause an interrupt of another instance), or
* the sound could not be played, perhaps due to a 404 error.
* @event failed
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
/**
* The event that is fired when a sound has completed playing but has loops remaining.
* @event loop
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
/**
* The event that is fired when playback completes. This means that the sound has finished playing in its
* entirety, including its loop iterations.
* @event complete
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
};
var p = createjs.extend(AbstractSoundInstance, createjs.EventDispatcher);
// TODO: deprecated
// p.initialize = function() {}; // searchable for devs wondering where it is. REMOVED. See docs for details.
// Public Methods:
/**
* Play an instance. This method is intended to be called on SoundInstances that already exist (created
* with the Sound API {{#crossLink "Sound/createInstance"}}{{/crossLink}} or {{#crossLink "Sound/play"}}{{/crossLink}}).
*
* <h4>Example</h4>
*
* var myInstance = createjs.Sound.createInstance(mySrc);
* myInstance.play({interrupt:createjs.Sound.INTERRUPT_ANY, loop:2, pan:0.5});
*
* Note that if this sound is already playing, this call will still set the passed in parameters.
* <b>Parameters Deprecated</b><br />
* The parameters for this method are deprecated in favor of a single parameter that is an Object or {{#crossLink "PlayPropsConfig"}}{{/crossLink}}.
*
* @method play
* @param {String | Object} [interrupt="none"|options] <b>This parameter will be renamed playProps in the next release.</b><br />
* This parameter can be an instance of {{#crossLink "PlayPropsConfig"}}{{/crossLink}} or an Object that contains any or all optional properties by name,
* including: interrupt, delay, offset, loop, volume, pan, startTime, and duration (see the above code sample).
* <br /><strong>OR</strong><br />
* <b>Deprecated</b> How to interrupt any currently playing instances of audio with the same source,
* if the maximum number of instances of the sound are already playing. Values are defined as <code>INTERRUPT_TYPE</code>
* constants on the Sound class, with the default defined by {{#crossLink "Sound/defaultInterruptBehavior:property"}}{{/crossLink}}.
* @param {Number} [delay=0] <b>Deprecated</b> The amount of time to delay the start of audio playback, in milliseconds.
* @param {Number} [offset=0] <b>Deprecated</b> The offset from the start of the audio to begin playback, in milliseconds.
* @param {Number} [loop=0] <b>Deprecated</b> How many times the audio loops when it reaches the end of playback. The default is 0 (no
* loops), and -1 can be used for infinite playback.
* @param {Number} [volume=1] <b>Deprecated</b> The volume of the sound, between 0 and 1. Note that the master volume is applied
* against the individual volume.
* @param {Number} [pan=0] <b>Deprecated</b> The left-right pan of the sound (if supported), between -1 (left) and 1 (right).
* Note that pan is not supported for HTML Audio.
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p.play = function (interrupt, delay, offset, loop, volume, pan) {
var playProps;
if (interrupt instanceof Object || interrupt instanceof createjs.PlayPropsConfig) {
playProps = createjs.PlayPropsConfig.create(interrupt);
} else {
playProps = createjs.PlayPropsConfig.create({interrupt:interrupt, delay:delay, offset:offset, loop:loop, volume:volume, pan:pan});
}
if (this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this.applyPlayProps(playProps);
if (this._paused) { this.setPaused(false); }
return;
}
this._cleanUp();
createjs.Sound._playInstance(this, playProps); // make this an event dispatch??
return this;
};
/**
* Stop playback of the instance. Stopped sounds will reset their position to 0, and calls to {{#crossLink "AbstractSoundInstance/resume"}}{{/crossLink}}
* will fail. To start playback again, call {{#crossLink "AbstractSoundInstance/play"}}{{/crossLink}}.
*
* If you don't want to lose your position use yourSoundInstance.paused = true instead. {{#crossLink "AbstractSoundInstance/paused"}}{{/crossLink}}.
*
* <h4>Example</h4>
*
* myInstance.stop();
*
* @method stop
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p.stop = function () {
this._position = 0;
this._paused = false;
this._handleStop();
this._cleanUp();
this.playState = createjs.Sound.PLAY_FINISHED;
return this;
};
/**
* Remove all external references and resources from AbstractSoundInstance. Note this is irreversible and AbstractSoundInstance will no longer work
* @method destroy
* @since 0.6.0
*/
p.destroy = function() {
this._cleanUp();
this.src = null;
this.playbackResource = null;
this.removeAllEventListeners();
};
/**
* Takes an PlayPropsConfig or Object with the same properties and sets them on this instance.
* @method applyPlayProps
* @param {PlayPropsConfig | Object} playProps A PlayPropsConfig or object containing the same properties.
* @since 0.6.1
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p.applyPlayProps = function(playProps) {
if (playProps.offset != null) { this.setPosition(playProps.offset) }
if (playProps.loop != null) { this.setLoop(playProps.loop); }
if (playProps.volume != null) { this.setVolume(playProps.volume); }
if (playProps.pan != null) { this.setPan(playProps.pan); }
if (playProps.startTime != null) {
this.setStartTime(playProps.startTime);
this.setDuration(playProps.duration);
}
return this;
};
p.toString = function () {
return "[AbstractSoundInstance]";
};
// get/set methods that allow support for IE8
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/paused:property"}}{{/crossLink}} directly as a property,
*
* @deprecated
* @method getPaused
* @returns {boolean} If the instance is currently paused
* @since 0.6.0
*/
p.getPaused = function() {
return this._paused;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/paused:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setPaused
* @param {boolean} value
* @since 0.6.0
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p.setPaused = function (value) {
if ((value !== true && value !== false) || this._paused == value) {return;}
if (value == true && this.playState != createjs.Sound.PLAY_SUCCEEDED) {return;}
this._paused = value;
if(value) {
this._pause();
} else {
this._resume();
}
clearTimeout(this.delayTimeoutId);
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/volume:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setVolume
* @param {Number} value The volume to set, between 0 and 1.
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p.setVolume = function (value) {
if (value == this._volume) { return this; }
this._volume = Math.max(0, Math.min(1, value));
if (!this._muted) {
this._updateVolume();
}
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/volume:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getVolume
* @return {Number} The current volume of the sound instance.
*/
p.getVolume = function () {
return this._volume;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/muted:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setMuted
* @param {Boolean} value If the sound should be muted.
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
* @since 0.6.0
*/
p.setMuted = function (value) {
if (value !== true && value !== false) {return;}
this._muted = value;
this._updateVolume();
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/muted:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getMuted
* @return {Boolean} If the sound is muted.
* @since 0.6.0
*/
p.getMuted = function () {
return this._muted;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/pan:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setPan
* @param {Number} value The pan value, between -1 (left) and 1 (right).
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p.setPan = function (value) {
if(value == this._pan) { return this; }
this._pan = Math.max(-1, Math.min(1, value));
this._updatePan();
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/pan:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getPan
* @return {Number} The value of the pan, between -1 (left) and 1 (right).
*/
p.getPan = function () {
return this._pan;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/filterFrequency:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setFilterFrequency
* @param {Number} value The filter frequency value, between 0 and half the sample rate.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p.setFilterFrequency = function (value) {
if(value == this._filterFrequency) { return this; }
this._filterFrequency = value;
this._updateFilter();
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/filterFrequency:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getFilterFrequency
* @return {Number} The value of the filter frequency, between 0 and half the sample rate.
*/
p.getFilterFrequency = function () {
return this._filterFrequency;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/filterQ:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setFilterQ
* @param {Number} value The filter quality factor, between 0.0001 and 1000.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p.setFilterQ = function (value) {
if(value == this._filterQ) { return this; }
this._filterQ = value;
this._updateFilter();
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/filterQ:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getFilterQ
* @return {Number} The value of the filter frequency, between 0.0001 and 1000.
*/
p.getFilterQ = function () {
return this._filterQ;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/filterType:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setFilterType
* @param {String} The filter type, one of the following: "lowpass" "highpass" bandpass".
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p.setFilterType = function (value) {
if(value == this._filterType) { return this; }
var acceptedTypes = {
"lowpass" : true,
"highpass" : true,
"bandpass" : true
};
if (typeof acceptedTypes[value] === 'undefined') { return false; }
this._filterType = value;
this._updateFilter();
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/filterType:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getFilterType
* @return {String} The filter type, one of the following: "lowpass" "highpass" bandpass".
*/
p.getFilterType = function () {
return this._filterType;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/filterDetune:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setFilterDetune
* @param {Number} The filter detune value in cents.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p.setFilterDetune = function (value) {
if(value == this._filterDetune) { return this; }
this._filterDetune= value;
this._updateFilter();
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/filterDetune:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getFilterDetune
* @return {Number} The filter detune value in cents.
*/
p.getFilterDetune = function () {
return this._filterDetune;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/distortionAmount:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setDistortionAmount
* @param {Number} The distortion value in amount.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p.setDistortionAmount = function (value) {
if(value == this._distortionAmount) { return this; }
this._distortionAmount = value;
this._updateDistortion();
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/distortionAmount:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getDistortionAmount
* @return {Number} The distortion value in amount.
*/
p.getDistortionAmount = function () {
return this._distortionAmount;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/convolverBuffer:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setConvolverBuffer
* @param {String} The filepath to an impulse response WAV || {AudioBuffer} The audio buffer to use as the convoler's buffer.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p.setConvolverBuffer = function (buffer) {
if (typeof buffer === 'string') {
//if a filepath is passed, must import it as an arraybuffer and decode
this._getConvolverBufferFromFilepath(buffer);
}
else {
if (typeof AudioBuffer !== 'undefined' && buffer instanceof AudioBuffer) {
//audio buffer is passed, set it directly
this._convolverBuffer = buffer;
this._updateConvolver();
}
else {
return false;
}
}
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/convolverBuffer:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getConvolverBuffer
* @return {AudioBuffer} The audio buffer being used as the convolver's buffer.
*/
p.getConvolverBuffer = function () {
return this._convolverBuffer;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/position:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getPosition
* @return {Number} The position of the playhead in the sound, in milliseconds.
*/
p.getPosition = function () {
if (!this._paused && this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this._position = this._calculateCurrentPosition();
}
return this._position;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/position:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setPosition
* @param {Number} value The position to place the playhead, in milliseconds.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p.setPosition = function (value) {
this._position = Math.max(0, value);
if (this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this._updatePosition();
}
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getStartTime
* @return {Number} The startTime of the sound instance in milliseconds.
*/
p.getStartTime = function () {
return this._startTime;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setStartTime
* @param {number} value The new startTime time in milli seconds.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p.setStartTime = function (value) {
if (value == this._startTime) { return this; }
this._startTime = Math.max(0, value || 0);
this._updateStartTime();
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/duration:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getDuration
* @return {Number} The duration of the sound instance in milliseconds.
*/
p.getDuration = function () {
return this._duration;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/duration:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setDuration
* @param {number} value The new duration time in milli seconds.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
* @since 0.6.0
*/
p.setDuration = function (value) {
if (value == this._duration) { return this; }
this._duration = Math.max(0, value || 0);
this._updateDuration();
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/playbackResource:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setPlayback
* @param {Object} value The new playback resource.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
* @since 0.6.0
**/
p.setPlaybackResource = function (value) {
this._playbackResource = value;
if (this._duration == 0) { this._setDurationFromSource(); }
return this;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/playbackResource:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method setPlayback
* @param {Object} value The new playback resource.
* @return {Object} playback resource used for playing audio
* @since 0.6.0
**/
p.getPlaybackResource = function () {
return this._playbackResource;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/loop:property"}}{{/crossLink}} directly as a property
*
* @deprecated
* @method getLoop
* @return {number}
* @since 0.6.0
**/
p.getLoop = function () {
return this._loop;
};
/**
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/loop:property"}}{{/crossLink}} directly as a property,
*
* @deprecated
* @method setLoop
* @param {number} value The number of times to loop after play.
* @since 0.6.0
*/
p.setLoop = function (value) {
if(this._playbackResource != null) {
// remove looping
if (this._loop != 0 && value == 0) {
this._removeLooping(value);
}
// add looping
else if (this._loop == 0 && value != 0) {
this._addLooping(value);
}
}
this._loop = value;
};
// Private Methods:
/**
* A helper method that dispatches all events for AbstractSoundInstance.
* @method _sendEvent
* @param {String} type The event type
* @protected
*/
p._sendEvent = function (type) {
var event = new createjs.Event(type);
this.dispatchEvent(event);
};
/**
* Clean up the instance. Remove references and clean up any additional properties such as timers.
* @method _cleanUp
* @protected
*/
p._cleanUp = function () {
clearTimeout(this.delayTimeoutId); // clear timeout that plays delayed sound
this._handleCleanUp();
this._paused = false;
createjs.Sound._playFinished(this); // TODO change to an event
};
/**
* The sound has been interrupted.
* @method _interrupt
* @protected
*/
p._interrupt = function () {
this._cleanUp();
this.playState = createjs.Sound.PLAY_INTERRUPTED;
this._sendEvent("interrupted");
};
/**
* Called by the Sound class when the audio is ready to play (delay has completed). Starts sound playing if the
* src is loaded, otherwise playback will fail.
* @method _beginPlaying
* @param {PlayPropsConfig} playProps A PlayPropsConfig object.
* @return {Boolean} If playback succeeded.
* @protected
*/
// OJR FlashAudioSoundInstance overwrites
p._beginPlaying = function (playProps) {
this.setPosition(playProps.offset);
this.setLoop(playProps.loop);
this.setVolume(playProps.volume);
this.setPan(playProps.pan);
if (playProps.startTime != null) {
this.setStartTime(playProps.startTime);
this.setDuration(playProps.duration);
}
if (this._playbackResource != null && this._position < this._duration) {
this._paused = false;
this._handleSoundReady();
this.playState = createjs.Sound.PLAY_SUCCEEDED;
this._sendEvent("succeeded");
return true;
} else {
this._playFailed();
return false;
}