# TonePlayer

## sound TonePlayer

This class handles the playing of tones.

## Constructor

#### new TonePlayer(options)

Source:
  - sound/TonePlayer.js, line 19

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
`duration_s` | number | <optional> | `0.5` | duration of the tone (in seconds). If duration_s == -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

- SoundPlayer

### Members

#### (static) SoundLibrary :Object

Source:
  - sound/TonePlayer.js, line 351

##### Type:

- Object

### Methods

#### (static) accept(sound) → {Object|undefined}

Source:
  - sound/TonePlayer.js, line 72

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
--- | --- | ---
`sound` | module:sound.Sound | the sound

##### Returns:

an instance of TonePlayer that can play the given sound or undefined otherwise

Type
  Object | undefined

#### (protected) _initSoundLibrary()

Source:
  - sound/TonePlayer.js, line 270

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:
  - sound/TonePlayer.js, line 121
Overrides:
  - SoundPlayer#getDuration

Get the duration of the sound.

##### Returns:

the duration of the sound, in seconds

Type
  number

#### play(loopsopt)

Source:
  - sound/TonePlayer.js, line 180
Overrides:
  - SoundPlayer#play

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(duration_s)

Source:
  - sound/TonePlayer.js, line 131
Overrides:
  - SoundPlayer#setDuration

Set the duration of the tone.

##### Parameters:

Name | Type | Description
--- | --- | ---
`duration_s` | number | the duration of the tone (in seconds) If duration_s == -1, the sound will play indefinitely.

#### setLoops(loops)

Source:
  - sound/TonePlayer.js, line 141
Overrides:
  - SoundPlayer#setLoops

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.

#### setVolume(volume, muteopt)

Source:
  - sound/TonePlayer.js, line 152
Overrides:
  - SoundPlayer#setVolume

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:
  - sound/TonePlayer.js, line 242
Overrides:
  - SoundPlayer#stop

Stop playing the sound immediately.