libchk_stl.h 15.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
/*======================================================================*/
/*		NuSystem						*/
/*		libchk_stl.h						*/
/*									*/
/*		Copyright (C) 1999, NINTENDO Co,Ltd.			*/
/*									*/
/*======================================================================*/

#ifndef _LIBCHK_STL_H_
#define _LIBCHK_STL_H_
#ifndef N_AUDIO
#define N_AUDIO
#endif

/*--------------------------------------*/
/* SYNTHESIZER AND PLAYER DEFINES	*/
/*--------------------------------------*/
#define NU_AU_STL_CHANNELS	24
#define NU_AU_STL_UPDATE_MAX	256
#define NU_AU_STL_FIFO_LENGTH	64
#define NU_AU_STL_CLIST_LEN	0x800
#define NU_AU_STL_OUTPUT_RATE	32000

/*--------------------------------------*/
/* AUDIO DMA DEFINE			*/
/*--------------------------------------*/
#define	NU_AU_STL_DMA_BUFFER_NUM	64	/* DMA転送バッファ数	*/
#define	NU_AU_STL_DMA_BUFFER_SIZE	1024    /* DMAバッファサイズ	*/

/*--------------------------------------*/
/* AUDIO HEAP DEFINE			*/
/*--------------------------------------*/
#define NU_AU_STL_HEAP_SIZE	0x50000	/* デフォルトのHEAPサイズ */
#define NU_AU_STL_HEAP_ADDR	(NU_GFX_FRAMEBUFFER_ADDR - NU_AU_STL_HEAP_SIZE)

/*--------------------------------------*/
/* USERS DATA DEFINE			*/
/*--------------------------------------*/
#define NU_AU_STL_SONG_SIZE	0x4000
#define NU_AU_STL_SAMPLE_SIZE	0x4000
#define NU_AU_STL_SE_SIZE	0x4000

/*--------------------------------------*/
/* SYNTHE DEFINE			*/
/*--------------------------------------*/
#define	NU_AU_SYN_VVOICE_MAX	64	/* 最大仮想ボイス数(実は未使用) */
#define NU_AU_SYN_PVOICE_MAX	32	/* 最大物理ボイス数 */
#define NU_AU_SYN_UPDATE_MAX	128	/*シンセサイザのパラメータ更新最大数 */
#define	NU_AU_SYN_HEAP_SIZE	(144+NU_AU_SYN_PVOICE_MAX*432+32*NU_AU_SYN_UPDATE_MAX+0x2000)	/* reference for you */

/*--------------------------------------*/
/* AUDIO DMA DEFINE			*/
/*--------------------------------------*/
#define	NU_AU_DMA_BUFFER_NUM	64	/* DMA転送バッファ数	*/
#define	NU_AU_DMA_BUFFER_SIZE	1024    /* DMAバッファサイズ	*/
#define NU_AU_BUFFER_USE_FRAME  1	/* DMABufferをクリアーするフレーム間隔 */

/*--------------------------------------*/
/* SOUND DEFINE				*/
/*--------------------------------------*/
#define	NU_AU_MGR_THREAD_PRI	70
#define	NU_AU_MGR_THREAD_ID	6
#define NU_AU_STACK_SIZE	0x2000
#define	NU_AU_CLIST_LEN		0x800
#define	NU_AU_CLIST_SIZE	(NU_AU_CLIST_LEN*sizeof(Acmd))    /* コマンドリストのバッファサイズ */	/* reference for you */

#define	NU_AU_OUTPUT_RATE	32000   /* 周波数設定 */
#define	NU_AU_MESG_MAX		8

#ifdef N_AUDIO
#define	NU_AU_AUDIO_SAMPLES	184	/* サンプル数は184の倍数 */
#else
#define	NU_AU_AUDIO_SAMPLES	16	/* サンプル数は16の倍数 */
#endif	/* N_AUDIO */

#define NU_AU_AUDIO_EXTRASMP	0	/* サンプル数の拡張分	*/

#define NU_AU_TASK_STOP		0	/* オーディオタスク実行停止 */
#define NU_AU_TASK_RUN		1	/* オーディオタスク実行可   */

#define NU_AU_AI_FIFO_MSG	0x100	/* AIイベントメッセージ	*/
#define NU_AU_AI_DEBUG_MSG	0x1000	/* AIデバッグ用		*/
    
