Sound

The sound library is capable of playing sounds from the speaker embedded in the Spike hub. It's basic functionalities include playing a sound, stopping sound, and changing the volume of a sound.

Constants

  1. ANY=-2
  2. DEFAULT=-1
  3. WAVEFORM_SINE=1
  4. WAVEFORM_SAWTOOTH=3
  5. WAVEFORM_SQUARE=2
  6. WAVEFORM_TRIANGLE=1

Beep(integer frequency, integer duration, integer volume)

Returns

None
Plays a sound from the hub utilizing frequency, duration, and the volume provided. Currently only capable of playing a sine wave with the provided parameters.

Parameters

  1. 1.integerfrequency

    The frequency in hertz of the sound

  2. 2.integerduration

    The duration in milliseconds of the sound

  3. 3.integervolume

    The volume intensity of the sound from 0 to 100

Example

1 2 3 use Libraries.Robots.Spike.Sound Sound noise noise:Beep(440, 500, 100)

Beep(integer frequency, integer duration, integer volume, integer attack, integer decay, integer sustain, integer release, integer transition, integer waveform, integer channel)

Returns

None
Plays a sound from the hub utilizing frequency, duration, volume, attack, decay, sustain, release, transition, waveform, and channel arguments.

Parameters

  1. 1.integerfrequency

    The frequency in hertz of the sound

  2. 2.integerduration

    The duration in milliseconds of the sound

  3. 3.integervolume

    The volume intensity of the sound from 0 to 100

  4. 4.integerattack

    The time in milliseconds between the start of the sound to the peak

  5. 5.integerdecay

    The time in milliseconds between the peak volume to sustain volume

  6. 6.integersustain

    The volume intensity of the sustain of the sound between 0 and 100 until the sound is released

  7. 7.integerrelease

    The time in milliseconds for the volume intensity to decay to 0 from release time

  8. 8.integertransition

    The time in milliseconds for the sound to transition from the currently playing sound

  9. 9.integerwaveform

    The waveform to use to play the sound, using one of the constants defined in the Sound class

  10. 10.integerchannel

    The channel to play on, either DEFAULT or ANY from the constants defined in the Sound class

Example

1 2 3 use Libraries.Robots.Spike.Sound Sound noise noise:Beep(440, 500, 100, 120, 50, 50, 60, 10, noise:WAVEFORM_SQUARE, noise:DEFAULT)

StopSound()

Returns

None
Stops all sound coming from the hub

Parameters

  1. 1.integervol

    The volume intensity of the sound from 0 to 100

Example

1 2 3 4 use Libraries.Robots.Spike.Sound Sound noise noise:Beep(440, 5000, 100) noise:Stop()

SetVolume(integer vol)

Returns

None
Sets the volume of the noise coming from the hub

Parameters

None

Example

1 2 3 4 5 6 7 use Libraries.Robots.Spike.Sound use Libraries.Robots.Spike.Hub Sound noise Hub hb noise:Beep(440, 5000, 100) hb:Sleep(1000) noise:SetVolume(25)