From 55f9ce35f4b1eb6304c63e746ea5c5696742fc63 Mon Sep 17 00:00:00 2001 From: Alex Clink Date: Sat, 19 Feb 2022 22:58:43 -0500 Subject: [PATCH] Add volume --- src/audio/sound.cr | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/audio/sound.cr b/src/audio/sound.cr index e4f99d5..4cb3253 100644 --- a/src/audio/sound.cr +++ b/src/audio/sound.cr @@ -60,13 +60,15 @@ module PF property started_at : Float64 property wave : Wave property released_at : Float64? = nil + property volume : Float64 = 1.0 - def initialize(@hertz, @envelope, @started_at, @wave = Sound.sin_wave) + def initialize(@hertz, @envelope, @started_at, @volume = 1.0, @wave = Sound.sin_wave) end def sample(time : Float64) @wave.call(time - @started_at, @hertz) * - @envelope.amplitude(time, @started_at, @released_at) + @envelope.amplitude(time, @started_at, @released_at) * + @volume end def release!(time : Float64)