/*******************************************************************/
/* 効果音の演奏部 (se.h)                                           */
/* void init_sound(void):サウンド部の初期化                        */
/* void sound_on(int type):効果音の発生                            */
/* void sound_off(void):効果音の消去                               */
/*******************************************************************/

#ifndef _SE_H_
#define _SE_H_

#include <sys/bios.h>


/* 効果音の種類 */
#define MOVE_SOUND 0
#define CATCH_SOUND 1
#define MISS_SOUND 2
#define ALARM_SOUND 3

/* 効果音の周波数 */
/* (sound_set_pitchに設定する値) */
#define MOVE_FREQ 2002
#define CATCH_FREQ 1681
#define MISS_FREQ 1681
#define ALARM_FREQ 1975


/************************/
/* サウンドを初期化する */
/************************/
void init_sound(void)
{
	sound_init();
	sound_set_channel(1);

	/* ヘッドフォンが接続されていれば */
	/* ヘッドフォンのみに音を出力する */
	if (sound_get_output() & 0x80) sound_set_output(0x08);
	else sound_set_output(0x07);
}


/**********************/
/* 効果音を発生させる */
/* int type:音の種類  */
/**********************/
void sound_on(int type)
{
	/* 効果音の波形 */
	/* wave[x][16]のx */
	/* 0:風船の移動音 */
	/* 1:風船のキャッチ音、ミス音兼用 */
	/* 2:アラーム音 */
	static unsigned char wave[3][16] =
	 {{0xff, 0x88, 0x00, 0x88, 0xff, 0x88, 0x00, 0x88,
	   0xff, 0x88, 0x00, 0x88, 0xff, 0x88, 0x00, 0x88},
	  {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
	   0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00},
	  {0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe,
	   0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01}};

	switch (type)
	{

	/* 風船の移動音 */
	case MOVE_SOUND:
		sound_set_wave(0, wave[0]);
		sound_set_pitch(0, MOVE_FREQ);
		break;

	/* 風船のキャッチ音、ミス音 */
	case CATCH_SOUND:
	case MISS_SOUND:
		sound_set_wave(0, wave[1]);
		sound_set_pitch(0, CATCH_FREQ);
		break;

	/* アラーム音 */
	case ALARM_SOUND:
		sound_set_wave(0, wave[2]);
		sound_set_pitch(0, ALARM_FREQ);
		break;
	}
	sound_set_volume(0, 0xff);
}


/**************************/
/* 効果音の発生を中止する */
/**************************/
void sound_off(void)
{
	sound_set_volume(0, 0);
}


#endif