/*--------------------------------------*/
/* DEBUG & PERFORMANCE			*/
/*--------------------------------------*/
#define	NU_AU_DEBUG_NORMAL	0x00000001	/* warning & error 	*/
#define	NU_AU_DEBUG_DISABLEDMA	0x00010000	/* disable dma callback	*/
#define	NU_AU_DEBUG_DISABLEAI	0x00020000	/* disable set AI	*/
#define	NU_AU_DEBUG_DISABLETASK	0x00040000	/* disable task		*/
#define	NU_AU_DEBUG_FIFOOFF	0x00080000	/* FIFO EVENT OFF	*/
#define	NU_AU_DEBUG_RETRACEOFF	0x00100000	/* RETRACE EVENT OFF	*/
    
#define NU_AU_DEBUG_NODMABUF	0x00000001	/* No DMA Buffer 	*/
#define NU_AU_DEBUG_ACMDBUFOVER 0x00000002	/* Acmd buffer is small */
#define NU_AU_DEBUG_DMABUFSIZE	0x00000004	/* dma buffer size is small */
#define	NU_AU_DEBUG_DMANOTCOMPLETE    0x00000008 /* dma not completed 	*/

#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)

#include <ultra64.h>
#include <internal_sc.h>
#include <internal_sc_sn.h>
#include <nusys.h>

/*--------------------------------------*/
/* audio typedef			*/
/*--------------------------------------*/
/*--------------------------------------*/
/* DMA BUFFER STRUCT			*/
/*--------------------------------------*/
typedef struct {
    ALLink	node;		/* リンクリストポインタ */
    s32		startAddr;	/* データのROM内でのアドレス */
    s32		frameCnt;	/* バッファを残しておくフレームカウンタ */
    char*	ptr;		/* バッファへのポインタ値 */
} NUDMABuffer;
/*--------------------------------------*/
/* sequence playerのDMA callback	*/
/*   ルーチンで使用する DMA status	*/
/* DMABufferの使用状態を格納する構造体	*/
/*--------------------------------------*/
typedef struct {
    u8		initialized;  /* すでに初期化されているかのフラグ    */
    NUDMABuffer* firstUsed;   /* 使用中のDMABufferリンクリストの先頭 */
    NUDMABuffer* firstFree;   /* 空きDMABufferリンクリストの先頭     */
} NUDMAState;


/*--------------------------------------*/
/* CALL BACK Function	typedef		*/
/*--------------------------------------*/
typedef void (*NUAuPreNMIFunc)(NUScMsg,u32);	/* PRENMIコールバック関数 */
typedef void (*NUAuMgrFunc)(void);		/* Acmdコールバック関数 */

/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* extern variables 							*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/    
/*--------------------------------------*/
/*  audio variables 			*/
/*--------------------------------------*/

/* from nuaudma.c */
extern OSMesgQueue	nuAuDmaMesgQ;
extern OSMesg*		nuAuDmaMesgBuf;
extern OSIoMesg*	nuAuDmaIOMesgBuf;

extern NUDMAState	nuAuDmaState;
extern NUDMABuffer*	nuAuDmaBuf;
extern s16		nuAuDmaBufNum;
extern s16		nuAuDmaBufSize;
extern u32		nuAuDmaDisableFlag;	/* サンプルをDMA転送する必要があるか */

/* from nuauheap.c */
extern ALHeap		nuAuHeap;		/* Heap構造体 */

/* from nuaumgrconfig.c */
extern ALSynConfig	nuAuSynConfig;

/* from nuaumgrparams.c */
extern u64*		nuAuMgrStack;
extern NUScTask		nuAuTask;		/* オーディオタスクバッファ */
extern s16*		nuAuBuffer_ptr[];	/* オーディオバッファ */
extern NUScClient	nuAuClient;
extern OSThread		nuAuMgrThread;
extern u32		nuAuFrameCounter;	/* フレームカウンタ */
extern ALGlobals	nuAuGlobal;
extern NUAuPreNMIFunc	nuAuPreNMIFunc;
extern NUAuMgrFunc	nuAuMgrFunc;
extern OSMesgQueue	nuAuMesgQ;	/* オーディオマネージャのキュー	*/
extern u32		nuAuAcmdLen;
extern s16		nuAuFrameSampleSize;	/* 1度に作成するサンプル数 */
extern s16		nuAuExtraSampleSize;	/* 余剰サンプル数 */
extern u8		nuAuTaskStop;
extern u8		nuAuPreNMI;
extern u8		nuAuRetraceCount;

