📄 masnddrv.c
字号:
/* Description : Set the expression of specificated channel */
/* Event type : 0xBn0x0B... */
/* Note : default value 0x7F(127) */
/****************************************************************/
SINT32 MaSndDrv_Expression
(
SINT32 delta_time, /* delta time */
UINT32 ch, /* channel number */
UINT32 vol /* volume value */
)
{
UINT8 volume; /* volume value */
UINT32 num; /* number of packet data */
UINT32 reg_index; /* register index number */
SINT32 result; /* result of function */
/* check arguments */
if(( ch > MASMW_MAX_CHANNEL )||( vol > MASMW_MAX_VOLUME ))
return MASMW_ERROR;
/* update channel information */
ma_channel_info[ch].expression = (UINT8)(vol & MASMW_MASK_VOLUME);
volume = CalcChVolume( ch );
/* Make packet data and send it */
num = MakeDeltaTime( &packet_buf[0], delta_time );
reg_index = (UINT32)(MA_CHANNEL_VOLUME + ch);
/*MAKE_ADDRESS_PART( seq_id, num, reg_index )*/
packet_buf[num++] = (UINT8)( reg_index & 0x7F );
packet_buf[num++] = (UINT8)( (reg_index >> 7) | 0x80 );
/*MAKE_CHANNEL_VOLUME( seq_id, num, volume )*/
packet_buf[num++] = (UINT8)( (volume & 0x7C) | 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;
}
/*****************************************************************/
/* Fuction Name : MaSndDrv_ModulationDepth */
/* Description : Sets the depth of vibrato of specified channel */
/* Event type : 0xBn0x01... */
/* Note : default volume 0x00 */
/*****************************************************************/
SINT32 MaSndDrv_ModulationDepth
(
SINT32 delta_time, /* delta time */
UINT32 ch, /* channel number */
UINT32 depth /* modulation depth */
)
{
UINT8 sfx; /* sfx value */
UINT32 num; /* number of packet data */
UINT32 reg_index; /* register index number */
SINT32 result; /* result of function */
static const UINT8 xvb[8] = { 0, 1, 2, 4, 6, 0, 0, 0 };
/* check arguments */
if(( ch > MASMW_MAX_CHANNEL )||( depth > MASMW_MAX_DEPTH ))
return MASMW_ERROR;
/* update channel information */
depth &= MASMW_MASK_DEPTH;
sfx = (UINT8)( (ma_channel_info[ch].sfx & MASMW_MASK_XVB) | xvb[depth] );
ma_channel_info[ch].sfx = sfx;
/* Make packet data and send it */
num = MakeDeltaTime( &packet_buf[0], delta_time );
reg_index = (UINT32)(MA_CHANNEL_VIBRATO + ch);
/*MAKE_ADDRESS_PART( seq_id, num, reg_index )*/
packet_buf[num++] = (UINT8)( reg_index & 0x7F );
packet_buf[num++] = (UINT8)( (reg_index >> 7) | 0x80 );
/*MAKE_SFX( seq_id, num, sfx )*/
packet_buf[num++] = (UINT8)( sfx | 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 Name : MaSndDrv_Hold1 */
/* Description : Sets the dumpper setting of specified channel */
/* Event type : 0xBn0x40... */
/* Note : default value 0x00 */
/*****************************************************************/
SINT32 MaSndDrv_Hold1
(
SINT32 delta_time, /* delta time */
UINT32 ch, /* channle number */
UINT32 val /* dumper setting value */
)
{
UINT8 sfx; /* sfx value */
UINT32 num; /* number of packet data */
UINT32 reg_index; /* register index number */
SINT32 result; /* result of function */
/* check arguments */
if(( ch > MASMW_MAX_CHANNEL )||( val > MASMW_MAX_HOLD1 ))
return MASMW_ERROR;
/* updata channel information */
sfx = (UINT8)( (ma_channel_info[ch].sfx & MASMW_MASK_SUS) | ((val & 0x01) << 4) );
ma_channel_info[ch].sfx = sfx;
/* Make packet data and send it */
num = MakeDeltaTime( &packet_buf[0], delta_time );
reg_index = (UINT32)(MA_CHANNEL_SUSTAIN + ch);
/*MAKE_ADDRESS_PART( seq_id, num, reg_index )*/
packet_buf[num++] = (UINT8)( reg_index & 0x7F );
packet_buf[num++] = (UINT8)( (reg_index >> 7) | 0x80 );
/*MAKE_SFX( seq_id, num, sfx )*/
packet_buf[num++] = (UINT8)( sfx | 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;
}
/*****************************************************************/
/* Fuction Name : MaSndDrv_ResetAllControllers */
/* Description : Resets the control values of specified channel */
/* Event type : 0xBn0x790x00 */
/* Note : contain : Channel volume , sfx, Pitch bend */
/*****************************************************************/
SINT32 MaSndDrv_ResetAllControllers
(
SINT32 delta_time, /* delta time */
UINT32 ch /* channel number */
)
{
UINT8 volume; /* volume value */
UINT8 bend_range; /* bend range */
UINT16 bend; /* bend value */
UINT8 sfx; /* sfx */
UINT32 num; /* number of packet data */
UINT32 reg_index; /* register index number */
SINT32 result; /* result of function */
/* check arguments */
if( ch > MASMW_MAX_CHANNEL )
return MASMW_ERROR;
/* updata channel information */
ma_channel_info[ch].sfx = 0x00;
sfx = ma_channel_info[ch].sfx;
ma_channel_info[ch].expression = 127;
/* Make packet data */
num = MakeDeltaTime( &packet_buf[0], delta_time );
/* channel volume */
volume = CalcChVolume( ch );
reg_index = (UINT32)(MA_CHANNEL_VOLUME + ch);
/*MAKE_ADDRESS_PART( seq_id, num, reg_index )*/
packet_buf[num++] = (UINT8)( reg_index & 0x7F );
packet_buf[num++] = (UINT8)( (reg_index >> 7) | 0x80 );
/*MAKE_CHANNEL_VOLUME( seq_id, num, volume )*/
packet_buf[num++] = (UINT8)( (volume & 0x7C) | 0x80 );
/* sfx */
reg_index = (UINT32)(MA_CHANNEL_SUSTAIN + ch);
/*MAKE_TIMER_PART( seq_id, num, delta_time )*/
if ( delta_time >= 0 )
{
packet_buf[num++] = (UINT8)( 0x80 );
}
/*MAKE_ADDRESS_PART( seq_id, num, reg_index )*/
packet_buf[num++] = (UINT8)( reg_index & 0x7F );
packet_buf[num++] = (UINT8)( (reg_index >> 7) | 0x80 );
/*MAKE_SFX( seq_id, num, ma_channel_info[ch].sfx )*/
packet_buf[num++] = (UINT8)( sfx | 0x80 );
/* pitch bend */
bend_range = ma_channel_info[ch].bend_range;
bend = ma_pitchbend[bend_range][64];
reg_index = (UINT32)( MA_CHANNEL_BEND + ch*2 );
/*MAKE_TIMER_PART( seq_id, num, delta_time )*/
if ( delta_time >= 0 )
{
packet_buf[num++] = (UINT8)( 0x80 );
}
/*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, bend )*/
packet_buf[num++] = (UINT8)( (bend >> 7) & 0x7F );
packet_buf[num++] = (UINT8)( 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 Name : MaSndDrv_MonoModeOn */
/* Description : Sets the monophonic mode to specified channel */
/* Event type : 0xBn0x7E0x01 */
/* Note : */
/******************************************************************/
SINT32 MaSndDrv_MonoModeOn
(
SINT32 delta_time, /* delta time */
UINT32 ch /* channel number */
)
{
SINT32 result; /* result of function */
/* check argument */
if( ch > MASMW_MAX_CHANNEL )
return MASMW_ERROR;
/* updata channel information */
if ( ma_channel_info[ch].bank_no < 128 )
{
ma_channel_info[ch].poly = MA_MODE_MONO;
}
/* Make packet data and send it */
if ( delta_time > 0 )
result = MaSndDrv_Nop( delta_time, 0 );
else
result = MASMW_SUCCESS;
return result;
}
/********************************************************************/
/* Function Name : MaSndDrv_PolyModeOn */
/* Description : Sets the polyphonic mode to specified channel */
/* Event type : 0xBn0x7F0x00 */
/* Note : the Poly Mode is default setting */
/********************************************************************/
SINT32 MaSndDrv_PolyModeOn
(
SINT32 delta_time, /* delta time */
UINT32 ch /* channel number */
)
{
SINT32 result; /* result of function */
/* check argument */
if( ch > MASMW_MAX_CHANNEL )
return MASMW_ERROR;
/* updata channel information */
ma_channel_info[ch].poly = MA_MODE_POLY;
/* Make packet data and send it */
if ( delta_time > 0 )
result = MaSndDrv_Nop( delta_time, 0 );
else
result = MASMW_SUCCESS;
return result;
}
/***************************************************************/
/* Function Name : MaSndDrv_BendRange */
/* Description : Set the bend range of specificated channel */
/* Event type : 0xBn0x06... */
/* Note : */
/***************************************************************/
SINT32 MaSndDrv_BendRange
(
SINT32 delta_time, /* delta time */
UINT32 ch, /* channel number */
UINT32 bend_range /* bend range */
)
{
SINT32 result; /* result of function */
/* check argument */
if(( ch > MASMW_MAX_CHANNEL )||( bend_range > MASMW_MAX_BENDRANGE ))
return MASMW_ERROR;
/* updata channel information */
ma_channel_info[ch].bend_range = (UINT8)( bend_range );
/* Make packet data and send it */
if ( delta_time > 0 )
result = MaSndDrv_Nop( delta_time, 0 );
else
result = MASMW_SUCCESS;
return result;
}
/**********************************************************/
/* Function Name : MaSndDrv_MasterVolume */
/* Description : make master volume */
/* Event type : 0xF0...0x00 (Exclusive Message) */
/* Note : default volume = 0x2D */
/**********************************************************/
SINT32 MaSndDrv_MasterVolume
(
SINT32 delta_time, /* delta time */
UINT32 vol /* volume value */
)
{
SINT32 result; /* result of function */
ma_snddrv_info.master_volume = (UINT8)vol;
result = MaSndDrv_Nop( delta_time, 0 );
return result;
}
/**********************************************************/
/* Function Name : MaSndDrv_ProgramChange */
/* Description : make program number */
/* Event type : 0xCn... */
/* Note : default value = 0x00 */
/**********************************************************/
SINT32 MaSndDrv_ProgramChange
(
SINT32 delta_time, /* duration */
UINT8 ch, /* channel number */
UINT8 BankM, /* bankM number */
UINT8 BankL, /* bankL number */
UINT8 prog_no /* program number */
)
{
UINT8 bank_no;
SINT32 result; /* result of function */
if (BankM == 0x7C)
{
if(BankL < 0x0a)
bank_no = (UINT8)(BankL + 1);
else
bank_no = 0;
}
else if (BankM == 0x7D)
{
if((BankL == 0x00) && (prog_no < 0x0A))
bank_no = (UINT8)(prog_no + 129);
else
bank_no = (UINT8)128;
}
else
{
if (ch == 0x09)
{
bank_no = (UINT8)128;
}
else
{
bank_no = 0;
}
}
/* update channel information */
ma_channel_info[ch].bank_no = bank_no & MASMW_MASK_BANK;
ma_channel_info[ch].prog_no = prog_no & MASMW_MASK_PROGRAM;
if ( bank_no >= 128 )
{
ma_channel_info[ch].poly = MA_MODE_POLY;
}
if ( delta_time > 0 )
result = MaSndDrv_Nop( delta_time, 0 );
else
result = MASMW_SUCCESS;
return result;
}
/****************************************************************/
/* Function Name : MasndDrv_PitchBend */
/* Description : Sets the pitch bend of the specified channel */
/* Event type : 0xEn... */
/* Note : default value 0x40(LSB),0x00(MSB) */
/****************************************************************/
SINT32 MaSndDrv_PitchBend
(
SINT32 delta_time, /* delta time */
UINT32 ch, /* channel number */
UINT32 bend /* bend */
)
{
UINT8 bend_range; /* bend range */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -