www.pudn.com > ncdzsrc.rar > sndintrf.c


/*************************************************************************** 
 
	sndintrf.c 
 
	サウンドインタフェース 
 
***************************************************************************/ 
 
#include "neogeocd.h" 
 
 
/**************************************************************************** 
	グローバル変数 
 ***************************************************************************/ 
 
int sample_rate; 
 
 
/**************************************************************************** 
	ローカル変数 
 ***************************************************************************/ 
 
static void *sound_update_timer = NULL; 
static double refresh_period; 
static double refresh_period_inv; 
 
static int cleared_value = 0x00; 
static int latch = 0x00; 
 
 
/*************************************************************************** 
	グローバル関数 
 ***************************************************************************/ 
 
/*-------------------------------------------------------- 
 
	サウンド再生処理を初期化 
 
	引  数: なし 
	戻り値: 1:成功  0:失敗 
 
 -------------------------------------------------------*/ 
 
int sound_init(void) 
{ 
	sample_rate = options.samplerate; 
 
	refresh_period = TIME_IN_HZ(video_fps); 
	refresh_period_inv = 1.0 / refresh_period; 
	sound_update_timer = timer_alloc(NULL); 
 
	if (streams_sh_start() != 0) 
		return 0; 
 
	if (YM2610_sh_start() != 0) 
		return 0; 
 
	return 1; 
} 
 
 
/*-------------------------------------------------------- 
 
	サウンド再生処理を終了 
 
	引  数: なし 
	戻り値: なし 
 
 -------------------------------------------------------*/ 
 
void sound_shutdown(void) 
{ 
	YM2610_sh_stop(); 
	streams_sh_stop(); 
} 
 
 
/*-------------------------------------------------------- 
 
	サウンドを更新 
 
	引  数: なし 
	戻り値: なし 
 
 -------------------------------------------------------*/ 
 
void sound_update(void) 
{ 
	if (sample_rate) 
	{ 
		if (cdrom_loading_state != CDROM_IDLE) 
			stream_update(1000000 / (sample_rate * video_fps)); 
		streams_sh_update(); 
		timer_adjust(sound_update_timer, TIME_NEVER, 0, 0); 
	} 
} 
 
 
/*-------------------------------------------------------- 
 
	サウンドをリセット 
 
	引  数: なし 
	戻り値: なし 
 
 -------------------------------------------------------*/ 
 
void sound_reset(void) 
{ 
	if (sample_rate) 
		YM2610_sh_reset(); 
} 
 
 
/*-------------------------------------------------------- 
 
	サウンドのバッファ内の現在位置を取得 
 
	引  数: int value 
	戻り値: 現在の位置 
 
 -------------------------------------------------------*/ 
 
int sound_scalebufferpos(int value) 
{ 
	int result = (int)((double)value * timer_timeelapsed(sound_update_timer) * refresh_period_inv); 
 
	if (value >= 0) 
		return (result < value) ? result : value; 
	else 
		return (result > value) ? result : value; 
} 
 
 
/*-------------------------------------------------------- 
 
	サウンド再生のデータの書き込み 
 
	引  数: offs_t offset  オフセット(未使用) 
	        UINT8 data     データ(サウンド番号等) 
	戻り値: なし 
 
 -------------------------------------------------------*/ 
 
WRITE8_HANDLER( soundlatch_w ) 
{ 
	latch = data; 
} 
 
 
/*-------------------------------------------------------- 
 
	サウンド再生のデータの読み込み 
 
	引  数: offs_t offset  オフセット(未使用) 
	戻り値: 再生待ちのデータ 
 
 -------------------------------------------------------*/ 
 
READ8_HANDLER( soundlatch_r ) 
{ 
	return latch; 
} 
 
 
/*-------------------------------------------------------- 
 
	サウンド再生のデータのクリア 
 
	引  数: offs_t offset  オフセット(未使用) 
	        UINT8 data     データ(サウンドクリア値) 
	戻り値: なし 
 
 -------------------------------------------------------*/ 
 
WRITE8_HANDLER( soundlatch_clear_w ) 
{ 
	latch = cleared_value; 
} 
 
 
/*-------------------------------------------------------- 
 
	サウンド再生のデータのクリア値を設定 
 
	引  数: int value    データのクリアに使用する値 
	戻り値: なし 
 
 -------------------------------------------------------*/ 
 
void soundlatch_setclearedvalue(int value) 
{ 
	cleared_value = value; 
}