funfriend/src/soundman.cr

26 lines
598 B
Crystal
Raw Normal View History

2023-05-31 12:14:38 +02:00
require "sdl"
require "sdl/mix"
module Funfriend::SoundMan
extend self
@@sounds = Hash(String, SDL::Mix::Sample).new
def play_sound(filepath : String)
if !@@sounds.has_key?(filepath)
sound = SDL::Mix::Sample.new(filepath)
@@sounds[filepath] = sound
end
SDL::Mix::Channel.play(@@sounds[filepath])
end
def init
SDL.init(SDL::Init::AUDIO); at_exit { SDL.quit }
SDL::Mix.init(SDL::Mix::Init::OGG); at_exit { SDL::Mix.quit }
SDL::Mix.open
2023-06-01 15:36:10 +02:00
SDL::Mix::Channel.volume = SDL::Mix::MAX_VOLUME * ConfigMan.config["sound"]["volume"].as(Float64)
2023-05-31 12:14:38 +02:00
end
end