module
Eagle::Audio
Overview
The mixer: global volume, named buses, and the list of playing voices.
Eagle mixes audio in Crystal and sends it to the device, SDL on desktop and WebAudio in the browser. Browsers only allow sound after the first click or key press.
Buses group voices so players can set music and effects volume separately:
Audio.bus("music").volume = 0.5
Audio.bus("sfx").muted = true
Audio.volume = 0.8 # master volume, applies to everything
Audio.stop_all
Defined in:
eagle/audio/audio.crConstant Summary
-
SAMPLE_RATE =
48000 -
Output sample rate requested from the device.
-
TARGET_LATENCY =
0.06 -
Seconds of audio kept queued ahead of the device. Lower means more responsive sound but a higher risk of crackles.
Class Method Summary
-
.add_stream(s : AudioStream) : AudioStream
Starts mixing a stream.
-
.bus(name : String) : Bus
The bus called name, created on first use.
-
.enabled? : Bool
True when an audio device is open.
-
.init(platform : Platform::Base) : Nil
Opens the audio device.
-
.master : Bus
The master bus.
-
.max_voices=(n : Int32)
Caps simultaneous voices (64 by default).
-
.play(sound : Sound, volume : Number = 1, pitch : Number = 1, pan : Number = 0, loop : Bool = false, bus : String = "master") : Voice
Plays a sound and returns its voice.
-
.remove_stream(s : AudioStream) : Nil
Stops mixing a stream.
-
.render(frames : Int32) : Slice(Float32)
Mixes frames stereo frames and returns them, without touching the device.
-
.sample_rate : Int32
The actual output sample rate.
-
.shutdown : Nil
Closes the audio device.
-
.stop_all : Nil
Stops every voice and stream.
-
.voice_count : Int32
Number of voices currently playing.
-
.voices : Array(Voice)
Every voice currently playing.
-
.volume : Float32
Master volume.
-
.volume=(v : Number)
Sets the master volume.
Class Method Detail
The bus called name, created on first use. The default bus is "master".
Opens the audio device. Eagle.run calls this unless Config#audio is false.
Caps simultaneous voices (64 by default). When full, the oldest non-looping voice is cut off, so rapid-fire effects can't drown out music.
Plays a sound and returns its voice. Same as Sound#play.
Mixes frames stereo frames and returns them, without touching the device. Used by tests.