⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 masndseq.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
 *																			*
 *		Copyright (C) 2001-2003	YAMAHA CORPORATION. All rights reserved.	*
 *																			*
 *		Module		: masndseq.c											*
 *																			*
 *		Description	: MA Sound Sequencer 									*
 *																			*
 * 		Version		: 1.3.14.0	2003.01.17									*
 *																			*
 ****************************************************************************/

#include "masndseq.h"
#include "macnvprf.h"

extern UINT8 _ma_intstate;

extern void machdep_Sleep( UINT32 sleep_time );

/*--------------------------------------------------------------------------*/

static MASNDSEQINFO ma_sndseq_info;

static const UINT8 ma_seqtype[MASMW_NUM_SRMCNV] = { 0, 0, 1, 1, 2, 0, 0, 1, 2, 0, 1, 2 };

/*--------------------------------------------------------------------------*/

/* dummy functions */

static SINT32 dummy_Init   ( void )
{
	return MASMW_SUCCESS;
}
static SINT32 dummy_Load   ( UINT8 * file_ptr, UINT32 file_size, UINT8 mode, SINT32 (*func)(UINT8 id), void * ext_args )
{
	(void)file_ptr;
	(void)file_size;
	(void)mode;
	(void)func;
	(void)ext_args;
	return MASMW_SUCCESS;
}
static SINT32 dummy_Open   ( SINT32 file_id, UINT16 open_mode, void * ext_args )
{
	(void)file_id;
	(void)open_mode;
	(void)ext_args;
	return 0;
}
static SINT32 dummy_Control( SINT32 file_id, UINT8 ctrl_num, void * prm, void * ext_args )
{
	(void)file_id;
	(void)ctrl_num;
	(void)prm;
	(void)ext_args;
	return MASMW_SUCCESS;
}
static SINT32 dummy_Standby( SINT32 file_id, void * ext_args )
{
	(void)file_id;
	(void)ext_args;
	return MASMW_SUCCESS;
}
static SINT32 dummy_Seek   ( SINT32 file_id, UINT32 pos, UINT8 flag, void * ext_args )
{
	(void)file_id;
	(void)pos;
	(void)flag;
	(void)ext_args;
	return MASMW_SUCCESS;
}
static SINT32 dummy_Start  ( SINT32 file_id, void * ext_args )
{
	(void)file_id;
	(void)ext_args;
	return MASMW_SUCCESS;
}
static SINT32 dummy_Stop   ( SINT32 file_id, void * ext_args )
{
	(void)file_id;
	(void)ext_args;
	return MASMW_SUCCESS;
}
static SINT32 dummy_Close  ( SINT32 file_id, void * ext_args )
{
	(void)file_id;
	(void)ext_args;
	return MASMW_SUCCESS;
}
static SINT32 dummy_Unload ( SINT32 file_id, void * ext_args )
{
	(void)file_id;
	(void)ext_args;
	return MASMW_SUCCESS;
}
static SINT32 dummy_End    ( void )
{
	return MASMW_SUCCESS;
}

/*--------------------------------------------------------------------------*/

/****************************************************************************
 *	MaSound_ReceiveMessage
 *
 *	Function:
 *			Receive the message from MA Sound Driver.
 *	Argument:
 *			id		id number
 *			file_id	file id 
 *			message	message type
 *	Return:
 *			0		success
 *			< 0		error code
 *
 ****************************************************************************/
