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

📄 masnddrv.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
{
	UINT32	slot_no;					/* slot number */
	UINT8	old_ch;						/* old channel number */
	UINT8	vo_volume;					/* voice volume */
	UINT32	num;						/* number of packet data */
	UINT32	reg_index;					/* register index */
	UINT32	pitch;						/* pitch */
	SINT32	result;						/* result of function */
	MAVINFO	voice_info;					/* voice information */
	
	MASNDDRV_DBGMSG((" MaSndDrv_NoteOn: id=%ld dt=%ld ch=%ld key=%ld vel=%ld\n", seq_id, delta_time, ch, key, velocity));

	/* check arguments */

	MASMW_ASSERT( ch <= MASMW_MAX_CHANNEL );
	MASMW_ASSERT( key <= MASMW_MAX_KEY );
	MASMW_ASSERT( velocity <= MASMW_MAX_VELOCITY );

	/* get voice information */

	result = GetVoiceInfo( seq_id, ch, key, &voice_info );
	if ( result < MASMW_SUCCESS )
	{
		result = MaSndDrv_Nop( seq_id, delta_time, 0, 0, 0 );
		return result;
	}

	/* get slot number */

	if ( ma_channel_info[ch].poly == MA_MODE_POLY )
	{
		slot_no = GetSlotList( seq_id, voice_info.synth-1 );

		if ( ( ma_slot_info[slot_no].ch & 0x80 ) != 0 )
		{
			old_ch = (UINT8)( ( ma_slot_info[slot_no].ch - 1 ) & 0x7F );
			ma_channel_info[old_ch].note_on = 0;
		}
	}
	else
	{
		if ( ma_channel_info[ch].note_on == 0 )
		{
			slot_no = GetSlotList( seq_id, voice_info.synth-1 );
			ma_channel_info[ch].slot_no = (UINT8)slot_no;

			if ( ( ma_slot_info[slot_no].ch & 0x80 ) != 0 )
			{
				old_ch = (UINT8)( ( ma_slot_info[slot_no].ch - 1 ) & 0x7F );
				ma_channel_info[old_ch].note_on = 0;
			}
		}
		else
		{
			slot_no = ma_channel_info[ch].slot_no;
			RemakeSlotListE( seq_id, (UINT8)(voice_info.synth - 1), slot_no );
		}
	
		ma_channel_info[ch].note_on++;
	}

	/* set register index value and pitch of slot */

	if ( slot_no < 16 )
	{
		reg_index = (UINT32)(((slot_no -  0) * 6) + MA_FM_VOICE_ADDRESS);
		pitch = GetFmBlockFnum( seq_id, (UINT8)ch, key, voice_info.key );
		vo_volume = CalcVoiceVolume( seq_id, velocity, 0 );
	}
	else if ( slot_no < 32 )
	{
		reg_index = (UINT32)(((slot_no - 16) * 6) + MA_EXT_FM_VOICE_ADDRESS);
		pitch = GetFmBlockFnum( seq_id, (UINT8)ch, key, voice_info.key );
		vo_volume = CalcVoiceVolume( seq_id, velocity, 0 );
	}
	else if ( slot_no < 40 )
	{
		reg_index = (UINT32)(((slot_no - 32) * 6) + MA_WT_VOICE_ADDRESS);
		pitch = GetWtBlockFnum( seq_id, (UINT8)ch, key, voice_info.key );
		vo_volume = CalcVoiceVolume( seq_id, velocity, (12 << 1) );
	}
	else
	{
		result = MaSndDrv_Nop( seq_id, delta_time, 0, 0, 0 );
		return result;
	}

	/* alternate assign */

	if ( ma_channel_info[ch].bank_no >= 128 )
	{
		if ( ma_snddrv_info[seq_id].drum_mode == 0 )
		{
			delta_time = AlternateAssign( seq_id, delta_time, key );
		}
	}


	num = MakeDeltaTime( &packet_buf[seq_id][0], delta_time );


	if ( ma_channel_info[ch].poly == MA_MODE_POLY )
	{
		if ( ( ma_slot_info[slot_no].ch & 0x80 ) == 0 )	/* new note */
		{
			old_ch = (UINT8)ch;
		}
		else
		{
			old_ch = (UINT8)( ma_slot_info[slot_no].ch - 1 );
		}

		if ( delta_time <= 0 )
		{
			/* NOP2 */
			MAKE_NOP( seq_id, num, (UINT16)MA_NOP_2 )
			MAKE_TIMER_PART( seq_id, num, delta_time )
		}

		/* KeyOn */
		reg_index += 5;
		MAKE_ADDRESS_PART( seq_id, num, reg_index )
		MAKE_RST( seq_id, num, old_ch )
		MAKE_TIMER_PART( seq_id, num, delta_time )

		MAKE_NOP( seq_id, num, (UINT16)MA_NOP_2 )
		MAKE_TIMER_PART( seq_id, num, delta_time )

		reg_index -= 5;
		MAKE_ADDRESS_PART( seq_id, num, reg_index )
		MAKE_KEY_ON( seq_id, num, voice_info.address, vo_volume, pitch, ch )
	}
	else
	{
		if ( ma_channel_info[ch].bank_no >= 128 ) return MASMW_SUCCESS;

		if ( ma_channel_info[ch].note_on == 1 )	/* new note */
		{
			if ( delta_time <= 0 )
			{
				/* NOP2 */
				MAKE_NOP( seq_id, num, (UINT16)MA_NOP_2 )
				MAKE_TIMER_PART( seq_id, num, delta_time )
			}

			/* KeyOn */
			reg_index += 5;
			MAKE_ADDRESS_PART( seq_id, num, reg_index )
			MAKE_RST( seq_id, num, ch )
			MAKE_TIMER_PART( seq_id, num, delta_time )

			MAKE_NOP( seq_id, num, (UINT16)MA_NOP_2 )
			MAKE_TIMER_PART( seq_id, num, delta_time )

			reg_index -= 5;
			MAKE_ADDRESS_PART( seq_id, num, reg_index )
			MAKE_KEY_ON( seq_id, num, voice_info.address, vo_volume, pitch, ch )
		}
		else
		{
			/* velocity & pitch */
			reg_index += 2;
			MAKE_ADDRESS_PART( seq_id, num, reg_index )
			MAKE_VEL_PITCH( seq_id, num, vo_volume, pitch )
		}
	}

	/* Send packet data */

	if ( delta_time < 0 )				/* direct command */
	{
		result = MaDevDrv_SendDirectPacket( &packet_buf[seq_id][0], num );
	}
	else								/* delayed command */
	{
		result = SendDelayedPacket( &packet_buf[seq_id][0], num );
	}

	/* update the slot information */

	ma_slot_info[slot_no].ch	= (UINT8)( (ch + 1) | 0x80 );
	ma_slot_info[slot_no].key	= key;

	return result;
}
/****************************************************************************
 *	MaSndDrv_NoteOnMa2
 *
 *	Description:
 *			MA-2 compatible Note On prcessing
 *	Argument:
 *			seq_id		sequence id (0..2)
 *			delta_time	delta time [tick]
 *			ch			channel number (0..15)
 *			key			key number (0..127)
 *			velocity	velocity (0..127)
 *	Return:
 *			Number of byte data of created packet
 *
 ****************************************************************************/
