Libraries.Robots.Spike.Sound Documentation

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.

Example Code

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

Inherits from: Libraries.Language.Object

Variables Table

VariablesDescription
integer DEFAULT
integer WAVEFORM_SINE
integer ANY
integer WAVEFORM_SAWTOOTH
integer WAVEFORM_TRIANGLEPlays a sound from the hub utilizing frequency, duration, and the volume provided. Currently only capable of playing a sine wave with the provided parameters.
integer WAVEFORM_SQUARE

Actions Documentation

Beep(integer frequency, integer duration, integer volume)

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

  • integer frequency: The frequency in hertz of the sound
  • integer duration: The duration in milliseconds of the sound
  • integer volume: The volume intensity of the sound from 0 to 100 Attribtue: Example 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)

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

Parameters

  • integer frequency: The frequency in hertz of the sound
  • integer duration: The duration in milliseconds of the sound
  • integer volume: The volume intensity of the sound from 0 to 100
  • integer attack: The time in milliseconds between the start of the sound to the peak
  • integer decay: The time in milliseconds between the peak volume to sustain volume
  • integer sustain: The volume intensity of the sustain of the sound between 0 and 100 until the sound is released
  • integer release: The time in milliseconds for the volume intensity to decay to 0 from release time
  • integer transition: The time in milliseconds for the sound to transition from the currently playing sound
  • integer waveform: The waveform to use to play the sound, using one of the constants defined in the Sound class
  • integer channel: The channel to play on, either DEFAULT or ANY from the constants defined in the Sound class

Example

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

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

SetVolume(integer vol)

Sets the volume of the noise coming from the hub

Parameters

  • integer vol: The volume intensity of the sound from 0 to 100

Example

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)

StopSound()

Stops all sound coming from the hub

Example

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