Submit initial patch from FS#12176. Adds support for several new game music formats...
[kugel-rb.git] / apps / codecs / libgme / emu2413.h
blob9ee4513ff32b7984556ac2507596ca782335b934
1 #ifndef _EMU2413_H_
2 #define _EMU2413_H_
4 #include "blargg_common.h"
5 #include "emutypes.h"
7 #ifdef EMU2413_DLL_EXPORTS
8 #define EMU2413_API __declspec(dllexport)
9 #elif defined(EMU2413_DLL_IMPORTS)
10 #define EMU2413_API __declspec(dllimport)
11 #else
12 #define EMU2413_API
13 #endif
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
19 #define AUDIO_MONO_BUFFER_SIZE 1024
21 #define PI 3.14159265358979323846
23 enum OPLL_TONE_ENUM {OPLL_2413_TONE=0, OPLL_VRC7_TONE=1, OPLL_281B_TONE=2} ;
25 /* voice data */
26 typedef struct __OPLL_PATCH {
27 e_uint32 TL,FB,EG,ML,AR,DR,SL,RR,KR,KL,AM,PM,WF ;
28 } OPLL_PATCH ;
30 /* slot */
31 typedef struct __OPLL_SLOT {
33 OPLL_PATCH *patch;
35 e_int32 type ; /* 0 : modulator 1 : carrier */
37 /* OUTPUT */
38 e_int32 feedback ;
39 e_int32 output[2] ; /* Output value of slot */
41 /* for Phase Generator (PG) */
42 e_uint16 *sintbl ; /* Wavetable */
43 e_uint32 phase ; /* Phase */
44 e_uint32 dphase ; /* Phase increment amount */
45 e_uint32 pgout ; /* output */
47 /* for Envelope Generator (EG) */
48 e_int32 fnum ; /* F-Number */
49 e_int32 block ; /* Block */
50 e_int32 volume ; /* Current volume */
51 e_int32 sustine ; /* Sustine 1 = ON, 0 = OFF */
52 e_uint32 tll ; /* Total Level + Key scale level*/
53 e_uint32 rks ; /* Key scale offset (Rks) */
54 e_int32 eg_mode ; /* Current state */
55 e_uint32 eg_phase ; /* Phase */
56 e_uint32 eg_dphase ; /* Phase increment amount */
57 e_uint32 egout ; /* output */
59 } OPLL_SLOT ;
61 /* Mask */
62 #define OPLL_MASK_CH(x) (1<<(x))
63 #define OPLL_MASK_HH (1<<(9))
64 #define OPLL_MASK_CYM (1<<(10))
65 #define OPLL_MASK_TOM (1<<(11))
66 #define OPLL_MASK_SD (1<<(12))
67 #define OPLL_MASK_BD (1<<(13))
68 #define OPLL_MASK_RHYTHM ( OPLL_MASK_HH | OPLL_MASK_CYM | OPLL_MASK_TOM | OPLL_MASK_SD | OPLL_MASK_BD )
70 /* opll */
71 typedef struct __OPLL {
73 e_uint32 adr ;
74 e_int32 out ;
76 #ifndef EMU2413_COMPACTION
77 e_uint32 realstep ;
78 e_uint32 oplltime ;
79 e_uint32 opllstep ;
80 e_int32 prev, next ;
81 e_int32 sprev[2],snext[2];
82 e_uint32 pan[16];
83 #endif
85 /* Register */
86 e_uint8 reg[0x40] ;
87 e_int32 slot_on_flag[18] ;
89 /* Pitch Modulator */
90 e_uint32 pm_phase ;
91 e_int32 lfo_pm ;
93 /* Amp Modulator */
94 e_int32 am_phase ;
95 e_int32 lfo_am ;
97 e_uint32 quality;
99 /* Noise Generator */
100 e_uint32 noise_seed ;
102 /* Channel Data */
103 e_int32 patch_number[9];
104 e_int32 key_status[9] ;
106 /* Slot */
107 OPLL_SLOT slot[18] ;
109 /* Voice Data */
110 OPLL_PATCH patch[19*2] ;
111 e_int32 patch_update[2] ; /* flag for check patch update */
113 e_uint32 mask ;
114 e_uint32 current_mask;
115 e_uint32 status;
117 e_uint32 internal_mute;
118 e_int16 buffer[AUDIO_MONO_BUFFER_SIZE];
119 } OPLL ;
121 /* Create Object */
122 EMU2413_API void OPLL_new(OPLL *, e_uint32 clk, e_uint32 rate) ;
123 EMU2413_API void OPLL_delete(OPLL *) ;
125 /* Setup */
126 EMU2413_API void OPLL_reset(OPLL *) ;
127 EMU2413_API void OPLL_reset_patch(OPLL *, e_int32) ;
128 EMU2413_API void OPLL_set_rate(OPLL *opll, e_uint32 r) ;
129 EMU2413_API void OPLL_set_quality(OPLL *opll, e_uint32 q) ;
130 EMU2413_API void OPLL_set_pan(OPLL *, e_uint32 ch, e_uint32 pan);
131 EMU2413_API void OPLL_set_internal_mute(OPLL *, e_uint32 mute);
132 EMU2413_API e_uint32 OPLL_is_internal_muted(OPLL *);
134 /* Port/Register access */
135 EMU2413_API void OPLL_writeIO(OPLL *, e_uint32 reg, e_uint32 val); ICODE_ATTR
136 EMU2413_API void OPLL_writeReg(OPLL *, e_uint32 reg, e_uint32 val); ICODE_ATTR
137 EMU2413_API e_uint32 OPLL_read(OPLL *, e_uint32 port);
139 /* Synthsize */
140 EMU2413_API e_int16 OPLL_calc(OPLL *) ; ICODE_ATTR
141 EMU2413_API void OPLL_calc_stereo(OPLL *, e_int32 out[2]) ; ICODE_ATTR
142 EMU2413_API e_int16 *OPLL_update_buffer(OPLL *, e_uint32 length) ; ICODE_ATTR
144 /* Misc */
145 EMU2413_API void OPLL_setPatch(OPLL *, const e_uint8 *dump) ;
146 EMU2413_API void OPLL_copyPatch(OPLL *, e_int32, OPLL_PATCH *) ;
147 EMU2413_API void OPLL_forceRefresh(OPLL *) ;
148 /* Utility */
149 EMU2413_API void OPLL_dump2patch(const e_uint8 *dump, OPLL_PATCH *patch) ;
150 EMU2413_API void OPLL_patch2dump(const OPLL_PATCH *patch, e_uint8 *dump) ;
151 EMU2413_API void OPLL_getDefaultPatch(e_int32 type, e_int32 num, OPLL_PATCH *) ;
153 /* Channel Mask */
154 EMU2413_API e_uint32 OPLL_setMask(OPLL *, e_uint32 mask) ;
155 EMU2413_API e_uint32 OPLL_toggleMask(OPLL *, e_uint32 mask) ;
157 #define dump2patch OPLL_dump2patch
159 #ifdef __cplusplus
161 #endif
163 #endif