abstract class
Eagle::AudioStream
- Eagle::AudioStream
- Reference
- Object
Overview
Audio you generate on the fly, a block of samples at a time: synthesizers, engine hum, procedural music.
Subclass it, implement #fill, and register it with Audio.add_stream.
class Hum < AudioStream
@phase = 0.0
def fill(buf : Slice(Float32), frames : Int32, sample_rate : Int32) : Nil
frames.times do |i|
s = (Math.sin(@phase) * 0.2).to_f32
buf[i * 2] = s # left
buf[i * 2 + 1] = s # right
@phase += Math::TAU * 60 / sample_rate
end
end
end
Audio.add_stream(Hum.new)
Defined in:
eagle/audio/audio.crInstance Method Summary
-
#fill(buf : Slice(Float32), frames : Int32, sample_rate : Int32) : Nil
Writes frames stereo frames of interleaved samples into buf.
-
#playing? : Bool
False after
#stop. -
#stop : Nil
Stops the stream.
-
#volume : Float32
Volume applied to what
#fillwrites. -
#volume=(volume : Float32)
Volume applied to what
#fillwrites.
Instance Method Detail
abstract
def fill(buf : Slice(Float32), frames : Int32, sample_rate : Int32) : Nil
#
Writes frames stereo frames of interleaved samples into buf. It runs on the main thread once per frame, so keep it fast.