extern u32		nuAuDebFlag;
extern u32		nuAuDebStatus;		/* 状態フラグ		*/
extern u32		nuAuDebDmaCount;	/* 総PI-DMA数		*/
extern u32		nuAuDebDmaFrame;	/* DMA数計測カウンタ	*/
extern u32		nuAuDebDmaMax;	/* 最大PI-DMA数	*/
extern u32		nuAuDebDmaBufMaxUse;/* 最大DMAバッファ使用数 */
extern u32		nuAuDebDmaCallbackCount;/* 総DMAコールバック数	*/
extern u32		nuAuDebDmaCallbackFrame;/* DMAコールバック数	*/
extern u32		nuAuDebDmaCallbackMax; /* 最大DMAコールバック数 */
extern u32		nuAuDebAcmdLenMax;	/* オーディオコマンドリストの最大値 */
extern u32		nuAuDebDmaLengthFrame; /* 必要サンプル長 */
extern u32		nuAuDebDmaLengthMax; /* 最大必要サンプル長 */

/*----------------------------------------------------------------------*/    
/*----------------------------------------------------------------------*/
/* Global Function 							*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*--------------------------------------*/
/* audio manager function		*/
/*--------------------------------------*/
extern s32 nuAuMgrInit(void* heap_ptr, u32 size, ALSynConfig* synconfig);
extern s32 nuAuMgrInitEx(void* heap_ptr, u32 size, ALSynConfig* synConfig);

extern void nuAuPreNMIFuncSet(NUAuPreNMIFunc func);
extern void nuAuMgrFuncSet(NUAuMgrFunc func);
extern ALDMAproc nuAuDmaNew(NUDMAState **state);
extern void nuAuCleanDMABuffers(void);

extern void nuAuHeapInit(ALHeap* hp, u8* base, s32 len);
extern void* nuAuHeapAlloc(s32 length);
extern s32 nuAuHeapGetFree(void);
extern s32 nuAuHeapGetUsed(void);

/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* MACRO	 							*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/

/* コールバック関数の削除 */
#define nuAuPreNMIFuncRemove()	nuAuPreNMIFuncSet(NULL)
#define nuAuMgrFuncRemove()	nuAuMgrFuncSet(NULL)

/*----------------------------------------------------------------------*/    
#include <sched.h>

/* --------- MUSIC PLAYER API TYPEDEFS --------- */

/* audio manager and synthesizer initialize function */
typedef void	*(*LIBMUSinit_audio)	(void *);

/* configuration */
typedef struct 
{
    u32		control_flag;

    u32 	channels;
//    void	*sched;
    u32		thread_priority;
    u8		*heap;
    u32		heap_length;
    void	*audio_heap;

    u8		*ptr;
    u8		*wbk;

    void	*default_fxbank;

    u32		fifo_length;

    u32		fxtype;

    LIBMUSinit_audio syn_init_func;
    u32		syn_updates;
    u32		syn_output_rate;
    u32		syn_rsp_cmds;
    u32		syn_retraceCount;
    u32		syn_num_dma_bufs;
    u32		syn_dma_buf_size;

// Special Addition
//    OSPiHandle	*diskrom_handle;
} musConfig;

/* enabled/disable flag */
typedef enum
{
    MUSBOOL_OFF,
    MUSBOOL_ON
} musBool;

/* task descriptor */
typedef struct
{
    u64		*data;		/* address of Acmd list		*/
    s32		data_size;	/* size of Acmd list		*/
    u64		*ucode;		/* address of microcode code	*/
    u64		*ucode_data;	/* address of microcode data	*/
} musTask;

/* handle type */
typedef u32	musHandle;

/* marker callback function */
typedef void	(*LIBMUScb_marker)	(musHandle, s32);

/* scheduler support callback functions */
typedef void	(*LIBMUScb_install)	(void);
typedef OSScMsg	*(*LIBMUScb_waitframe)	(void); // yutaka
typedef void 	(*LIBMUScb_dotask)	(musTask *);

/* scheduler support callback list */
typedef struct
{
    LIBMUScb_install	install;	/* called when thread starts	*/
    LIBMUScb_waitframe	waitframe;	/* called to wait for vsync message */
    LIBMUScb_dotask	dotask;		/* called to process RSP task	*/
} musSched;


/* --------- MUSIC PLAYER API MACROS --------- */

/* control flags */
#define MUSCONTROL_RAM	(1<<0)

/* channel types flags */
#define MUSFLAG_EFFECTS	1
#define MUSFLAG_SONGS	2


/* --------- MUSIC PLAYER GLOBAL VALUES --------- */
extern s32 mus_random_seed;

/* scheduler support, if you use the library supported traditional audio manager */
extern OSSched mus_sched;