SINT32 MaSound_ReceiveMessage
(
	SINT32	seq_id,						/* sequence id */
	SINT32	file_id,					/* file id */
	UINT8	message						/* message number */
)
{
	SINT32	func_id;					/* function id */
	SINT32	result;						/* result of function */

	MASNDSEQ_DBGMSG(("MaSndSeq_ReceiveMessage: id=%ld fid=%ld msg=%d\n", seq_id, file_id, message));

	func_id = ma_sndseq_info.func_id[seq_id];
	if ( seq_id != 1 )
		file_id = ma_sndseq_info.file_id[seq_id];

	switch ( message )
	{
	case MASMW_END_OF_DATA:


		if ( ma_sndseq_info.play_mode[seq_id][file_id] == 0xFFFF )
		{
			return MASMW_END_OF_SEQUENCE;
		}

		if ( ma_sndseq_info.play_mode[seq_id][file_id] != 0 )
		{
			ma_sndseq_info.play_mode[seq_id][file_id]--;
			if ( ma_sndseq_info.play_mode[seq_id][file_id] == 0 )
			{
				ma_sndseq_info.play_mode[seq_id][file_id] = 0xFFFF;

				return MASMW_END_OF_SEQUENCE;
			}
		}

		MaSndDrv_ControlSequencer( seq_id, 2 );

		if ( seq_id == 2 )
		{
			result = ma_srmcnv_func[func_id].Stop( file_id, (void *)(-1) );
		}
		else
		{
			result = ma_srmcnv_func[func_id].Stop( file_id, NULL );
		}
		if ( result < MASMW_SUCCESS ) return result;
		
		result = ma_srmcnv_func[func_id].Seek( file_id, ma_sndseq_info.start_point[func_id][file_id], 0, NULL );
		if ( result < MASMW_SUCCESS ) return result;

		result = ma_srmcnv_func[func_id].Start( file_id, ma_sndseq_info.start_extargs[func_id][file_id] );
		if ( result < MASMW_SUCCESS ) return result;

		MaSndDrv_ControlSequencer( seq_id, 3 );

		break;

	case MASMW_END_OF_SEQUENCE:


		if ( ma_sndseq_info.loop_count[seq_id][file_id] == 0xFFFF )
		{
			message = MASMW_END_OF_SEQUENCE;
		}
		else if ( ma_sndseq_info.loop_count[seq_id][file_id] != 0 )
		{
			ma_sndseq_info.loop_count[seq_id][file_id]--;
			if ( ma_sndseq_info.loop_count[seq_id][file_id] == 0 )
			{
				ma_sndseq_info.loop_count[seq_id][file_id] = 0xFFFF;
				ma_sndseq_info.save_mode[seq_id][file_id] = 0xFFFF;

				if ( seq_id == 0 )
				{
					result = ma_srmcnv_func[func_id].Stop( file_id, NULL );
					if ( result < MASMW_SUCCESS ) return result;
				}
				else if ( seq_id == 2 )
				{
					result = ma_srmcnv_func[func_id].Stop( file_id, (void *)(-1) );
					if ( result < MASMW_SUCCESS ) return result;
				}

				ma_sndseq_info.state[func_id][file_id] = MASMW_STATE_READY;

				message = MASMW_END_OF_SEQUENCE;
			}
			else
			{
				ma_sndseq_info.seek_point[func_id][file_id] =
					ma_sndseq_info.start_point[func_id][file_id]
				  + ma_sndseq_info.seek_pos0[func_id][file_id];
				MaSndDrv_UpdatePos( seq_id, 0 );
				message = MASMW_REPEAT;
			}
		}
		else
		{
			ma_sndseq_info.seek_point[func_id][file_id] =
				ma_sndseq_info.start_point[func_id][file_id]
			  + ma_sndseq_info.seek_pos0[func_id][file_id];
			MaSndDrv_UpdatePos( seq_id, 0 );
			message = MASMW_REPEAT;
		}
	
	
	default:

		if ( ma_sndseq_info.clback_func[func_id][file_id] != NULL )
		{
			ma_sndseq_info.clback_func[func_id][file_id]( message );
		}
		break;
	}
	
	return MASMW_SUCCESS;
}
/****************************************************************************
 *	MaSound_Create
 *
 *	Function:
 *			Setting the MA Stream Converter and callback function.
 *	Argument:
 *			cnv_id		ID number of MA Stream Converter
 *	Return:
 *			>= 0		function id of registered MA Stream Converter
 *			< 0			error code
 *
 ****************************************************************************/
SINT32 MaSound_Create
(
	UINT8	cnv_id						/* stream converter id */
)
{
	UINT32	i;							/* loop counter */
	SINT32	result;						/* result of function */

	MASNDSEQ_DBGMSG(("MaSound_Create: cnv_id=%d\n", cnv_id));

	if ( cnv_id >= MASMW_NUM_SRMCNV )
	{
		return MASMW_ERROR;
	}

	if ( ( ma_sndseq_info.srmcnv_map & (UINT32)(1 << cnv_id) ) != 0 )
	{
		return MASMW_ERROR;
	}

	result = ma_srmcnv_func[cnv_id].Init();

	if ( result < MASMW_SUCCESS )
	{
		MASNDSEQ_DBGMSG(("Can't initialize the stream converter\n"));
		return result;
	}

	for ( i = 0; i < MASMW_NUM_FILE; i++ )
	{
		ma_sndseq_info.state[cnv_id][i] = MASMW_STATE_IDLE;
	}

	ma_sndseq_info.srmcnv_map |= (UINT32)(1 << cnv_id);

	return (SINT32)cnv_id;
}
/****************************************************************************
 *	MaSound_Load
 *
 *	Function:
 *			Performs loading processing of Stream Converter.
 *	Arguments:
 *			func_id		function id
 *			file_ptr	pointer to file
 *			file_size	byte size of file
 *			mode		error check mode	0: no check
 *											1: check
 *											2: check only
 *											3: get contents information
 *			func		callback function
 *			ext_args	for future extension
 *	Return:
 *			>= 0		success. file id.
 *			< 0			error code
 *
 ****************************************************************************/
