TonePlayer

sound TonePlayer

This class handles the playing of tones.

Constructor

new TonePlayer(options)

Source:

This class handles the playing of tones.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
psychoJS module:core.PsychoJS

the PsychoJS instance

secs number <optional>
0.5

duration of the tone (in seconds). If secs == -1, the sound will play indefinitely.

note string | number <optional>
'C4'

note (if string) or frequency (if number)

volume number <optional>
1.0

volume of the tone (must be between 0 and 1.0)

loops number <optional>
0

how many times to repeat the tone after it has played once. If loops == -1, the tone will repeat indefinitely until stopped.

Extends

Members

(static) SoundLibrary :Object

Source:
Type:
  • Object

Methods

(static) accept(value, octave) → {Object|boolean}

Source:

Determine whether this player can play the given sound.

Note: if TonePlayer accepts the sound but Tone.js is not available, e.g. if the browser is IE11, we throw an exception.

Parameters:
Name Type Description
value string | number

potential frequency or note

octave number

the octave corresponding to the tone

Returns:

argument needed to instantiate a TonePlayer that can play the given sound or false otherwise

Type
Object | boolean

(protected) _initSoundLibrary()

Source:

Initialise the sound library.

Note: if TonePlayer accepts the sound but Tone.js is not available, e.g. if the browser is IE11, we throw an exception.

getDuration() → {number}

Source:
Overrides:

Get the duration of the sound.

Returns:

the duration of the sound, in seconds

Type
number

play(loopsopt)

Source:
Overrides:

Start playing the sound.

Parameters:
Name Type Attributes Description
loops boolean <optional>

how many times to repeat the sound after it has played once. If loops == -1, the sound will repeat indefinitely until stopped.

setDuration(secs)

Source:
Overrides:

Set the duration of the tone.

Parameters:
Name Type Description
secs number

the duration of the tone (in seconds) If secs == -1, the sound will play indefinitely.

setLoops(loops)

Source:
Overrides:

Set the number of loops.

Parameters:
Name Type Description
loops number

how many times to repeat the track after it has played once. If loops == -1, the track will repeat indefinitely until stopped.

setTone(value, octave)

Source:

Set the note for tone.

Parameters:
Name Type Default Description
value string | number C

potential frequency or note

octave number 4

the octave corresponding to the tone

setVolume(volume, muteopt)

Source:
Overrides:

Set the volume of the tone.

Parameters:
Name Type Attributes Default Description
volume Integer

the volume of the tone

mute boolean <optional>
false

whether or not to mute the tone

stop()

Source:
Overrides:

Stop playing the sound immediately.