📄 masnddrv.c
字号:
UINT16 pitch_bend; /* pitch bend */
UINT32 reg_index; /* register index number */
SINT32 num; /* number of packet data */
SINT32 result; /* result of function */
/* check range */
if(( ch > MASMW_MAX_CHANNEL )||( bend > MASMW_MAX_BEND ))
return MASMW_ERROR;
/* setting the bend value */
bend &= MASMW_MASK_BEND;
bend_range = ma_channel_info[ch].bend_range;
pitch_bend = ma_pitchbend[bend_range][bend >> 7];
/* Make packet data and send it */
num = MakeDeltaTime( &packet_buf[0], delta_time );
reg_index = (UINT32)(MA_CHANNEL_BEND + ch * 2);
/* MAKE_ADDRESS_PART( seq_id, num, reg_index ) */
packet_buf[num++] = (UINT8)( reg_index & 0x7F );
packet_buf[num++] = (UINT8)( (reg_index >> 7) | 0x80 );
/* MAKE_PITCH_BEND( seq_id, num, pitch_bend ) */
packet_buf[num++] = (UINT8)( (pitch_bend >> 7) & 0x7F );
packet_buf[num++] = (UINT8)( pitch_bend | 0x80 );
if ( delta_time < 0 ) /* direct command */
{
result = MaDevDrv_SendDirectPacket( &packet_buf[0], num );
}
else /* delayed command */
{
result = MaDevDrv_SendDelayedPacket( &packet_buf[0], num );
}
return result;
}
/*****************************************************************/
/* Function Group Name : Set_EOS */
/* Description : EOS is a flag event of the Mtsq Chunck */
/* Event type : 0xFF 0x2F 0x00 */
/* Member function: RemakeSlotList MaSndDrv_AllSoundOff */
/* Note : All_Note_Off Event is used for the processing */
/*****************************************************************/
void RemakeSlotList
(
UINT32 synth_type, /* synth type */
UINT32 slot_no, /* slot number */
UINT32 type /* type */
)
{
UINT32 prv_slot;
UINT32 nxt_slot;
UINT32 temp = 0;
UINT32 flag = 0;
UINT32 min_slot;
UINT32 max_slot;
UINT32 i;
min_slot = ma_snddrv_info.min_slot[synth_type];
max_slot = ma_snddrv_info.max_slot[synth_type];
prv_slot = nxt_slot = ma_slot_list.top[synth_type];
for ( i = min_slot; i <= max_slot; i++ )
{
if ( flag == 0 )
{
if ( ma_slot_info[nxt_slot].ch > type )
{
if ( nxt_slot == ma_slot_list.top[synth_type] )
{
ma_slot_list.top[synth_type] = (UINT8)slot_no;
}
else
{
ma_slot_list.next[prv_slot] = (UINT8)slot_no;
}
temp = ma_slot_list.next[slot_no];
ma_slot_list.next[slot_no] = (UINT8)nxt_slot;
flag = 1;
}
}
if ( flag == 1 )
{
if ( ma_slot_list.next[nxt_slot] == slot_no )
{
if ( slot_no == ma_slot_list.end[synth_type] )
{
ma_slot_list.end[synth_type] = (UINT8)nxt_slot;
}
ma_slot_list.next[nxt_slot] = (UINT8)temp;
break;
}
}
prv_slot = nxt_slot;
nxt_slot = ma_slot_list.next[nxt_slot];
}
}
SINT32 MaSndDrv_AllSoundOff
(
SINT32 delta_time, /* delta time */
UINT32 ch /* channel number */
)
{
UINT32 slot_no; /* slot number */
UINT32 min_slot; /* minimum slot number */
UINT32 max_slot; /* maximum slot number */
UINT32 synth_type; /* type of synth */
UINT32 tnum = 0; /* total number of packet data */
UINT32 num = 0; /* number of packet data */
UINT32 reg_index; /* register index number */
SINT32 result = MASMW_SUCCESS; /* result of packet sending */
if( ch > MASMW_MAX_CHANNEL )
return MASMW_ERROR;
ma_channel_info[ch].note_on = 0;
/* FM & WT */
tnum = 0;
for ( synth_type = 0; synth_type < 2; synth_type++ )
{
min_slot = ma_snddrv_info.min_slot[synth_type];
max_slot = ma_snddrv_info.max_slot[synth_type];
for ( slot_no = min_slot; slot_no <= max_slot; slot_no++ )
{
if ( (ma_slot_info[slot_no].ch & 0x7F) == (UINT8)(ch + 1) )
{
if ( ( ma_slot_info[slot_no].ch & 0x80 ) != 0 )
{
RemakeSlotList( synth_type, slot_no, 0x80 );
ma_slot_info[slot_no].ch = (UINT8)(ch + 1);
}
if ( slot_no < 16 )
{
reg_index = (UINT32)(((slot_no - 0) * 6) + MA_FM_VOICE_ADDRESS);
}
else if ( slot_no < 32 )
{
reg_index = (UINT32)(((slot_no - 16) * 6) + MA_EXT_FM_VOICE_ADDRESS);
}
else if ( slot_no < 40 )
{
reg_index = (UINT32)(((slot_no - 32) * 6) + MA_WT_VOICE_ADDRESS);
}
else
{
continue;
}
num = MakeDeltaTime( &packet_buf[0], delta_time );
if ( delta_time <= 0 )
{
/* NOP2 */
/*MAKE_NOP( seq_id, num, (UINT16)MA_NOP_2 )*/
packet_buf[num++] = (UINT8)( (UINT16)MA_NOP_2 & 0x7F );
packet_buf[num++] = (UINT8)( ((UINT16)MA_NOP_2 >> 7) | 0x80 );
packet_buf[num++] = (UINT8)( 0x00 | 0x80 );
/*MAKE_TIMER_PART( seq_id, num, delta_time )*/
if ( delta_time >= 0 )
{
packet_buf[num++] = (UINT8)( 0x80 ); /* make delta time */
}
}
/* KeyOff & MUTE & RST */
reg_index += 5;
/*MAKE_ADDRESS_PART( seq_id, num, reg_index )*/
packet_buf[num++] = (UINT8)( reg_index & 0x7F );
packet_buf[num++] = (UINT8)( (reg_index >> 7) | 0x80 );
/*MAKE_RST_MUTE( seq_id, num, ch )*/
packet_buf[num++] = (UINT8)( (0x30 + ch) | 0x80 );
if ( delta_time < 0 ) /* direct command */
{
result = MaDevDrv_SendDirectPacket( &packet_buf[0], num );
}
else /* delayed command */
{
result = MaDevDrv_SendDelayedPacket( &packet_buf[0], num );
}
tnum += num;
}
}
}
if ( tnum == 0 )
{
if ( delta_time > 0 )
result = MaSndDrv_Nop( delta_time, 0 );
else
result = MASMW_SUCCESS;
}
return result;
}
SINT32 MaSndDrv_AllSoundOff_EOS
(
SINT32 delta_time /* delta time */
)
{
UINT32 ch; /* channel number */
UINT32 slot_no; /* slot number */
UINT32 min_slot; /* minimum slot number */
UINT32 max_slot; /* maximum slot number */
UINT32 synth_type; /* type of synth */
UINT32 tnum = 0; /* total number of packet data */
UINT32 num = 0; /* number of packet data */
UINT32 reg_index; /* register index number */
SINT32 result = MASMW_SUCCESS; /* result of packet sending */
for(ch = 0; ch <= MASMW_MAX_CHANNEL; ch++)
{
ma_channel_info[ch].note_on = 0;
/* FM & WT */
tnum = 0;
for ( synth_type = 0; synth_type < 2; synth_type++ )
{
min_slot = ma_snddrv_info.min_slot[synth_type];
max_slot = ma_snddrv_info.max_slot[synth_type];
for ( slot_no = min_slot; slot_no <= max_slot; slot_no++ )
{
if ( (ma_slot_info[slot_no].ch & 0x7F) == (UINT8)(ch + 1) )
{
if ( ( ma_slot_info[slot_no].ch & 0x80 ) != 0 )
{
RemakeSlotList( synth_type, slot_no, 0x80 );
ma_slot_info[slot_no].ch = (UINT8)(ch + 1);
}
if ( slot_no < 16 )
{
reg_index = (UINT32)(((slot_no - 0) * 6) + MA_FM_VOICE_ADDRESS);
}
else if ( slot_no < 32 )
{
reg_index = (UINT32)(((slot_no - 16) * 6) + MA_EXT_FM_VOICE_ADDRESS);
}
else if ( slot_no < 40 )
{
reg_index = (UINT32)(((slot_no - 32) * 6) + MA_WT_VOICE_ADDRESS);
}
else
{
continue;
}
num = MakeDeltaTime( &packet_buf[0], delta_time );
if ( delta_time <= 0 )
{
/* NOP2 */
/*MAKE_NOP( seq_id, num, (UINT16)MA_NOP_2 )*/
packet_buf[num++] = (UINT8)( (UINT16)MA_NOP_2 & 0x7F );
packet_buf[num++] = (UINT8)( ((UINT16)MA_NOP_2 >> 7) | 0x80 );
packet_buf[num++] = (UINT8)( 0x00 | 0x80 );
/*MAKE_TIMER_PART( seq_id, num, delta_time )*/
if ( delta_time >= 0 )
{
packet_buf[num++] = (UINT8)( 0x80 ); /* make delta time */
}
}
/* KeyOff & MUTE & RST */
reg_index += 5;
/*MAKE_ADDRESS_PART( seq_id, num, reg_index )*/
packet_buf[num++] = (UINT8)( reg_index & 0x7F );
packet_buf[num++] = (UINT8)( (reg_index >> 7) | 0x80 );
/*MAKE_RST_MUTE( seq_id, num, ch )*/
packet_buf[num++] = (UINT8)( (0x30 + ch) | 0x80 );
if ( delta_time < 0 ) /* direct command */
{
result = MaDevDrv_SendDirectPacket( &packet_buf[0], num );
}
else /* delayed command */
{
result = MaDevDrv_SendDelayedPacket( &packet_buf[0], num );
}
tnum += num;
}
}
}
if ( tnum == 0 )
{
if ( delta_time > 0 )
result = MaSndDrv_Nop( delta_time, 0 );
else
result = MASMW_SUCCESS;
}
}
return result;
}
/*******************************************************************/
/* Function Name : MaSndDrv_AllSoundOff2 */
/* Description : */
/* Note : */
/*******************************************************************/
SINT32 MaSndDrv_AllSoundOff2
(
SINT32 delta_time
)
{
UINT32 num;
SINT32 result;
num = MakeDeltaTime( &packet_buf[0], delta_time ); /* timer part */
/* stop the sequencer */
packet_buf[num++] = (UINT8)( MA_START_SEQ & 0x7F ); /* address */
packet_buf[num++] = (UINT8)( (MA_START_SEQ >> 7) | 0x80 );
packet_buf[num++] = (UINT8)( 0x80 ); /* data */
if ( delta_time < 0 ) /* direct command */
{
result = MaDevDrv_SendDirectPacket( &packet_buf[0], num );
}
else /* delayed command */
{
result = MaDevDrv_SendDelayedPacket( &packet_buf[0], num );
}
/* clear the FIFO of the delayed path */
MaDevDrv_ClearFifo();
return result;
}
/**********************************/
/* section4 is Note Event process */
/**********************************/
/********************************************************************/
/* Function Group Name: Note_ON */
/* Description : make note play */
/* Event type : 0x8n... or 0x9n... */
/* Member function : GetSlotList , GetFmBlockFnum ,GetWtBlockFnum */
/* CalcVoiceVolume ,MakeDeltaTime ,GetVoiceInfo */
/* MaSndDrv_NoteOn . */
/* Note : It's the core of SMAF!!! */
/********************************************************************/
SINT32 GetSlotList
(
SINT32 synth_type /* synth type */
)
{
UINT8 top_slot;
UINT8 end_slot;
top_slot = ma_slot_list.top[synth_type];
end_slot = ma_slot_list.end[synth_type];
ma_slot_list.next[end_slot] = top_slot;
ma_slot_list.top[synth_type] = ma_slot_list.next[top_slot];
ma_slot_list.end[synth_type] = top_slot;
ma_slot_list.next[top_slot] = (UINT8)(ma_snddrv_info.max_slot[synth_type] + 1);
return top_slot;
}
UINT16 GetFmBlockFnum
(
UINT8 ch, /* channel number */
UINT8 key, /* key number */
UINT16 drum_key /* key number for drum */
)
{
UINT8 bank_no; /* bank number */
UINT8 prog_no; /* program number */
UINT16 pitch; /* pitch = block&fnum */
bank_no = ma_channel_info[ch].bank_no;
prog_no = ma_channel_info[ch].prog_no;
if ( bank_no < 128 )
{
if ( prog_no <= 114 ) /* 1..114 */
{
pitch = ma_fm_block_100[key];
}
else if ( prog_no == 115 ) /* 115 */
{
pitch = ma_fm_block_50a[key];
}
else if ( prog_no == 116 ) /* 116 */
{
pitch = ma_fm_block_50b[key];
}
else if ( prog_no == 117 ) /* 117 */
{
pitch = ma_fm_block_50c[key];
}
else if ( prog_no <= 119 ) /* 118, 119 */
{
pitch = ma_fm_block_50[key];
}
else if ( prog_no <= 121 ) /* 120, 121 */
{
pitch = ma_fm_block_100[key];
}
else if ( ( prog_no == 122 ) || ( prog_no == 127 ) ) /* 122, 127 */
{
pitch = ma_fm_block_20[key];
}
else if ( ( prog_no == 123 ) || ( prog_no == 126 ) ) /* 123, 126 */
{
pitch = ma_fm_block_5[key];
}
else if ( ( prog_no == 124 ) || ( prog_no == 125 ) ) /* 124, 125 */
{
pitch = ma_fm_block_10[key];
}
else
{
pitch = ma_fm_block_100[key];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -