addon/classes/sampler.js:16
Sampler
An instance of the Sampler class behaves just like a Sound, but allows many AudioBuffers to exist and automatically alternately plays them (round-robin) each time any of the play methods are called.
Property Summary
Public Properties | |
---|---|
public |
Determines the gain applied to each sample. |
public |
Determines the stereo pan position of each sample. |
public |
Acts as a register for loaded audio sources. Audio sources can be anything that uses Playable. If not set on instantiation, automatically set to |
Private Properties | |
---|---|
private |
Temporary storage for the iterable that comes from the sounds Set. This iterable is meant to be replaced with a new copy every time it reaches it's end, resulting in an infinite stream of Sound instances. |
Method Summary
Public Methods | |
---|---|
public |
play( )
Gets the next audio source and plays it immediately. |
public |
playAt(time)
Gets the next Sound and plays it at the specified moment in time. A "moment in time" is measured in seconds from the moment that the AudioContext was instantiated. |
public |
playIn(seconds)
Gets the next Sound and plays it after the specified offset has elapsed. |
Private Methods | |
---|---|
private |
_getNextSound( ): Sound
Gets _soundIterator and returns it's next value. If _soundIterator has reached it's end, replaces _soundIterator with a fresh copy from sounds and returns the first value from that. |
private |
_initSounds( )
Sets |
private |
_setGainAndPan( ): Sound
Applies the |
Public Properties
addon/classes/sampler.js:30
public gain: Number
Determines the gain applied to each sample.
addon/classes/sampler.js:40
public pan: Number
Determines the stereo pan position of each sample.
addon/classes/sampler.js:62
public sounds: Set
Acts as a register for loaded audio sources. Audio sources can be anything
that uses Playable. If not set on
instantiation, automatically set to new Set()
via _initSounds
.
Private Properties
addon/classes/sampler.js:50
private _soundIterator: Iterator
Temporary storage for the iterable that comes from the sounds Set. This iterable is meant to be replaced with a new copy every time it reaches it's end, resulting in an infinite stream of Sound instances.
Public Methods
addon/classes/sampler.js:73
public play( )
Gets the next audio source and plays it immediately.
addon/classes/sampler.js:96
public playAt(time)
Gets the next Sound and plays it at the specified moment in time. A "moment in time" is measured in seconds from the moment that the AudioContext was instantiated.
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
time | Number |
|
The moment in time (in seconds, relative to the AudioContext's "beginning of time") when the next Sound should be played. |
addon/classes/sampler.js:83
public playIn(seconds)
Gets the next Sound and plays it after the specified offset has elapsed.
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
seconds | Number |
|
Number of seconds from "now" that the next Sound should be played. |
Private Methods
addon/classes/sampler.js:112
private _getNextSound( ): Sound
Gets _soundIterator and returns it's next value. If _soundIterator has reached it's end, replaces _soundIterator with a fresh copy from sounds and returns the first value from that.
Return:
addon/classes/sampler.js:156
private _initSounds( )
Sets sounds
to new Set()
if null on instantiation.
addon/classes/sampler.js:141
private _setGainAndPan( ): Sound
Applies the gain
and pan
properties from the Sampler instance to a
Sound instance and returns the Sound instance.
Return:
The input sound after having it's gain and pan set