]> Git Repo - qemu.git/blob - hw/audio/fmopl.h
audio: Remove INT8
[qemu.git] / hw / audio / fmopl.h
1 #ifndef FMOPL_H
2 #define FMOPL_H
3
4 #include <stdint.h>
5
6 /* --- system optimize --- */
7 /* select bit size of output : 8 or 16 */
8 #define OPL_OUTPUT_BIT 16
9
10 /* compiler dependence */
11 #ifndef OSD_CPU_H
12 #define OSD_CPU_H
13 typedef signed short    INT16;   /* signed 16bit   */
14 typedef signed int              INT32;   /* signed 32bit   */
15 #endif
16
17 #if (OPL_OUTPUT_BIT==16)
18 typedef INT16 OPLSAMPLE;
19 #endif
20 #if (OPL_OUTPUT_BIT==8)
21 typedef unsigned char  OPLSAMPLE;
22 #endif
23
24 typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
25 typedef void (*OPL_IRQHANDLER)(int param,int irq);
26 typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
27 typedef void (*OPL_PORTHANDLER_W)(int param,unsigned char data);
28 typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
29
30 /* !!!!! here is private section , do not access there member direct !!!!! */
31
32 #define OPL_TYPE_WAVESEL   0x01  /* waveform select    */
33 #define OPL_TYPE_ADPCM     0x02  /* DELTA-T ADPCM unit */
34 #define OPL_TYPE_KEYBOARD  0x04  /* keyboard interface */
35 #define OPL_TYPE_IO        0x08  /* I/O port */
36
37 /* Saving is necessary for member of the 'R' mark for suspend/resume */
38 /* ---------- OPL one of slot  ---------- */
39 typedef struct fm_opl_slot {
40         INT32 TL;               /* total level     :TL << 8            */
41         INT32 TLL;              /* adjusted now TL                     */
42         uint8_t  KSR;           /* key scale rate  :(shift down bit)   */
43         INT32 *AR;              /* attack rate     :&AR_TABLE[AR<<2]   */
44         INT32 *DR;              /* decay rate      :&DR_TALBE[DR<<2]   */
45         INT32 SL;               /* sustin level    :SL_TALBE[SL]       */
46         INT32 *RR;              /* release rate    :&DR_TABLE[RR<<2]   */
47         uint8_t ksl;            /* keyscale level  :(shift down bits)  */
48         uint8_t ksr;            /* key scale rate  :kcode>>KSR         */
49         uint32_t mul;           /* multiple        :ML_TABLE[ML]       */
50         uint32_t Cnt;           /* frequency count :                   */
51         uint32_t Incr;  /* frequency step  :                   */
52         /* envelope generator state */
53         uint8_t eg_typ; /* envelope type flag                  */
54         uint8_t evm;            /* envelope phase                      */
55         INT32 evc;              /* envelope counter                    */
56         INT32 eve;              /* envelope counter end point          */
57         INT32 evs;              /* envelope counter step               */
58         INT32 evsa;     /* envelope step for AR :AR[ksr]           */
59         INT32 evsd;     /* envelope step for DR :DR[ksr]           */
60         INT32 evsr;     /* envelope step for RR :RR[ksr]           */
61         /* LFO */
62         uint8_t ams;            /* ams flag                            */
63         uint8_t vib;            /* vibrate flag                        */
64         /* wave selector */
65         INT32 **wavetable;
66 }OPL_SLOT;
67
68 /* ---------- OPL one of channel  ---------- */
69 typedef struct fm_opl_channel {
70         OPL_SLOT SLOT[2];
71         uint8_t CON;                    /* connection type                     */
72         uint8_t FB;                     /* feed back       :(shift down bit)   */
73         INT32 *connect1;        /* slot1 output pointer                */
74         INT32 *connect2;        /* slot2 output pointer                */
75         INT32 op1_out[2];       /* slot1 output for selfeedback        */
76         /* phase generator state */
77         uint32_t  block_fnum;   /* block+fnum      :                   */
78         uint8_t kcode;          /* key code        : KeyScaleCode      */
79         uint32_t  fc;                   /* Freq. Increment base                */
80         uint32_t  ksl_base;     /* KeyScaleLevel Base step             */
81         uint8_t keyon;          /* key on/off flag                     */
82 } OPL_CH;
83
84 /* OPL state */
85 typedef struct fm_opl_f {
86         uint8_t type;                   /* chip type                         */
87         int clock;                      /* master clock  (Hz)                */
88         int rate;                       /* sampling rate (Hz)                */
89         double freqbase;        /* frequency base                    */
90         double TimerBase;       /* Timer base time (==sampling time) */
91         uint8_t address;                /* address register                  */
92         uint8_t status;         /* status flag                       */
93         uint8_t statusmask;     /* status mask                       */
94         uint32_t mode;          /* Reg.08 : CSM , notesel,etc.       */
95         /* Timer */
96         int T[2];                       /* timer counter                     */
97         uint8_t st[2];          /* timer enable                      */
98         /* FM channel slots */
99         OPL_CH *P_CH;           /* pointer of CH                     */
100         int     max_ch;                 /* maximum channel                   */
101         /* Rhythm sention */
102         uint8_t rhythm;         /* Rhythm mode , key flag */
103         OPL_PORTHANDLER_R porthandler_r;
104         OPL_PORTHANDLER_W porthandler_w;
105         int port_param;
106         OPL_PORTHANDLER_R keyboardhandler_r;
107         OPL_PORTHANDLER_W keyboardhandler_w;
108         int keyboard_param;
109         /* time tables */
110         INT32 AR_TABLE[75];     /* atttack rate tables */
111         INT32 DR_TABLE[75];     /* decay rate tables   */
112         uint32_t FN_TABLE[1024];  /* fnumber -> increment counter */
113         /* LFO */
114         INT32 *ams_table;
115         INT32 *vib_table;
116         INT32 amsCnt;
117         INT32 amsIncr;
118         INT32 vibCnt;
119         INT32 vibIncr;
120         /* wave selector enable flag */
121         uint8_t wavesel;
122         /* external event callback handler */
123         OPL_TIMERHANDLER  TimerHandler;         /* TIMER handler   */
124         int TimerParam;                                         /* TIMER parameter */
125         OPL_IRQHANDLER    IRQHandler;           /* IRQ handler    */
126         int IRQParam;                                           /* IRQ parameter  */
127         OPL_UPDATEHANDLER UpdateHandler;        /* stream update handler   */
128         int UpdateParam;                                        /* stream update parameter */
129 } FM_OPL;
130
131 /* ---------- Generic interface section ---------- */
132 #define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
133
134 FM_OPL *OPLCreate(int type, int clock, int rate);
135 void OPLDestroy(FM_OPL *OPL);
136 void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset);
137 void OPLSetIRQHandler(FM_OPL *OPL,OPL_IRQHANDLER IRQHandler,int param);
138 void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int param);
139
140 void OPLResetChip(FM_OPL *OPL);
141 int OPLWrite(FM_OPL *OPL,int a,int v);
142 unsigned char OPLRead(FM_OPL *OPL,int a);
143 int OPLTimerOver(FM_OPL *OPL,int c);
144
145 void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length);
146 #endif
This page took 0.02803 seconds and 4 git commands to generate.