static SINT32 MaSndDrv_NoteOnMa2
(
	SINT32	seq_id,						/* sequnce id */
	SINT32	delta_time,					/* delta time */
	UINT32	ch,							/* channel number */
	UINT32	key,						/* key number */
	UINT32	velocity					/* velocity */
)
{
	UINT32	slot_no;					/* slot number */
	UINT8	old_ch;						/* old channel number */
	UINT8	vo_volume;					/* voice volume */
	UINT32	num;						/* number of packet data */
	UINT32	reg_index;					/* register index */
	UINT32	pitch;						/* pitch */
	SINT32	result;						/* result of function */
	MAVINFO	voice_info;					/* voice information */
	
	MASNDDRV_DBGMSG((" MaSndDrv_NoteOnMa2: id=%ld dt=%ld ch=%ld key=%ld vel=%ld\n", seq_id, delta_time, ch, key, velocity));

	/* check arguments */

	MASMW_ASSERT( ch <= MASMW_MAX_CHANNEL );
	MASMW_ASSERT( key <= MASMW_MAX_KEY );
	MASMW_ASSERT( velocity <= MASMW_MAX_VELOCITY );

	/* get voice information */

	result = GetVoiceInfo( seq_id, ch, key, &voice_info );
	if ( result < MASMW_SUCCESS )
	{
		result = MaSndDrv_Nop( seq_id, delta_time, 0, 0, 0 );
		return result;
	}

	/* get slot number */

	slot_no = GetSlot( seq_id, voice_info.synth, (UINT8)ch );
	ma_channel_info[ch].note_on++;

	/* set register index value and pitch of slot */

	if ( slot_no < 16 )
	{
		reg_index = (UINT32)(((slot_no -  0) * 6) + MA_FM_VOICE_ADDRESS);
		pitch = GetFmBlockFnum( seq_id, (UINT8)ch, key, voice_info.key );
		vo_volume = CalcVoiceVolume( seq_id, velocity, 0 );
	}
	else if ( slot_no < 32 )
	{
		reg_index = (UINT32)(((slot_no - 16) * 6) + MA_EXT_FM_VOICE_ADDRESS);
		pitch = GetFmBlockFnum( seq_id, (UINT8)ch, key, voice_info.key );
		vo_volume = CalcVoiceVolume( seq_id, velocity, 0 );
	}
	else if ( slot_no < 40 )
	{
		reg_index = (UINT32)(((slot_no - 32) * 6) + MA_WT_VOICE_ADDRESS);
		pitch = GetWtBlockFnum( seq_id, (UINT8)ch, key, voice_info.key );
		vo_volume = CalcVoiceVolume( seq_id, velocity, (12 << 1) );
	}
	else
	{
		result = MaSndDrv_Nop( seq_id, delta_time, 0, 0, 0 );
		return result;
	}

	/* update channel information */

	old_ch = (UINT8)( ma_slot_info[slot_no].ch - 1 );


	num = MakeDeltaTime( &packet_buf[seq_id][0], delta_time );


	if ( delta_time <= 0 )
	{
		/* NOP2 */
		MAKE_NOP( seq_id, num, (UINT16)MA_NOP_2 )
		MAKE_TIMER_PART( seq_id, num, delta_time )
	}

	if ( ma_channel_info[ch].bank_no >= 128 )
	{
		/* KeyOff & RST */
		reg_index += 5;
		MAKE_ADDRESS_PART( seq_id, num, reg_index )
		MAKE_RST( seq_id, num, ch )
		MAKE_TIMER_PART( seq_id, num, delta_time )
		reg_index -= 5;

		/* NOP2 */
		MAKE_NOP( seq_id, num, (UINT16)MA_NOP_2 )
		MAKE_TIMER_PART( seq_id, num, delta_time )
	}

	/* KeyOn */

	if ( ma_channel_info[ch].note_on == 1 )		/* new note */
	{
		MAKE_ADDRESS_PART( seq_id, num, reg_index )
		MAKE_KEY_ON( seq_id, num, voice_info.address, vo_volume, pitch, ch )
	}
	else										/* continuouse note */
	{
		reg_index += 2;
		MAKE_ADDRESS_PART( seq_id, num, reg_index )
		MAKE_VEL_PITCH( seq_id, num, vo_volume, pitch )
	}

	/* Send packet data */

	if ( delta_time < 0 )				/* direct command */
	{
		result = MaDevDrv_SendDirectPacket( &packet_buf[seq_id][0], num );
	}
	else								/* delayed command */
	{
		result = SendDelayedPacket( &packet_buf[seq_id][0], num );
	}

	/* update the slot information */

	ma_slot_info[slot_no].ch	= (UINT8)( (ch + 1) | 0x80 );
	ma_slot_info[slot_no].key	= key;

	return result;
}
/****************************************************************************
 *	MaSndDrv_NoteOnMa2Ex
 *
 *	Description:
 *			MA-2 compatible Note On prcessing
 *	Argument:
 *			seq_id		sequence id (0..2)
 *			delta_time	delta time [tick]
 *			ch			channel number (0..15)
 *			key			key number (0..127)
 *			velocity	velocity (0..127)
 *	Return:
 *			Number of byte data of created packet
 *
 ****************************************************************************/
