Class OcsfmlAudio.sound

class sound : ?pitch:float -> ?volume:float -> ?position:float * float * float -> ?relative_to_listener:bool -> ?min_distance:float -> ?attenuation:float -> ?loop:bool -> ?buffer:sound_buffer -> ?playing_offset:OcsfmlSystem.Time.t -> unit -> object .. end
Regular sound that can be played in the audio environment.

OcsfmlAudio.sound is the class to use to play sounds.

It provides:

OcsfmlAudio.sound is perfect for playing short sounds that can fit in memory and require no latency, like foot steps or gun shots. For longer sounds, like background musics or long speeches, rather see (which is based on streaming).

In order to work, a sound must be given a buffer of audio data to play. Audio data (samples) is stored in OcsfmlAudio.sound_buffer, and attached to a sound with the set_buffer function. The buffer object attached to a sound must remain alive as long as the sound uses it. Note that multiple sounds can use the same sound buffer at the same time.

Usage example:

    let buffer = new buffer in
    buffer#load_from_file "sound.wav" ;
    let sound = new sound in
    sound#set_buffer buffer ;
    sound#play ;

method destroy : unit
method get_buffer : const_sound_buffer reference
Get the audio buffer attached to the sound.
Returns Sound buffer attached to the sound
method get_loop : bool
Tell whether or not the sound is in loop mode.
Returns True if the sound is looping, false otherwise
method get_playing_offset : OcsfmlSystem.Time.t
Get the current playing position of the sound.
Returns Current playing position, from the beginning of the sound
method get_status : status
Get the current status of the sound (stopped, paused, playing)
Returns Current status of the sound
method pause : unit
Pause the sound.

This function pauses the sound if it was playing, otherwise (sound already paused or stopped) it has no effect.

method play : unit
Start or resume playing the sound.

This function starts the stream if it was stopped, resumes it if it was paused, and restarts it from beginning if it was it already playing. This function uses its own thread so that it doesn't block the rest of the program while the sound is played.

method set_buffer : sound_buffer -> unit
Set the source buffer containing the audio data to play.

It is important to note that the sound buffer is not copied, thus the sf::SoundBuffer instance must remain alive as long as it is attached to the sound.

method set_loop : bool -> unit
Set whether or not the sound should loop after reaching the end.

If set, the sound will restart from beginning after reaching the end and so on, until it is stopped or setLoop(false) is called. The default looping state for sound is false.

method set_playing_offset : OcsfmlSystem.Time.t -> unit
Change the current playing position of the sound.

The playing position can be changed when the sound is either paused or playing.

method stop : unit
Stop playing the sound.

This function stops the sound if it was playing or paused, and does nothing if it was already stopped. It also resets the playing position (unlike pause).