function bgm_play(_key)
{
	if !global.audio_enabled
		return;
		
    var _mus = oAudioManager.bgm_map[$ _key];
    if _mus == undefined exit;
    
    if audio_is_playing(oAudioManager.bgm_current)
        audio_sound_gain(oAudioManager.bgm_current, 0, 1000);
    
    oAudioManager.bgm_next = _mus;
    oAudioManager.bgm_fade_timer = 60;
}

function bgm_stop()
{
	if !global.audio_enabled
		return;

    audio_stop_sound(oAudioManager.bgm_current);
    oAudioManager.bgm_current = noone;
}

function sfx_play(_key, _pitch_vary = 0.1, _vol_vary = 0.1)
{
	if !global.audio_enabled
		return;
	
    var _sfx = oAudioManager.sfx_map[$ _key];
    var _inst = audio_play_sound(_sfx, 1, false);
    
    var _pitch = 1.0 + (random(_pitch_vary * 2) - _pitch_vary);
    var _vol = oAudioManager.sfx_volume * (1.0 - random(_vol_vary));
    
    audio_sound_pitch(_inst, _pitch);
    audio_sound_gain(_inst, _vol, 0);
    return _inst;
}
function sfx_heartbeat_play()
{
	if !global.audio_enabled
		return;
		
	var _threshold = 2;
	if global.playerHP <= _threshold
	{
	    var _vol = 1// - (global.playerHP / _threshold) * 0.5;
	    audio_sound_gain(heartbeat_sound, _vol, 100);
    
	    var _bgm_vol = oAudioManager.bgm_volume * (1 - _vol * 0.7);
	    audio_sound_gain(oAudioManager.bgm_current, _bgm_vol, 100);
	}
	else
	{
	    audio_sound_gain(heartbeat_sound, 0, 200);
	    audio_sound_gain(oAudioManager.bgm_current, oAudioManager.bgm_volume, 200); // 恢复
	}
}