1 //**************************************************************************************************
7 * Copyright (C) 2005-2013 Team XBMC
10 * This Program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This Program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with XBMC; see the file COPYING. If not, see
22 * <http://www.gnu.org/licenses/>.
29 #if defined __BORLANDC__
32 typedef unsigned char b8;
38 typedef unsigned char u8;
39 typedef unsigned short u16;
40 typedef unsigned int u32;
41 #if defined _MSC_VER || defined __BORLANDC__
42 typedef unsigned __int64 u64;
44 typedef unsigned long long int u64;
50 #if defined _MSC_VER || defined __BORLANDC__
53 typedef long long int s64;
58 typedef long double f80;
60 typedef struct DSPVoice
62 s8 volL; //Volume Left
63 s8 volR; //Volume Right
64 u16 pitch; //Pitch (rate/32000) (3.11)
65 u8 srcn; //Sound source being played back
66 u8 adsr[2]; //Envelope rates for attack, decay, and sustain
67 u8 gain; //Envelope gain (if not using ADSR)
68 s8 envx; //Current envelope height (.7)
69 s8 outx; //Current sample being output (-.7)
73 typedef struct SPCState
75 void *pRAM; //[0.0] -> APU's RAM (64k)
76 u32 _r1; //[0.4] reserved
77 u16 pc; //[0.8] Registers
82 u32 t8kHz,t64kHz; //[1.0] # of cycles left until timer increase
83 u32 t64Cnt; //[1.8] # of 64kHz ticks since emulation began
84 u32 _r2; //[1.C] reserved
85 u8 upCnt[3]; //[2.0] Up counters for counter increase
86 u8 portMod; //[2.3] Flags for in ports that have been modified
87 u8 outp[4]; //[2.4] Out ports
88 u32 _r3[2]; //[2.8] reserved
94 s8 c; //Filter coefficient
99 DSPVoice voice[8]; //Voice registers
101 struct //Global registers
104 s8 mvolL; //Main Volume Left (-.7)
105 s8 efb; //Echo Feedback (-.7)
107 s8 c0; //FIR filter coefficent (-.7)
110 s8 mvolR; //Main Volume Right (-.7)
116 s8 evolL; //Echo Volume Left (-.7)
117 u8 pmon; //Pitch Modulation on/off for each voice
122 s8 evolR; //Echo Volume Right (-.7)
123 u8 non; //Noise output on/off for each voice
128 u8 kon; //Key On for each voice
129 u8 eon; //Echo on/off for each voice
134 u8 kof; //Key Off for each voice (instantiates release mode)
135 u8 dir; //Page containing source directory (wave table offsets)
140 u8 flg; //DSP flags and noise frequency
141 u8 esa; //Starting page used to store echo waveform
146 u8 endx; //Waveform has ended
147 u8 edl; //Echo Delay in ms >> 4
152 DSPFIR fir[8]; //FIR filter
159 //Voice -----------08
160 DSPVoice *pVoice; //-> voice registers in DSP
162 //Waveform --------06
163 void *bCur; //-> current block
164 u8 bHdr; //Block Header for current block
165 u8 mFlg; //Mixing flags (see MixF)
166 //Envelope --------22
167 u8 eMode; //[3-0] Current mode (see EnvM)
168 //[6-4] ADSR mode to switch into from Gain
169 //[7] Envelope is idle
170 u8 eRIdx; //Index in RateTab (0-31)
171 u32 eRate; //Rate of envelope adjustment (16.16)
172 u32 eCnt; //Sample counter (16.16)
173 u32 eVal; //Current envelope value
174 s32 eAdj; //Amount to adjust envelope height
175 u32 eDest; //Envelope Destination
176 //Visualization ---08
177 s32 vMaxL; //Maximum absolute sample output
179 //Samples ---------52
180 s32 sP1; //Last sample decompressed (prev1)
181 s32 sP2; //Second to last sample (prev2)
182 s16 *sIdx; //-> current sample in sBuf
183 s16 sBufP[4]; //Last 4 samples from previous block (needed for inter.)
184 s16 sBuf[16]; //32 bytes for decompressed sample blocks
185 //Mixing ----------32
186 float mTgtL; //Target volume (floating-point routine only)
188 s32 mChnL; //Channel Volume (-24.7)
190 u32 mRate; //Pitch Rate after modulation (16.16)
191 u32 mDec; //Pitch Decimal (.16) (used as delta for interpolation)
192 u32 mOrgP; //Original pitch rate converted from the DSP (16.16)
193 s32 mOut; //Last sample output before chn vol (used for pitch mod)
196 typedef struct DSPState
198 DSPReg *pDSP; //[0.0] -> DSP registers (128 bytes)
199 Voice *pVoice; //[0.4] -> Internal mixing settings (1k)
200 void *pEcho; //[0.8] -> echo buffer (bytes = sample rate * 1.92)
201 u32 _r1; //[0.C] reserved
203 u32 vMMaxL,vMMaxR; //[1.0] Maximum output so far
204 u32 mAmp; //[1.8] Amplification
205 u8 vActive; //[1.C] Flags for each active voice
206 u8 _r2[3]; //[1.D] reserved
211 SPC_EMULATOR_UNKNOWN = 0,
216 typedef struct SPC_ID666
225 SPC_EmulatorType emulator;
228 //Interpolation routines -------------------
235 INT_GAUSS, //4-point Gaussian
236 INT_SINC, //8-point Sinc
240 //DSP options ------------------------------
243 OPT_ANALOG, //Simulate anomalies of the analog hardware
244 OPT_OLDSMP, //Old sample decompression routine
245 OPT_SURND, //"Surround" sound
246 OPT_REVERSE, //Reverse stereo samples
247 OPT_NOECHO, //Disable echo
248 OPT_FILTER //Pass each voice through an anti-aliasing filter
251 //Mixing routines (see DSP.Asm for details of each routine)
255 MIX_NONE = 0, //No mixing
256 MIX_INT = 1, //Use integer math
257 MIX_FLOAT = 3 //Use floating-point math