class

Tryst::SDL::Sound

Inherits Tryst::SDL::AudioSource < Reference < Object

A sound effect: a short clip, decoded up front, played over and over and freely overlapping with itself.

click = Tryst::SDL::Sound.new("click.wav")
click.play # as many times as you like, all at once

The mixer argument is what to pass when an application holds its own; left out, the sound attaches to Mixer.default, which opens a device on first use.

Constructors

new(path : String, mixer : Mixer = Mixer.default)
Source

Instance methods

destroy

Frees the pooled tracks before the audio they point at.

Source
play(gain : Float32 | Float64 | Nil = nil) : Nil

Plays the sound and forgets about it. Overlaps freely and there is nothing to clean up afterwards.

gain scales this one playing: 1.0 unchanged, 0.0 silent, above 1.0 louder. Left out, SDL's own fire-and-forget path handles it, which allocates nothing and reuses SDL's internal track pool.

Given a gain, a Track is needed - MIX_PlayAudio takes no options at all - so this keeps a small pool of its own and reuses whichever tracks have finished. The pool grows only to the number of copies that overlap at once, and goes away with #destroy.

Either way there is no handle, so a sound started here cannot be stopped, paused or faded. #play_track is for when it must be, and for looping - a loop with no handle would be unstoppable.

Source
play_track(loops : Int32 = 0, fade_ms : Int32 = 0, gain : Float32 | Float64 | Nil = nil) : Track

Plays the sound on a Track and hands it back, for when the caller needs to stop it, fade it, pause it or set its gain.

The caller owns the returned Track and should #destroy it when finished - unlike #play, nothing reclaims it automatically. loops counts EXTRA passes: 0 plays once, -1 repeats forever.

Source