class Eagle::Voice

Overview

One playing instance of a Sound. Keep it to change volume, pitch or pan while it plays, to fade it, or to stop it.

engine = Sound.tone(110, 1.0, Sound::Wave::Saw).play(loop: true, volume: 0.2)
speed = 0.5
engine.pitch = 0.8 + speed * 0.8 # rev up with speed
engine.fade(0, 0.5)

Defined in:

eagle/audio/audio.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(sound : Eagle::Sound, volume : Number, pitch : Number, pan : Number, loop : Bool, bus : String = "master") #

Creates a voice. Use Sound#play or Audio.play instead, which also start it.


Instance Method Detail

def bus : String #

The bus this voice mixes into. See Audio.bus.


def bus=(bus : String) #

The bus this voice mixes into. See Audio.bus.


def emit_finished(*args) : Nil #

Emitted when the voice reaches the end of a non-looping sound.


def fade(to : Number, seconds : Number) : Nil #

Ramps the volume to to over seconds. A fade to 0 is the smooth way to stop music.


def finished : Eagle::Emitter() #

Emitted when the voice reaches the end of a non-looping sound.


def finished? : Bool #

True once the voice reached the end or was stopped. A finished voice can't be resumed.


def loop=(loop : Bool) #

Whether playback restarts at the end.


def loop? : Bool #

Whether playback restarts at the end.


def on_finished(&block : -> Nil) : Proc(Nil) #

Emitted when the voice reaches the end of a non-looping sound.


def pan : Float32 #

Stereo position from -1 (left) to 1 (right).


def pan=(pan : Float32) #

Stereo position from -1 (left) to 1 (right).


def pan=(v : Number) #

Sets #pan from any number.


def pause : Nil #

Pauses playback. Call #resume to continue from the same spot.


def pitch : Float32 #

Playback speed: 1 is normal, 2 is an octave up.


def pitch=(pitch : Float32) #

Playback speed: 1 is normal, 2 is an octave up.


def pitch=(v : Number) #

Sets #pitch from any number.


def playing? : Bool #

True while the voice is producing sound. False when paused or finished.


def position : Float32 #

Playback position in seconds.


def position=(seconds : Number) #

Seeks to seconds.


def resume : Nil #

Continues after #pause.


def sound : Sound #

The sound being played.


def stop : Nil #

Stops playback for good.


def volume : Float32 #

Volume from 0 to 1. Values above 1 amplify.


def volume=(volume : Float32) #

Volume from 0 to 1. Values above 1 amplify.


def volume=(v : Number) #

Sets #volume from any number.