funfriend/src/soundman.cr

26 lines
598 B
Crystal

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
SDL::Mix::Channel.volume = SDL::Mix::MAX_VOLUME * ConfigMan.config["sound"]["volume"].as(Float64)
end
end