SINT32 MaSound_Load
(
	SINT32	func_id, 					/* function id */
	UINT8 *	file_ptr,					/* pointer to file */
	UINT32	file_size,					/* size of file */
	UINT8	mode,						/* error check mode */
	SINT32	(*func)(UINT8 id),			/* callback function */
	void *	ext_args					/* for future extension */
)
{
	SINT32	result;						/* result of function */
	
	MASNDSEQ_DBGMSG(("MaSound_Load: id=%ld\n", func_id));

	if ( ( ma_sndseq_info.srmcnv_map & (UINT32)(1 << func_id) ) == 0 )
	{
		return MASMW_ERROR;
	}

	result = ma_srmcnv_func[func_id].Load( file_ptr, file_size, mode, func, ext_args );

	if ( result >= MASMW_SUCCESS )
	{
		if ( result == 0 )
		{
			return result;
		}

		ma_sndseq_info.state[func_id][result] = MASMW_STATE_LOADED;

		ma_sndseq_info.clback_func[func_id][result] = func;
	}
	
	return result;
}
/****************************************************************************
 *	MaSound_Open
 *
 *	Function:
 *			Performs opening processing of Stream Converter.
 *	Arguments:
 *			func_id		function id
 *			file_id		file id
 *			open_mode	file open mode
 *			ext_args	for future extension
 *	Return:
 *			0			success
 *			< 0 		error code
 *
 ****************************************************************************/
SINT32 MaSound_Open
(
	SINT32	func_id,					/* function id */
	SINT32	file_id,					/* file id */
	UINT16	open_mode,					/* open mode */
	void *	ext_args					/* for future extension */
)
{
	SINT32	result;						/* result of function */
	SINT32	result2;					/* result of function */
	
	MASNDSEQ_DBGMSG(("MaSound_Open: id=%ld hd=%ld md=%hd\n", func_id, file_id, open_mode));

	if ( ( ma_sndseq_info.srmcnv_map & (UINT32)(1 << func_id) ) == 0 )
	{
		return MASMW_ERROR;
	}

	if ( ma_sndseq_info.state[func_id][file_id] != MASMW_STATE_LOADED )
	{
		return MASMW_ERROR;
	}

	result = ma_srmcnv_func[func_id].Open( file_id, open_mode, ext_args );

	if ( result >= MASMW_SUCCESS )
	{
		result = ma_srmcnv_func[func_id].Control( file_id, MASMW_GET_LENGTH, NULL, NULL );
		if ( result < MASMW_SUCCESS )
		{
			return result;
		}

		result2 = ma_srmcnv_func[func_id].Control( file_id, MASMW_GET_LENGTH, NULL, (void *)(-1) );
		if ( result2 < MASMW_SUCCESS )
		{
			return result2;
		}

		ma_sndseq_info.start_point[func_id][file_id] = 0;
		ma_sndseq_info.end_point[func_id][file_id]   = (UINT32)result;

		ma_sndseq_info.seek_point[func_id][file_id]  = 0;

		ma_sndseq_info.play_length[func_id][file_id] = (UINT32)result;
		ma_sndseq_info.loop_length[func_id][file_id] = (UINT32)result2;

		ma_sndseq_info.state[func_id][file_id] = MASMW_STATE_OPENED;

		result = MASMW_SUCCESS;
	}

	return result;
}
/****************************************************************************
 *	MaSound_Control
 *
 *	Function:
 *			Performs controlling processing of Stream Conveter.
 *	Argument:
 *			func_id		function id
 *			file_id		file id
 *			ctrl_num	control number
 *			prm			control parameter
 *			ext_args	for future extension
 *	Return:
 *			0			success
 *			< 0			error code
 *
 ****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -