add a thp-based huge page alloc fallback
[pcsx_rearmed.git] / plugins / dfsound / externals.h
CommitLineData
ef79bbde
P
1/***************************************************************************\r
2 externals.h - description\r
3 -------------------\r
4 begin : Wed May 15 2002\r
5 copyright : (C) 2002 by Pete Bernert\r
6 email : BlackDove@addcom.de\r
7 ***************************************************************************/\r
8/***************************************************************************\r
9 * *\r
10 * This program is free software; you can redistribute it and/or modify *\r
11 * it under the terms of the GNU General Public License as published by *\r
12 * the Free Software Foundation; either version 2 of the License, or *\r
13 * (at your option) any later version. See also the license.txt file for *\r
14 * additional informations. *\r
15 * *\r
16 ***************************************************************************/\r
17\r
908e426c 18#ifndef __P_SOUND_EXTERNALS_H__\r
19#define __P_SOUND_EXTERNALS_H__\r
20\r
ef79bbde
P
21#include <stdint.h>\r
22\r
23/////////////////////////////////////////////////////////\r
24// generic defines\r
25/////////////////////////////////////////////////////////\r
26\r
7df2c03c 27//#define log_unhandled printf\r
28#define log_unhandled(...)\r
29\r
f05d6ca2 30#ifdef __GNUC__\r
b72f17a1 31#define noinline __attribute__((noinline))\r
32#define unlikely(x) __builtin_expect((x), 0)\r
33#else\r
34#define noinline\r
35#define unlikely(x) x\r
36#endif\r
05c7cec7 37#if defined(__GNUC__) && !defined(_TMS320C6X)\r
38#define preload __builtin_prefetch\r
39#else\r
40#define preload(...)\r
41#endif\r
b72f17a1 42\r
ef79bbde
P
43#define PSE_LT_SPU 4\r
44#define PSE_SPU_ERR_SUCCESS 0\r
45#define PSE_SPU_ERR -60\r
46#define PSE_SPU_ERR_NOTCONFIGURED PSE_SPU_ERR - 1\r
47#define PSE_SPU_ERR_INIT PSE_SPU_ERR - 2\r
48#ifndef max\r
49#define max(a,b) (((a) > (b)) ? (a) : (b))\r
50#define min(a,b) (((a) < (b)) ? (a) : (b))\r
51#endif\r
52\r
53////////////////////////////////////////////////////////////////////////\r
54// spu defines\r
55////////////////////////////////////////////////////////////////////////\r
56\r
ef79bbde
P
57// num of channels\r
58#define MAXCHAN 24\r
59\r
1775933a 60// note: must be even due to the way reverb works now\r
650adfd2 61#define NSSIZE ((44100 / 50 + 16) & ~1)\r
ef79bbde
P
62\r
63///////////////////////////////////////////////////////////\r
64// struct defines\r
65///////////////////////////////////////////////////////////\r
66\r
9ad8abfa 67enum ADSR_State {\r
68 ADSR_ATTACK = 0,\r
69 ADSR_DECAY = 1,\r
70 ADSR_SUSTAIN = 2,\r
71 ADSR_RELEASE = 3,\r
72};\r
73\r
ef79bbde 74// ADSR INFOS PER CHANNEL\r
ef79bbde
P
75typedef struct\r
76{\r
9ad8abfa 77 unsigned char State:2; // ADSR_State\r
6d866bb7 78 unsigned char AttackModeExp:1;\r
79 unsigned char SustainModeExp:1;\r
80 unsigned char SustainIncrease:1;\r
81 unsigned char ReleaseModeExp:1;\r
82 unsigned char AttackRate;\r
83 unsigned char DecayRate;\r
84 unsigned char SustainLevel;\r
85 unsigned char SustainRate;\r
86 unsigned char ReleaseRate;\r
ef79bbde 87 int EnvelopeVol;\r
ef79bbde
P
88} ADSRInfoEx;\r
89 \r
90///////////////////////////////////////////////////////////\r
91\r
92// Tmp Flags\r
93\r
94// used for debug channel muting\r
95#define FLAG_MUTE 1\r
96\r
97// used for simple interpolation\r
98#define FLAG_IPOL0 2\r
99#define FLAG_IPOL1 4\r
100\r
101///////////////////////////////////////////////////////////\r
102\r
103// MAIN CHANNEL STRUCT\r
104typedef struct\r
105{\r
ef79bbde
P
106 int iSBPos; // mixing stuff\r
107 int spos;\r
108 int sinc;\r
650adfd2 109 int sinc_inv;\r
ef79bbde 110\r
ef79bbde
P
111 unsigned char * pCurr; // current pos in sound mem\r
112 unsigned char * pLoop; // loop ptr in sound mem\r
113\r
6d866bb7 114 unsigned int bReverb:1; // can we do reverb on this channel? must have ctrl register bit, to get active\r
6d866bb7 115 unsigned int bRVBActive:1; // reverb active flag\r
116 unsigned int bNoise:1; // noise active flag\r
117 unsigned int bFMod:2; // freq mod (0=off, 1=sound channel, 2=freq channel)\r
e4f075af 118 unsigned int prevflags:3; // flags from previous block\r
9601ca6d 119 unsigned int bIgnoreLoop:1; // Ignore loop\r
4ecb720e 120 unsigned int bNewPitch:1; // pitch changed\r
6183ddf9 121 unsigned int bStarting:1; // starting after keyon\r
3fc2a418 122 union {\r
123 struct {\r
124 int iLeftVolume; // left volume\r
125 int iRightVolume; // right volume\r
126 };\r
127 int iVolume[2];\r
128 };\r
6d866bb7 129 ADSRInfoEx ADSRX;\r
130 int iRawPitch; // raw pitch (0...3fff)\r
ef79bbde
P
131} SPUCHAN;\r
132\r
133///////////////////////////////////////////////////////////\r
134\r
135typedef struct\r
136{\r
137 int StartAddr; // reverb area start addr in samples\r
138 int CurrAddr; // reverb area curr addr in samples\r
139\r
140 int VolLeft;\r
141 int VolRight;\r
ef79bbde
P
142\r
143 int FB_SRC_A; // (offset)\r
144 int FB_SRC_B; // (offset)\r
145 int IIR_ALPHA; // (coef.)\r
146 int ACC_COEF_A; // (coef.)\r
147 int ACC_COEF_B; // (coef.)\r
148 int ACC_COEF_C; // (coef.)\r
149 int ACC_COEF_D; // (coef.)\r
150 int IIR_COEF; // (coef.)\r
151 int FB_ALPHA; // (coef.)\r
152 int FB_X; // (coef.)\r
153 int IIR_DEST_A0; // (offset)\r
154 int IIR_DEST_A1; // (offset)\r
155 int ACC_SRC_A0; // (offset)\r
156 int ACC_SRC_A1; // (offset)\r
157 int ACC_SRC_B0; // (offset)\r
158 int ACC_SRC_B1; // (offset)\r
159 int IIR_SRC_A0; // (offset)\r
160 int IIR_SRC_A1; // (offset)\r
161 int IIR_DEST_B0; // (offset)\r
162 int IIR_DEST_B1; // (offset)\r
163 int ACC_SRC_C0; // (offset)\r
164 int ACC_SRC_C1; // (offset)\r
165 int ACC_SRC_D0; // (offset)\r
166 int ACC_SRC_D1; // (offset)\r
167 int IIR_SRC_B1; // (offset)\r
168 int IIR_SRC_B0; // (offset)\r
169 int MIX_DEST_A0; // (offset)\r
170 int MIX_DEST_A1; // (offset)\r
171 int MIX_DEST_B0; // (offset)\r
172 int MIX_DEST_B1; // (offset)\r
173 int IN_COEF_L; // (coef.)\r
174 int IN_COEF_R; // (coef.)\r
1775933a 175\r
176 int dirty; // registers changed\r
177\r
1775933a 178 // MIX_DEST_xx - FB_SRC_x\r
7b2c4897 179 int FB_SRC_A0, FB_SRC_A1, FB_SRC_B0, FB_SRC_B1;\r
ef79bbde
P
180} REVERBInfo;\r
181\r
ef79bbde
P
182///////////////////////////////////////////////////////////\r
183\r
ef79bbde
P
184// psx buffers / addresses\r
185\r
de4a0279 186#define SB_SIZE (32 + 4)\r
187\r
3154bfab 188typedef struct\r
189{\r
190 unsigned short spuCtrl;\r
191 unsigned short spuStat;\r
ef79bbde 192\r
3154bfab 193 unsigned int spuAddr;\r
5514a050 194 union {\r
195 unsigned char *spuMemC;\r
196 unsigned short *spuMem;\r
197 };\r
3154bfab 198 unsigned char * pSpuIrq;\r
77d6fd63 199\r
3154bfab 200 unsigned int cycles_played;\r
56e500f3 201 unsigned int cycles_dma_end;\r
3154bfab 202 int decode_pos;\r
203 int decode_dirty_ch;\r
204 unsigned int bSpuInit:1;\r
205 unsigned int bSPUIsOpen:1;\r
0c1151fe 206 unsigned int bMemDirty:1; // had external write to SPU RAM\r
ef79bbde 207\r
3154bfab 208 unsigned int dwNoiseVal; // global noise generator\r
209 unsigned int dwNoiseCount;\r
210 unsigned int dwNewChannel; // flags for faster testing, if new channel starts\r
2daa7c1d 211 unsigned int dwChannelsAudible; // not silent channels\r
3154bfab 212 unsigned int dwChannelDead; // silent+not useful channels\r
ef79bbde 213\r
3154bfab 214 unsigned char * pSpuBuffer;\r
215 short * pS;\r
ef79bbde 216\r
3154bfab 217 void (CALLBACK *irqCallback)(void); // func of main emu, called on spu irq\r
7d6997de 218 void (CALLBACK *cddavCallback)(short, short);\r
3154bfab 219 void (CALLBACK *scheduleCallback)(unsigned int);\r
ef79bbde 220\r
403a6290 221 const xa_decode_t * xapGlobal;\r
3154bfab 222 unsigned int * XAFeed;\r
223 unsigned int * XAPlay;\r
224 unsigned int * XAStart;\r
225 unsigned int * XAEnd;\r
ef79bbde 226\r
3154bfab 227 unsigned int * CDDAFeed;\r
228 unsigned int * CDDAPlay;\r
229 unsigned int * CDDAStart;\r
230 unsigned int * CDDAEnd;\r
ef79bbde 231\r
3154bfab 232 unsigned int XARepeat;\r
233 unsigned int XALastVal;\r
650adfd2 234\r
3154bfab 235 int iLeftXAVol;\r
236 int iRightXAVol;\r
650adfd2 237\r
5514a050 238 SPUCHAN * s_chan;\r
05c7cec7 239 REVERBInfo * rvb;\r
5514a050 240\r
05c7cec7 241 // buffers\r
242 int * SB;\r
3bd31caf 243 int * SSumLR;\r
244\r
3154bfab 245 unsigned short regArea[0x400];\r
3154bfab 246} SPUInfo;\r
ef79bbde 247\r
a0d4a8f5 248#define regAreaGet(offset) \\r
249 spu.regArea[((offset) - 0xc00)>>1]\r
250#define regAreaGetCh(ch, offset) \\r
9601ca6d 251 spu.regArea[((ch<<4)|(offset))>>1]\r
252\r
ef79bbde 253///////////////////////////////////////////////////////////\r
3154bfab 254// SPU.C globals\r
ef79bbde
P
255///////////////////////////////////////////////////////////\r
256\r
3154bfab 257#ifndef _IN_SPU\r
ef79bbde 258\r
3154bfab 259extern SPUInfo spu;\r
ef79bbde 260\r
63a4f6b6 261void do_samples(unsigned int cycles_to, int do_sync);\r
3154bfab 262void schedule_next_irq(void);\r
54604e03 263void check_irq_io(unsigned int addr);\r
ef79bbde 264\r
6183ddf9 265#define do_samples_if_needed(c, sync, samples) \\r
3154bfab 266 do { \\r
6183ddf9 267 if (sync || (int)((c) - spu.cycles_played) >= (samples) * 768) \\r
63a4f6b6 268 do_samples(c, sync); \\r
3154bfab 269 } while (0)\r
ef79bbde
P
270\r
271#endif\r
272\r
908e426c 273#endif /* __P_SOUND_EXTERNALS_H__ */\r