📄 maresmgr.c
字号:
/****************************************************************************
* *
* Copyright (C) 2001-2003 YAMAHA CORPORATION. All rights reserved. *
* *
* Module : maresmgr.c *
* *
* Description : MA Resource Manager *
* *
* Version : 1.3.15.3 2003.03.17 *
* *
****************************************************************************/
#include "maresmgr.h" /* MA Resource Manager */
/* Resource Information */
static MA_RESOURCE_INFO ma_resource_info;
static const UINT16 ma_rom_drum_type[128/16] =
{
/* F E D C B A 9 8 7 6 5 4 3 2 1 0 */
/* --------+------------------------------------ */
0x0000, /* 0- 15 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0x8000, /* 16- 31 | 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0xFF5A, /* 32- 47 | 1 1 1 1 1 1 1 1 0 1 0 1 1 0 1 0 */
0x0A9F, /* 48- 63 | 0 0 0 0 1 0 1 0 1 0 0 1 1 1 1 1 */
0x0000, /* 64- 79 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0x0000, /* 80- 95 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0x0000, /* 96-111 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0x0000, /* 112-127 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
};
static const UINT16 ma_rom_wave_address[MA_MAX_ROM_WAVE] =
{ 0x1400, 0x15D6, 0x1BA4, 0x2288, 0x24F4, 0x2B72, 0x34D2 };
static const UINT16 ma_rom_drum_key[61] =
{
0x0058, 0x001D, 0x003C, 0x0024, 0x0018, 0x0012, 0x0057, 0x0155,
0x005E, 0x00C0, 0x0027, 0x00D5, 0x0100, 0x004A, 0x0195, 0x0063,
0x01EA, 0x00AA, 0x0140, 0x00D5, 0x012A, 0x010A, 0x014A, 0x0140,
0x0180, 0x0119, 0x01C0, 0x0155, 0x00C0, 0x006F, 0x006D, 0x01C0,
0x0054, 0x012A, 0x001A, 0x0180, 0x003E, 0x003D, 0x004C, 0x0047,
0x0039, 0x0040, 0x003B, 0x004D, 0x0048, 0x0064, 0x006D, 0x0030,
0x002C, 0x0031, 0x0030, 0x0045, 0x0049, 0x0044, 0x0050, 0x0010,
0x0058, 0x0058, 0x005E, 0x004C, 0x003E
};
/****************************************************************************
* MaResMgr_GetResourceInfo
*
* Function:
* Gets the currenet mapping of resources.
* Argument:
* None
* Return:
* Pointer to the resource information structure.
*
****************************************************************************/
PMA_RESOURCE_INFO MaResMgr_GetResourceInfo( void )
{
MARESMGR_DBGMSG((" MaResMgr_GetResourceInfo:\n"));
return &ma_resource_info;
}
/****************************************************************************
* MaResMgr_GetDefWaveAddress
*
* Function:
* Get internal memory address of specified wave data.
* Argument:
* wave_id wave id number (0..6)
* Return:
* > 0 internal memory address of specified wave data.
* 0 no entry
* < 0 error code
*
****************************************************************************/
SINT32 MaResMgr_GetDefWaveAddress
(
UINT8 wave_id /* wave id */
)
{
SINT32 result;
MARESMGR_DBGMSG((" MaResMgr_GetDefWaveAddress: wave_id=%d ->", wave_id));
if ( wave_id >= MA_MAX_ROM_WAVE ) return MASMW_ERROR_ARGUMENT;
result = (SINT32)ma_rom_wave_address[wave_id];
MARESMGR_DBGMSG((" %04lX\n", result));
return result;
}
/****************************************************************************
* MaResMgr_GetDefVoiceAddress
*
* Function:
* Get internal memory address of specified timber.
* Argument:
* prog program number(0..127: melody timbers, 128..255: drum timbers)
* Return:
* > 0 internal memory address of specified timber.
* 0 no entry
* < 0 error code
*
****************************************************************************/
SINT32 MaResMgr_GetDefVoiceAddress
(
UINT8 prog /* program number */
)
{
SINT32 result;
MARESMGR_DBGMSG((" MaResMgr_GetDefVoiceAddress: prog=%d ->", prog));
if ( prog < 128 )
{
/* melody */
result = (SINT32)( MA_NORMAL_ROM_ADDRESS + ( prog * 16 ) );
}
else
{
prog -= 128;
/* drum */
if ( ( prog < MA_MIN_ROM_DRUM ) || ( MA_MAX_ROM_DRUM < prog ) )
{
result = (SINT32)(0);
}
else
{
result = (SINT32)( MA_DRUM_ROM_ADDRESS + ( ( prog - MA_MIN_ROM_DRUM ) * 16 ) );
}
}
MARESMGR_DBGMSG((" %04lX\n", result));
return result;
}
/****************************************************************************
* MaResMgr_GetDefVoiceSynth
*
* Function:
* Get the voice type of specified timber.
* Argument:
* prog program number(0..127: melody timbers, 128..255: drum timbers)
* Return:
* > 0 voice type of specified timber (1:FM, 2:WT).
* 0 no entry
* < 0 error code
*
****************************************************************************/
SINT32 MaResMgr_GetDefVoiceSynth
(
UINT8 prog /* program number */
)
{
SINT32 result;
MARESMGR_DBGMSG((" MaResMgr_GetDefVoiceSynth: prog=%d ->", prog));
if ( prog < 128 )
{
result = (SINT32)(1);
}
else
{
prog -= 128;
if ( ( prog < MA_MIN_ROM_DRUM ) || ( MA_MAX_ROM_DRUM < prog ) )
{
result = (SINT32)(0);
}
else
{
result = (SINT32)( ( ( ma_rom_drum_type[prog/16] >> (prog%16) ) & 0x1 ) + 1 );
}
}
MARESMGR_DBGMSG((" %lu\n", result));
return result;
}
/****************************************************************************
* MaResMgr_GetDefVoiceKey
*
* Function:
* Get the key(block:f-number) of specified timber.
* Argument:
* prog program number(0..127: melody timbers, 128..255: drum timbers)
* Return:
* > 0 internal memory address of specified timber.
* 0 no entry
* < 0 error code
*
****************************************************************************/
SINT32 MaResMgr_GetDefVoiceKey
(
UINT8 prog /* program number */
)
{
SINT32 result;
MARESMGR_DBGMSG((" MaResMgr_GetDefVoiceKey: prog=%d ->", prog));
if ( prog < 128 )
{
result = (SINT32)MASMW_ERROR;
}
else
{
prog -= 128;
if ( ( prog < MA_MIN_ROM_DRUM ) || ( MA_MAX_ROM_DRUM < prog ) )
{
result = (SINT32)(0);
}
else
{
result = (SINT32)ma_rom_drum_key[prog - MA_MIN_ROM_DRUM];
}
}
MARESMGR_DBGMSG((" %ld\n", result));
return result;
}
/****************************************************************************
* MaResMgr_RegStreamAudio
*
* Function:
* Regist the wave data for stream audio.
* Argument:
* wave_id wave id
* format wave format
* wave_ptr pointer to the wave data for stream audio
* wave_size size of the wave data for stream audio
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_RegStreamAudio
(
UINT8 wave_id, /* wave id */
UINT8 format, /* wave format */
UINT8 * wave_ptr, /* pointer to the wave data */
UINT32 wave_size /* size of the wave data */
)
{
MARESMGR_DBGMSG((" MaResMgr_RegStreamAudio: id=%d ptr=%p sz=%ld\n", wave_id, wave_ptr, wave_size));
/* check arugment */
if ( wave_id > MASMW_MAX_WAVEID ) return MASMW_ERROR_ARGUMENT;
if ( wave_ptr == NULL ) return MASMW_ERROR_ARGUMENT;
if ( wave_size == 0 ) return MASMW_ERROR_ARGUMENT;
ma_resource_info.stream_audio[wave_id].format = format;
ma_resource_info.stream_audio[wave_id].wave_ptr = wave_ptr;
ma_resource_info.stream_audio[wave_id].wave_size = wave_size;
ma_resource_info.stream_audio[wave_id].seek_pos = (UINT32)0;
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_DelStreamAudio
*
* Function:
* Delete the wave data for stream audio.
* Argument:
* wave_id wave id
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_DelStreamAudio
(
UINT8 wave_id /* wave id */
)
{
MARESMGR_DBGMSG((" MaResMgr_DelStreamAudio: id=%d\n", wave_id));
/* check arugment */
if ( wave_id > MASMW_MAX_WAVEID ) return MASMW_ERROR_ARGUMENT;
ma_resource_info.stream_audio[wave_id].wave_ptr = NULL;
ma_resource_info.stream_audio[wave_id].wave_size = 0;
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_SetStreamSeekPos
*
* Function:
* Set seek point of stream.
* Argument:
* wave_id wave id (0..31)
* seek_pos seek point (byte)
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_SetStreamSeekPos
(
UINT8 wave_id, /* wave id */
UINT32 seek_pos /* seek point */
)
{
MARESMGR_DBGMSG((" MaResMgr_SetStreamSeekPos: id=%d pos=%ld\n", wave_id, seek_pos));
/* check arguments */
if ( wave_id > MASMW_MAX_WAVEID ) return MASMW_ERROR_ARGUMENT;
if ( seek_pos > ma_resource_info.stream_audio[wave_id].wave_size )
{
return MASMW_ERROR_ARGUMENT;
}
/* regist seek point */
ma_resource_info.stream_audio[wave_id].seek_pos = seek_pos;
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_GetStreamAudioInfo
*
* Function:
* return speciefied stream audio information
* Argument:
* wave_id wave id
* format wave format
* wave_ptr pointer to the wave data for stream audio
* wave_size size of the wave data for stream audio
* seek_pos seek point of stream
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_GetStreamAudioInfo
(
UINT8 wave_id, /* wave id */
UINT8 * format, /* format */
UINT8 ** wave_ptr, /* pointer to the wave data */
UINT32 * wave_size, /* size of the wave data */
UINT32 * seek_pos /* seek point */
)
{
MARESMGR_DBGMSG((" MaResMgr_GetStreamAudioInfo: wave_id=%d\n", wave_id));
if ( wave_id > MASMW_MAX_WAVEID ) return MASMW_ERROR_ARGUMENT;
*format = ma_resource_info.stream_audio[wave_id].format;
*wave_ptr = ma_resource_info.stream_audio[wave_id].wave_ptr;
*wave_size = ma_resource_info.stream_audio[wave_id].wave_size;
*seek_pos = ma_resource_info.stream_audio[wave_id].seek_pos;
/* reset seek point */
ma_resource_info.stream_audio[wave_id].seek_pos = 0;
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_AllocStreamAudio
*
* Function:
* Allocate the specified stream audio resources.
* Argument:
* sa_map bit mapping of Stream Audio resources to allocate.
* Return:
* 0 success
* < 0 error code
*
****************************************************************************/
SINT32 MaResMgr_AllocStreamAudio
(
UINT32 sa_map /* stream audio id */
)
{
SINT32 result;
static UINT32 res_map[4] = { 0x00000000, 0x00000080, 0x00000060, 0x000000C0 };
MARESMGR_DBGMSG((" MaResMgr_AllocStreamAudio: sa_map=%08lX\n", sa_map));
if ( sa_map == 0x00000000 ) return MASMW_SUCCESS;
if ( ( sa_map & MA_SA_MAP_MASK ) != sa_map )
{
MARESMGR_DBGMSG(("Illegal sa_map value.\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( ( ma_resource_info.sa_map & sa_map ) != 0 )
{
MARESMGR_DBGMSG(("can't alloc stream audio\n"));
return MASMW_ERROR_RESOURCE_OVER;
}
result = MaResMgr_AllocWtVoice( res_map[sa_map] );
if ( result != MASMW_SUCCESS ) return result;
result = MaResMgr_AllocRam( res_map[sa_map] );
if ( result != MASMW_SUCCESS )
{
MaResMgr_FreeWtVoice( res_map[sa_map] );
return result;
}
result = MaResMgr_AllocSoftInt( sa_map );
if ( result != MASMW_SUCCESS )
{
MaResMgr_FreeWtVoice( res_map[sa_map] );
MaResMgr_FreeRam( res_map[sa_map] );
return result;
}
result = MaResMgr_AllocTimer( 1, 0x1B, 20, 0, 0 ); /* 0.999 * 20 [ms] */
if ( result != MASMW_SUCCESS )
{
MaResMgr_FreeWtVoice( res_map[sa_map] );
MaResMgr_FreeRam( res_map[sa_map] );
MaResMgr_FreeSoftInt( sa_map );
return result;
}
ma_resource_info.sa_map |= sa_map;
MARESMGR_DBGMSG((" -> sa_map=%08lX\n", ma_resource_info.sa_map));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -