Constructor
new Sound(options)
- Source:
Example
[...]
const track = new Sound({
win: psychoJS.window,
value: 440,
secs: 0.5
});
track.setVolume(1.0);
track.play(2);
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
Extends
- PsychObject
Methods
(protected) _getPlayer() → {SoundPlayer}
- Source:
Identify the appropriate player for the sound.
Throws:
-
exception if no appropriate SoundPlayer could be found for the sound
- Type
- Object.<string, *>
Returns:
the appropriate SoundPlayer
- Type
- SoundPlayer
getDuration() → {number}
- Source:
Get the duration of the sound, in seconds.
Returns:
the duration of the sound, in seconds
- Type
- number
play(loops, logopt)
- Source:
Start playing the sound.
Note: Sounds are played independently from the stimuli of the experiments, i.e. the experiment will not stop until the sound is finished playing. Repeat calls to play may results in the sounds being played on top of each other.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
loops |
number | how many times to repeat the sound after it plays once. If loops == -1, the sound will repeat indefinitely until stopped. |
||
log |
boolean |
<optional> |
true
|
whether or not to log |
setLoops(loopsopt, logopt)
- Source:
Set the number of loops.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
loops |
number |
<optional> |
0
|
how many times to repeat the sound after it has played once. If loops == -1, the sound will repeat indefinitely until stopped. |
log |
boolean |
<optional> |
true
|
whether of not to log |
setSecs(secsopt, logopt)
- Source:
Set the duration (in seconds)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
secs |
number |
<optional> |
0.5
|
duration of the tone (in seconds) If secs == -1, the sound will play indefinitely. |
log |
boolean |
<optional> |
true
|
whether or not to log |
setSound(sound, logopt)
- Source:
Set the sound value on demand past initialisation.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sound |
object | a sound instance to replace the current one |
||
log |
boolean |
<optional> |
true
|
whether or not to log |
setVolume(volume, muteopt, logopt)
- Source:
Set the playing volume of the sound.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
volume |
number | the volume (values should be between 0 and 1) |
||
mute |
boolean |
<optional> |
false
|
whether or not to mute the sound |
log |
boolean |
<optional> |
true
|
whether of not to log |
stop(options)
- Source:
Stop playing the sound immediately.
Parameters:
Name | Type | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|