Merge pull request #569 from gameblabla/gte_stalling_libretro
[pcsx_rearmed.git] / plugins / dfsound / externals.h
... / ...
CommitLineData
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
18#ifndef __P_SOUND_EXTERNALS_H__\r
19#define __P_SOUND_EXTERNALS_H__\r
20\r
21#include <stdint.h>\r
22\r
23/////////////////////////////////////////////////////////\r
24// generic defines\r
25/////////////////////////////////////////////////////////\r
26\r
27#ifdef __GNUC__\r
28#define noinline __attribute__((noinline))\r
29#define unlikely(x) __builtin_expect((x), 0)\r
30#else\r
31#define noinline\r
32#define unlikely(x) x\r
33#endif\r
34#if defined(__GNUC__) && !defined(_TMS320C6X)\r
35#define preload __builtin_prefetch\r
36#else\r
37#define preload(...)\r
38#endif\r
39\r
40#define PSE_LT_SPU 4\r
41#define PSE_SPU_ERR_SUCCESS 0\r
42#define PSE_SPU_ERR -60\r
43#define PSE_SPU_ERR_NOTCONFIGURED PSE_SPU_ERR - 1\r
44#define PSE_SPU_ERR_INIT PSE_SPU_ERR - 2\r
45#ifndef max\r
46#define max(a,b) (((a) > (b)) ? (a) : (b))\r
47#define min(a,b) (((a) < (b)) ? (a) : (b))\r
48#endif\r
49\r
50////////////////////////////////////////////////////////////////////////\r
51// spu defines\r
52////////////////////////////////////////////////////////////////////////\r
53\r
54// num of channels\r
55#define MAXCHAN 24\r
56\r
57// note: must be even due to the way reverb works now\r
58#define NSSIZE ((44100 / 50 + 16) & ~1)\r
59\r
60///////////////////////////////////////////////////////////\r
61// struct defines\r
62///////////////////////////////////////////////////////////\r
63\r
64enum ADSR_State {\r
65 ADSR_ATTACK = 0,\r
66 ADSR_DECAY = 1,\r
67 ADSR_SUSTAIN = 2,\r
68 ADSR_RELEASE = 3,\r
69};\r
70\r
71// ADSR INFOS PER CHANNEL\r
72typedef struct\r
73{\r
74 unsigned char State:2; // ADSR_State\r
75 unsigned char AttackModeExp:1;\r
76 unsigned char SustainModeExp:1;\r
77 unsigned char SustainIncrease:1;\r
78 unsigned char ReleaseModeExp:1;\r
79 unsigned char AttackRate;\r
80 unsigned char DecayRate;\r
81 unsigned char SustainLevel;\r
82 unsigned char SustainRate;\r
83 unsigned char ReleaseRate;\r
84 int EnvelopeVol;\r
85} ADSRInfoEx;\r
86 \r
87///////////////////////////////////////////////////////////\r
88\r
89// Tmp Flags\r
90\r
91// used for debug channel muting\r
92#define FLAG_MUTE 1\r
93\r
94// used for simple interpolation\r
95#define FLAG_IPOL0 2\r
96#define FLAG_IPOL1 4\r
97\r
98///////////////////////////////////////////////////////////\r
99\r
100// MAIN CHANNEL STRUCT\r
101typedef struct\r
102{\r
103 int iSBPos; // mixing stuff\r
104 int spos;\r
105 int sinc;\r
106 int sinc_inv;\r
107\r
108 unsigned char * pCurr; // current pos in sound mem\r
109 unsigned char * pLoop; // loop ptr in sound mem\r
110\r
111 unsigned int bReverb:1; // can we do reverb on this channel? must have ctrl register bit, to get active\r
112 unsigned int bRVBActive:1; // reverb active flag\r
113 unsigned int bNoise:1; // noise active flag\r
114 unsigned int bFMod:2; // freq mod (0=off, 1=sound channel, 2=freq channel)\r
115 unsigned int prevflags:3; // flags from previous block\r
116 unsigned int bIgnoreLoop:1; // Ignore loop\r
117 int iLeftVolume; // left volume\r
118 int iRightVolume; // right volume\r
119 ADSRInfoEx ADSRX;\r
120 int iRawPitch; // raw pitch (0...3fff)\r
121} SPUCHAN;\r
122\r
123///////////////////////////////////////////////////////////\r
124\r
125typedef struct\r
126{\r
127 int StartAddr; // reverb area start addr in samples\r
128 int CurrAddr; // reverb area curr addr in samples\r
129\r
130 int VolLeft;\r
131 int VolRight;\r
132\r
133 int FB_SRC_A; // (offset)\r
134 int FB_SRC_B; // (offset)\r
135 int IIR_ALPHA; // (coef.)\r
136 int ACC_COEF_A; // (coef.)\r
137 int ACC_COEF_B; // (coef.)\r
138 int ACC_COEF_C; // (coef.)\r
139 int ACC_COEF_D; // (coef.)\r
140 int IIR_COEF; // (coef.)\r
141 int FB_ALPHA; // (coef.)\r
142 int FB_X; // (coef.)\r
143 int IIR_DEST_A0; // (offset)\r
144 int IIR_DEST_A1; // (offset)\r
145 int ACC_SRC_A0; // (offset)\r
146 int ACC_SRC_A1; // (offset)\r
147 int ACC_SRC_B0; // (offset)\r
148 int ACC_SRC_B1; // (offset)\r
149 int IIR_SRC_A0; // (offset)\r
150 int IIR_SRC_A1; // (offset)\r
151 int IIR_DEST_B0; // (offset)\r
152 int IIR_DEST_B1; // (offset)\r
153 int ACC_SRC_C0; // (offset)\r
154 int ACC_SRC_C1; // (offset)\r
155 int ACC_SRC_D0; // (offset)\r
156 int ACC_SRC_D1; // (offset)\r
157 int IIR_SRC_B1; // (offset)\r
158 int IIR_SRC_B0; // (offset)\r
159 int MIX_DEST_A0; // (offset)\r
160 int MIX_DEST_A1; // (offset)\r
161 int MIX_DEST_B0; // (offset)\r
162 int MIX_DEST_B1; // (offset)\r
163 int IN_COEF_L; // (coef.)\r
164 int IN_COEF_R; // (coef.)\r
165\r
166 int dirty; // registers changed\r
167\r
168 // MIX_DEST_xx - FB_SRC_x\r
169 int FB_SRC_A0, FB_SRC_A1, FB_SRC_B0, FB_SRC_B1;\r
170} REVERBInfo;\r
171\r
172///////////////////////////////////////////////////////////\r
173\r
174// psx buffers / addresses\r
175\r
176#define SB_SIZE (32 + 4)\r
177\r
178typedef struct\r
179{\r
180 unsigned short spuCtrl;\r
181 unsigned short spuStat;\r
182\r
183 unsigned int spuAddr;\r
184 union {\r
185 unsigned char *spuMemC;\r
186 unsigned short *spuMem;\r
187 };\r
188 unsigned char * pSpuIrq;\r
189\r
190 unsigned int cycles_played;\r
191 int decode_pos;\r
192 int decode_dirty_ch;\r
193 unsigned int bSpuInit:1;\r
194 unsigned int bSPUIsOpen:1;\r
195 unsigned int bMemDirty:1; // had external write to SPU RAM\r
196\r
197 unsigned int dwNoiseVal; // global noise generator\r
198 unsigned int dwNoiseCount;\r
199 unsigned int dwNewChannel; // flags for faster testing, if new channel starts\r
200 unsigned int dwChannelOn; // not silent channels\r
201 unsigned int dwChannelDead; // silent+not useful channels\r
202\r
203 unsigned char * pSpuBuffer;\r
204 short * pS;\r
205\r
206 void (CALLBACK *irqCallback)(void); // func of main emu, called on spu irq\r
207 void (CALLBACK *cddavCallback)(short, short);\r
208 void (CALLBACK *scheduleCallback)(unsigned int);\r
209\r
210 xa_decode_t * xapGlobal;\r
211 unsigned int * XAFeed;\r
212 unsigned int * XAPlay;\r
213 unsigned int * XAStart;\r
214 unsigned int * XAEnd;\r
215\r
216 unsigned int * CDDAFeed;\r
217 unsigned int * CDDAPlay;\r
218 unsigned int * CDDAStart;\r
219 unsigned int * CDDAEnd;\r
220\r
221 unsigned int XARepeat;\r
222 unsigned int XALastVal;\r
223\r
224 int iLeftXAVol;\r
225 int iRightXAVol;\r
226\r
227 SPUCHAN * s_chan;\r
228 REVERBInfo * rvb;\r
229\r
230 // buffers\r
231 int * SB;\r
232 int * SSumLR;\r
233\r
234 int pad[29];\r
235 unsigned short regArea[0x400];\r
236} SPUInfo;\r
237\r
238#define regAreaGet(ch,offset) \\r
239 spu.regArea[((ch<<4)|(offset))>>1]\r
240\r
241///////////////////////////////////////////////////////////\r
242// SPU.C globals\r
243///////////////////////////////////////////////////////////\r
244\r
245#ifndef _IN_SPU\r
246\r
247extern SPUInfo spu;\r
248\r
249void do_samples(unsigned int cycles_to, int do_sync);\r
250void schedule_next_irq(void);\r
251\r
252#define do_samples_if_needed(c, sync) \\r
253 do { \\r
254 if (sync || (int)((c) - spu.cycles_played) >= 16 * 768) \\r
255 do_samples(c, sync); \\r
256 } while (0)\r
257\r
258#endif\r
259\r
260#endif /* __P_SOUND_EXTERNALS_H__ */\r