Legacy:Functions/Sounds

From Spherical
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Sounds

  • Sphere Sound object: Holds a sound or piece of music that can be played.
  • Sphere SoundEffect object: Holds a sound that can be played. This powerful object is designed mainly for sound effects.
  • LoadSound(filename [, streaming]): Load a sound from filename, streaming from disk optional.

Sound object

  • Sound.getVolume(): Get the volume of the sound (0-255). No effect on MIDIs.
  • Sound.setVolume(volume): Set the volume of the sound (0-255). No effect on MIDIs.
  • Sound.setPan(pan): Pan can be from -255 to 255. -255 = left, 255 = right. No effect on MIDIs.
  • Sound.getPan(): Returns the current pan of the sound. No effect on MIDIs.
  • Sound.setPitch(pitch): Sets the pitch for a sound. No effect on MIDIs.
  • Sound.getPitch(): Returns the current pitch. No effect on MIDIs.

Sound Effect object

  • Sphere SoundEffect object
  • LoadSoundEffect(filename [, type]): returns a SoundEffect object from 'filename'. If Sphere is unable to open the file, the engine will give an error message and exit. There are two types of sound effects: SE_SINGLE and SE_MULTIPLE.
    • SE_SINGLE sound effects only allow the sound to be played once at a time.
    • SE_MULTIPLE sound effects always open a new stream to the audio device for each time it is played (cleaning up or reusing old streams if possible).
  • SoundEffect.play(): plays the sound effect.
    • If the sound effect is of type SE_SINGLE, this plays the sound if it isn't playing yet, and starts it again if it is.
    • If the sound effect is of type SE_MULTIPLE, play() simply starts playing the sound again.
  • SoundEffect.stop(): stops playback
    • If the sound is of type SE_SINGLE, stop the sound.
    • If it is of type SE_MULTIPLE, stop all playing instances of the sound.
  • SoundEffect.setVolume(volume): sets the volume for the sound effect (0-255)
  • SoundEffect.getVolume(): returns the sound effect's volume (0-255)
  • SoundEffect.setPan(pan): pan ranges from -255 to 255. -255 = left, 255 = right. pan defaults to 0 (center).
  • SoundEffect.getPan(): returns the current pan of the sound effect
  • SoundEffect.setPitch(pitch): pitch ranges from 0.5 to 2.0. 0.5 is an octave down (and half as fast) while 2.0 is an octave up (and twice as fast). pitch defaults to 1.0
  • SoundEffect.getPitch(): returns the current pitch