static SINT32 MaSndDrv_NoteOnMa2Ex
(
	SINT32	seq_id,						/* sequnce id */
	SINT32	delta_time,					/* delta time */
	UINT32	ch,							/* channel number */
	UINT32	key,						/* key number */
	UINT32	velocity					/* velocity */
)
{
	UINT32	slot_no;					/* slot number */
	UINT8	old_ch;						/* old channel number */
	UINT8	vo_volume;					/* voice volume */
	UINT32	num;						/* number of packet data */
	UINT32	reg_index;					/* register index */
	UINT32	pitch;						/* pitch */
	SINT32	result;						/* result of function */
	MAVINFO	voice_info;					/* voice information */
	
	MASNDDRV_DBGMSG((" MaSndDrv_NoteOnMa2Ex: id=%ld dt=%ld ch=%ld key=%ld vel=%ld\n", seq_id, delta_time, ch, key, velocity));

	/* check arguments */

	MASMW_ASSERT( ch <= MASMW_MAX_CHANNEL );
	MASMW_ASSERT( velocity <= MASMW_MAX_VELOCITY );

	/* get voice information */

	result = GetVoiceInfo( seq_id, ch, key, &voice_info );
	if ( result < MASMW_SUCCESS )
	{
		result = MaSndDrv_Nop( seq_id, delta_time, 0, 0, 0 );
		return result;
	}

	/* get slot number */

	slot_no = GetSlot( seq_id, voice_info.synth, (UINT8)ch );
	ma_channel_info[ch].note_on++;

	/* set register index value and pitch of slot */

	if ( slot_no < 16 )
	{
		reg_index = (UINT32)(((slot_no -  0) * 6) + MA_FM_VOICE_ADDRESS);
		pitch = GetFmBlockFnumMa2( seq_id, (UINT8)ch, key, voice_info.key );
		vo_volume = CalcVoiceVolume( seq_id, velocity, 0 );
	}
	else if ( slot_no < 32 )
	{
		reg_index = (UINT32)(((slot_no - 16) * 6) + MA_EXT_FM_VOICE_ADDRESS);
		pitch = GetFmBlockFnumMa2( seq_id, (UINT8)ch, key, voice_info.key );
		vo_volume = CalcVoiceVolume( seq_id, velocity, 0 );
	}
	else if ( slot_no < 40 )
	{
		reg_index = (UINT32)(((slot_no - 32) * 6) + MA_WT_VOICE_ADDRESS);
		pitch = GetWtBlockFnum( seq_id, (UINT8)ch, key, voice_info.key );
		vo_volume = CalcVoiceVolume( seq_id, velocity, (12 << 1) );
	}
	else
	{
		result = MaSndDrv_Nop( seq_id, delta_time, 0, 0, 0 );
		return result;
	}

	/* update channel information */

	old_ch = (UINT8)( ma_slot_info[slot_no].ch - 1 );


	num = MakeDeltaTime( &packet_buf[seq_id][0], delta_time );


	if ( delta_time <= 0 )
	{
		/* NOP2 */
		MAKE_NOP( seq_id, num, (UINT16)MA_NOP_2 )
		MAKE_TIMER_PART( seq_id, num, delta_time )
	}

	if ( ma_channel_info[ch].bank_no >= 128 )
	{
		/* KeyOff & RST */
		reg_index += 5;
		MAKE_ADDRESS_PART( seq_id, num, reg_index )
		MAKE_RST( seq_id, num, ch )
		MAKE_TIMER_PART( seq_id, num, delta_time )
		reg_index -= 5;

		/* NOP2 */
		MAKE_NOP( seq_id, num, (UINT32)MA_NOP_2 )
		MAKE_TIMER_PART( seq_id, num, delta_time )
	}

	/* KeyOn */

	if ( ma_channel_info[ch].note_on == 1 )		/* new note */
	{
		MAKE_ADDRESS_PART( seq_id, num, reg_index )
		MAKE_KEY_ON( seq_id, num, voice_info.address, vo_volume, pitch, ch )
	}
	else										/* continuouse note */
	{
		reg_index += 2;
		MAKE_ADDRESS_PART( seq_id, num, reg_index )
		MAKE_VEL_PITCH( seq_id, num, vo_volume, pitch )
	}

	/* Send packet data */

	if ( delta_time < 0 )				/* direct command */
	{
		result = MaDevDrv_SendDirectPacket( &packet_buf[seq_id][0], num );
	}
	else								/* delayed command */
	{
		result = SendDelayedPacket( &packet_buf[seq_id][0], num );
	}

	/* update the slot information */

	ma_slot_info[slot_no].ch	= (UINT8)( (ch + 1) | 0x80 );
	ma_slot_info[slot_no].key	= key;

	return result;
}
/***********

⌨️ 快捷键说明

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