/* --------- MUSIC PLAYER API FUNCTION PROTOTYPES --------- */

/* initialise */
extern s32 MusPlayerInitialize		(musConfig *config);

/* audio configuration */
extern s32 MusSetFxType			(s32 fxtype);
extern s32 MusSetSongFxChange		(musBool onoff);

/* set master volume levels */
extern void MusSetMasterVolume		(u32 flags, s32 volume);

/* start songs and sound effects */
extern musHandle MusStartSong		(void *addr);
extern musHandle MusStartSongFromMarker	(void *addr, s32 marker);
extern musHandle MusStartEffect		(s32 number);
extern musHandle MusStartEffect2	(s32 number, s32 volume, s32 pan , s32 restartflag, s32 priority);

/* stop and query sound types */
extern void MusStop			(u32 flags, s32 speed);
extern s32  MusAsk			(u32 flags);

/* handle based processing */
extern s32 MusHandleAsk			(musHandle handle);
extern s32 MusHandleStop		(musHandle handle, s32 speed);
extern s32 MusHandleSetVolume		(musHandle handle, s32 volume);
extern s32 MusHandleSetPan		(musHandle handle, s32 pan);
extern s32 MusHandleSetFreqOffset	(musHandle handle, f32 offset);
extern s32 MusHandleSetTempo		(musHandle handle, s32 tempo);
extern s32 MusHandleSetReverb		(musHandle handle, s32 reverb);
extern s32 MusHandlePause		(musHandle handle);
extern s32 MusHandleUnPause		(musHandle handle);
extern void *MusHandleGetPtrBank	(musHandle handle);

/* sample bank support */
extern void MusPtrBankInitialize	(void *pbank, void *wbank);
extern void *MusPtrBankSetSingle	(void *ipbank);
extern void MusPtrBankSetCurrent	(void *ipbank);
extern void *MusPtrBankGetCurrent	(void);

/* sound effect bank support */
extern void MusFxBankInitialize		(void *fxbank);
extern void MusFxBankSetSingle		(void *ifxbank);
extern void MusFxBankSetCurrent		(void *ifxbank);
extern void *MusFxBankGetCurrent	(void);
extern s32  MusFxBankNumberOfEffects	(void *ifxbank);
extern void MusFxBankSetPtrBank		(void *ifxbank, void *ipbank);
extern void *MusFxBankGetPtrBank	(void *ifxbank);
extern void MusFxBankSetSingle		(void *ifxbank);

/* marker callback support */
extern void MusSetMarkerCallback	(void *callback);

/* wave list lookup in song header */
extern u32 MusHandleWaveCount		(musHandle handle);
extern u16 *MusHandleWaveAddress	(musHandle handle);

/* scheduler support, if you use the library supported traditional audio manager */
extern void MusSetScheduler		(musSched *sched_list);

/* intialization fuction, if you use the library supported traditional audio manager */
extern s32  *MusIntialize			(musConfig *);
extern void *MusAudioManagerInitialize		(void *);

/* macros to support previous sample bank functions - use is not recommended! */
#define MusBankInitialize(pbank,wbank)	\
	MusPtrBankInitialize(pbank,wbank)

#define MusBankStartSong(ipbank, addr)	\
	MusStartSong((addr)==(void *)MusPtrBankSetSingle(ipbank) ? (addr):(addr))

#define MusBankStartEffect(ipbank, number) \
	MusStartEffect((number)==(s32)MusPtrBankSetSingle(ipbank) ? (number):(number))

#define MusBankStartEffect2(ipbank, number, volume, pan, restartflag, priority) \
	MusStartEffect2((number)==(s32)MusPtrBankSetSingle(ipbank) ? (number):(number), \
			volume, pan, restartflag, priority)



/* --- DEVELOPEMENT API FUNCTION PROTOTYPES --- */

/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* extern variables 							*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*--------------------------------------*/
/*  audio variables 			*/
/*--------------------------------------*/
extern musConfig nuAuStlConfig;

/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* Global Function 							*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
extern void *nuAuStlMgrInit(void *config);
extern void *nuAuStlMgrInitEx(void *config);

extern void nuAuStlPreNMIProc(NUScMsg mesg_type, u32 frameCounter);

/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* MACRO	 							*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
#define nuAuPreNMIProc(mesg_type, frameCounter) \
    nuAuStlPreNMIProc(mesg_type, frameCounter)

/*----------------------------------------------------------------------*/    
#endif  /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
#ifdef _LANGUAGE_C_PLUS_PLUS
}
#endif
#endif /* _LIBCHK_STL_H__ */