#include "./sound.txt"
#include "./music.txt"

let soundObj = [];
let musicObj = [];
	
task TSound(num,vol)
	{
	ObjSound_SetSoundDivision(soundObj[num], SOUND_SE);
	ObjSound_SetVolumeRate(soundObj[num],vol);
	ObjSound_Play(soundObj[num]);
	}

task TSoundStop(numb)
	{
	ObjSound_Stop(soundObj[numb]);
	}

task TMusic(num)
	{
	ObjSound_SetSoundDivision(musicObj[num], SOUND_BGM);
	ObjSound_Play(musicObj[num]);
	}
task TMusicStop(num)
	{
	ObjSound_SetRestartEnable(musicObj[num],false);
	ObjSound_Stop(musicObj[num]);
	}
task TMusicVol(num,vol)
	{
	ObjSound_SetVolumeRate(musicObj[num],vol);
	}
task TMusicFade(num,time)
	{
	descent(t in 0..time)
		{
		ObjSound_SetVolumeRate(musicObj[num],t*100/time);
		yield;
		}
	TMusicStop(num);
	ObjSound_SetVolumeRate(musicObj[num],100);
	}
task TMusicPause(num)
	{
	ObjSound_SetRestartEnable(musicObj[num],true);
	ObjSound_Stop(musicObj[num]);
	}
task TMusicResume(num)
	{
	ObjSound_Play(musicObj[num]);
	ObjSound_SetRestartEnable(musicObj[num],false);
	}

function InitializeSound
	{
	ascent(i in 0..26)
		{
		soundObj = soundObj ~ [ObjSound_Create];
		let path = GetCurrentScriptDirectory ~ "./se/" ~ ToString(SENumbToName(i)) ~ ".wav";
		ObjSound_Load(soundObj[i],path);	
		}
	}

function InitializeMusic
	{
	ascent(i in 0..4)
		{
		musicObj = musicObj ~ [ObjSound_Create];
		let path = GetCurrentScriptDirectory ~ "./bgm/bgm_" ~ IntToString(i+1) ~ ".ogg";
		ObjSound_Load(musicObj[i],path);

		ObjSound_SetRestartEnable(musicObj[i],false);
		ObjSound_SetLoopEnable(musicObj[i],true);
		let time = GetBGMLoopTime(i);
		ObjSound_SetLoopTime(musicObj[i],time[0],time[1]);
		ObjSound_SetVolumeRate(musicObj[i],100);
		}
	}