/******************************************************************************
*******************************************************************************

	Space Impakto DS
	relminator
	http://rel.betterwebber.com


	Csound class


*******************************************************************************
******************************************************************************/

#include <nds.h>
#include <maxmod9.h>

#include "Csound.h"

Csound::Csound()
{

	num_bgm = 0;
	num_sfx = 0;
	playmode = E_BGM_NORMAL;
	
	volume = 1024 << 12;
	fade_steps = 1024;
	step_inc = 	0;
	
}


#ifndef NO_SOUND

void Csound::set_BGM_mode( E_BGM_MODE mode )
{
	playmode = mode;
	
	switch (playmode)
	{
		case E_BGM_NORMAL:
			step_inc = 0;
			break;
		case E_BGM_FADE_OUT:
			step_inc = 	-divf32(1024 << 12, fade_steps << 12);
			break;
		case E_BGM_FADE_IN:
			step_inc = 	divf32(1024 << 12, fade_steps << 12);
			break;
		default:
			step_inc = 0;
	}
}

void Csound::load_BGM( mm_word module_ID )
{
	
	if (num_bgm < E_BGM_MAX)
	{	
		mmLoad( module_ID );
		BGM_ID[num_bgm] = module_ID;
		num_bgm++;
	}
	
}

void Csound::load_SFX( mm_word sample_ID )
{

	if (num_sfx < E_SFX_MAX)
	{
		mmLoadEffect( sample_ID );
		SFX_ID[num_sfx] = sample_ID;
		
		sfx[num_sfx].id      = sample_ID; 	// sample ID (make sure it is loaded)
		sfx[num_sfx].rate    = 1024;     	// playback rate, 1024 = original sound
		sfx[num_sfx].handle  = 0;           // 0 = allocate new handle
		sfx[num_sfx].volume  = 255;         // volume level
		sfx[num_sfx].panning = 128;     	// panning at center
		
		num_sfx++;
	}
	
}

void Csound::unload_BGM( mm_word module_ID )
{
	mmUnload( module_ID );
}

#else

void Csound::set_BGM_mode( E_BGM_MODE mode )
{
}

void Csound::load_BGM( mm_word module_ID )
{
}

void Csound::load_SFX( mm_word sample_ID )
{
}

void Csound::unload_BGM( mm_word module_ID )
{
}

#endif
