2009-05-02 03:41:03 +00:00
|
|
|
/* SPU2null
|
|
|
|
* Copyright (C) 2002-2005 SPU2null Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2009-05-02 03:41:03 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-02 03:41:03 +00:00
|
|
|
#ifndef __SPU2_H__
|
|
|
|
#define __SPU2_H__
|
|
|
|
|
|
|
|
#define _CRT_SECURE_NO_DEPRECATE
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
extern "C" {
|
2009-05-02 03:41:03 +00:00
|
|
|
#define SPU2defs
|
|
|
|
#include "PS2Edefs.h"
|
|
|
|
}
|
2010-06-10 16:30:08 +00:00
|
|
|
#include "PS2Eext.h"
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2010-07-31 09:01:41 +00:00
|
|
|
#ifdef _MSC_VER
|
2009-05-02 03:41:03 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <windowsx.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define EXPORT_C_(type) extern "C" __declspec(dllexport) type CALLBACK
|
|
|
|
#else
|
2016-08-24 21:15:05 +00:00
|
|
|
#define EXPORT_C_(type) extern "C" __attribute__((stdcall, externally_visible, visibility("default"))) type
|
2009-05-02 03:41:03 +00:00
|
|
|
#endif
|
|
|
|
|
2016-08-28 16:14:07 +00:00
|
|
|
extern FILE *spu2Log;
|
2009-05-02 03:41:03 +00:00
|
|
|
#define SPU2_LOG __Log //debug mode
|
|
|
|
|
2009-05-17 21:57:24 +00:00
|
|
|
extern const u8 version;
|
|
|
|
extern const u8 revision;
|
|
|
|
extern const u8 build;
|
|
|
|
extern const u32 minor;
|
2016-08-28 16:14:07 +00:00
|
|
|
extern char *libraryName;
|
2009-05-02 03:41:03 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2016-08-24 21:15:05 +00:00
|
|
|
s32 Log;
|
2009-05-02 03:41:03 +00:00
|
|
|
} Config;
|
|
|
|
|
|
|
|
extern Config conf;
|
|
|
|
|
2016-08-28 16:14:07 +00:00
|
|
|
void __Log(char *fmt, ...);
|
2009-05-02 03:41:03 +00:00
|
|
|
void SaveConfig();
|
|
|
|
void LoadConfig();
|
2016-08-28 16:14:07 +00:00
|
|
|
void SysMessage(char *fmt, ...);
|
2009-05-02 03:41:03 +00:00
|
|
|
|
|
|
|
////////////////////
|
|
|
|
// SPU2 Registers //
|
|
|
|
////////////////////
|
2016-08-24 21:15:05 +00:00
|
|
|
#define REG_VP_VOLL 0x0000
|
|
|
|
#define REG_VP_VOLR 0x0002
|
|
|
|
#define REG_VP_PITCH 0x0004
|
|
|
|
#define REG_VP_ADSR1 0x0006
|
|
|
|
#define REG_VP_ADSR2 0x0008
|
|
|
|
#define REG_VP_ENVX 0x000A
|
|
|
|
#define REG_VP_VOLXL 0x000C
|
|
|
|
#define REG_VP_VOLXR 0x000E
|
|
|
|
#define REG_C0_FMOD1 0x0180
|
|
|
|
#define REG_C0_FMOD2 0x0182
|
|
|
|
#define REG_C1_FMOD1 0x0580
|
|
|
|
#define REG_C1_FMOD2 0x0582
|
|
|
|
#define REG_S_NON 0x0184
|
|
|
|
#define REG_S_VMIXL 0x0188
|
|
|
|
#define REG_S_VMIXEL 0x018C
|
|
|
|
#define REG_S_VMIXR 0x0190
|
|
|
|
#define REG_S_VMIXER 0x0194
|
|
|
|
#define REG_C0_MMIX 0x0198
|
|
|
|
#define REG_C1_MMIX 0x0598
|
|
|
|
#define REG_C0_CTRL 0x019A
|
|
|
|
#define REG_C0_IRQA_HI 0x019C
|
|
|
|
#define REG_C0_IRQA_LO 0x019D
|
|
|
|
#define REG_C1_IRQA_HI 0x059C
|
|
|
|
#define REG_C1_IRQA_LO 0x059D
|
|
|
|
#define REG_C0_SPUON1 0x1A0
|
|
|
|
#define REG_C0_SPUON2 0x1A2
|
|
|
|
#define REG_C1_SPUON1 0x5A0
|
|
|
|
#define REG_C1_SPUON2 0x5A2
|
|
|
|
#define REG_C0_SPUOFF1 0x1A4
|
|
|
|
#define REG_C0_SPUOFF2 0x1A6
|
|
|
|
#define REG_C1_SPUOFF1 0x5A4
|
|
|
|
#define REG_C1_SPUOFF2 0x5A6
|
2009-05-02 03:41:03 +00:00
|
|
|
#define REG_C0_SPUADDR_HI 0x01A8
|
|
|
|
#define REG_C0_SPUADDR_LO 0x01AA
|
|
|
|
#define REG_C1_SPUADDR_HI 0x05A8
|
|
|
|
#define REG_C1_SPUADDR_LO 0x05AA
|
2016-08-24 21:15:05 +00:00
|
|
|
#define REG_C0_SPUDATA 0x01AC
|
|
|
|
#define REG_C1_SPUDATA 0x05AC
|
|
|
|
#define REG_C0_DMACTRL 0x01AE
|
|
|
|
#define REG_C1_DMACTRL 0x05AE
|
|
|
|
#define REG_C0_ADMAS 0x01B0
|
|
|
|
#define REG_VA_SSA 0x01C0
|
|
|
|
#define REG_VA_LSAX 0x01C4
|
|
|
|
#define REG_VA_NAX 0x01C8
|
|
|
|
#define REG_A_ESA 0x02E0
|
|
|
|
#define REG_A_EEA 0x033C
|
|
|
|
#define REG_C0_END1 0x0340
|
|
|
|
#define REG_C0_END2 0x0342
|
|
|
|
#define REG_C1_END1 0x0740
|
|
|
|
#define REG_C1_END2 0x0742
|
|
|
|
#define REG_C0_SPUSTAT 0x0344 //not sure!
|
|
|
|
#define REG_C1_CTRL 0x059A
|
|
|
|
#define REG_C1_ADMAS 0x05B0
|
|
|
|
#define REG_C1_SPUSTAT 0x0744 //not sure!
|
|
|
|
#define REG_P_MVOLL 0x0760
|
|
|
|
#define REG_P_MVOLR 0x0762
|
|
|
|
#define REG_P_EVOLL 0x0764
|
|
|
|
#define REG_P_EVOLR 0x0766
|
|
|
|
#define REG_P_AVOLL 0x0768
|
|
|
|
#define REG_P_AVOLR 0x076A
|
|
|
|
#define REG_P_BVOLL 0x076C
|
|
|
|
#define REG_P_BVOLR 0x076E
|
|
|
|
#define REG_P_MVOLXL 0x0770
|
|
|
|
#define REG_P_MVOLXR 0x0772
|
|
|
|
#define SPDIF_OUT 0x07C0
|
|
|
|
#define REG_IRQINFO 0x07C2
|
|
|
|
#define SPDIF_MODE 0x07C6
|
|
|
|
#define SPDIF_MEDIA 0x07C8
|
|
|
|
|
2016-08-28 16:14:07 +00:00
|
|
|
#define spu2Rs16(mem) (*(s16 *)&spu2regs[(mem)&0xffff])
|
|
|
|
#define spu2Ru16(mem) (*(u16 *)&spu2regs[(mem)&0xffff])
|
2009-05-02 03:41:03 +00:00
|
|
|
//#define spu2Rs32(mem) (*(s32*)&spu2regs[(mem) & 0xffff])
|
|
|
|
//#define spu2Ru32(mem) (*(u32*)&spu2regs[(mem) & 0xffff])
|
|
|
|
|
|
|
|
#define IRQINFO spu2Ru16(REG_IRQINFO)
|
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
#define SPU2_GET32BIT(lo, hi) (((u32)(spu2Ru16(hi) & 0x3f) << 16) | (u32)spu2Ru16(lo))
|
|
|
|
#define SPU2_SET32BIT(value, lo, hi) \
|
|
|
|
{ \
|
|
|
|
spu2Ru16(hi) = ((value) >> 16) & 0x3f; \
|
|
|
|
spu2Ru16(lo) = (value)&0xffff; \
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-02 03:41:03 +00:00
|
|
|
#define C0_IRQA SPU2_GET32BIT(REG_C0_IRQA_LO, REG_C0_IRQA_HI)
|
|
|
|
#define C1_IRQA SPU2_GET32BIT(REG_C1_IRQA_LO, REG_C1_IRQA_HI)
|
|
|
|
|
|
|
|
#define C0_SPUADDR SPU2_GET32BIT(REG_C0_SPUADDR_LO, REG_C0_SPUADDR_HI)
|
|
|
|
#define C1_SPUADDR SPU2_GET32BIT(REG_C1_SPUADDR_LO, REG_C1_SPUADDR_HI)
|
|
|
|
|
|
|
|
#define C0_SPUADDR_SET(value) SPU2_SET32BIT(value, REG_C0_IRQA_LO, REG_C0_IRQA_HI)
|
|
|
|
#define C1_SPUADDR_SET(value) SPU2_SET32BIT(value, REG_C1_IRQA_LO, REG_C1_IRQA_HI)
|
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
#define SPU_NUMBER_VOICES 48
|
2009-05-02 03:41:03 +00:00
|
|
|
|
|
|
|
struct SPU_CONTROL_
|
|
|
|
{
|
2016-08-24 21:15:05 +00:00
|
|
|
u16 spuon : 1;
|
|
|
|
u16 spuUnmute : 1;
|
|
|
|
u16 noiseFreq : 6;
|
|
|
|
u16 reverb : 1;
|
|
|
|
u16 irq : 1;
|
|
|
|
u16 dma : 2; // 1 - no dma, 2 - write, 3 - read
|
|
|
|
u16 extr : 1; // external reverb
|
|
|
|
u16 cdreverb : 1;
|
|
|
|
u16 extAudio : 1;
|
|
|
|
u16 extCd : 1;
|
2009-05-02 03:41:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// the layout of each voice in wSpuRegs
|
|
|
|
struct _SPU_VOICE
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
2016-08-24 21:15:05 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
u16 Vol : 14;
|
|
|
|
u16 Inverted : 1;
|
|
|
|
u16 Sweep0 : 1;
|
2009-05-02 03:41:03 +00:00
|
|
|
} vol;
|
2016-08-24 21:15:05 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
u16 Vol : 7;
|
|
|
|
u16 res1 : 5;
|
|
|
|
u16 Inverted : 1;
|
|
|
|
u16 Decrease : 1; // if 0, increase
|
|
|
|
u16 ExpSlope : 1; // if 0, linear slope
|
|
|
|
u16 Sweep1 : 1; // always one
|
|
|
|
} sweep;
|
|
|
|
u16 word;
|
|
|
|
} left, right;
|
|
|
|
|
|
|
|
u16 pitch : 14; // 1000 - no pitch, 2000 - pitch + 1, etc
|
|
|
|
u16 res0 : 2;
|
|
|
|
|
|
|
|
u16 SustainLvl : 4;
|
|
|
|
u16 DecayRate : 4;
|
|
|
|
u16 AttackRate : 7;
|
|
|
|
u16 AttackExp : 1; // if 0, linear
|
|
|
|
|
|
|
|
u16 ReleaseRate : 5;
|
|
|
|
u16 ReleaseExp : 1; // if 0, linear
|
|
|
|
u16 SustainRate : 7;
|
|
|
|
u16 res1 : 1;
|
|
|
|
u16 SustainDec : 1; // if 0, inc
|
|
|
|
u16 SustainExp : 1; // if 0, linear
|
|
|
|
|
|
|
|
u16 AdsrVol;
|
|
|
|
u16 Address; // add / 8
|
|
|
|
u16 RepeatAddr; // gets reset when sample starts
|
2009-05-02 03:41:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ADSR INFOS PER CHANNEL
|
|
|
|
struct ADSRInfoEx
|
|
|
|
{
|
2016-08-24 21:15:05 +00:00
|
|
|
s32 State;
|
|
|
|
s32 AttackModeExp;
|
|
|
|
s32 AttackRate;
|
|
|
|
s32 DecayRate;
|
|
|
|
s32 SustainLevel;
|
|
|
|
s32 SustainModeExp;
|
|
|
|
s32 SustainIncrease;
|
|
|
|
s32 SustainRate;
|
|
|
|
s32 ReleaseModeExp;
|
|
|
|
s32 ReleaseRate;
|
|
|
|
s32 EnvelopeVol;
|
|
|
|
s32 lVolume;
|
2009-05-02 03:41:03 +00:00
|
|
|
};
|
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
#define NSSIZE 48 // ~ 1 ms of data
|
|
|
|
#define NSFRAMES 16 // gather at least NSFRAMES of NSSIZE before submitting
|
2009-05-02 03:41:03 +00:00
|
|
|
#define NSPACKETS 4
|
2016-08-28 16:14:07 +00:00
|
|
|
#define SPU_VOICE_STATE_SIZE (sizeof(VOICE_PROCESSED) - 4 * sizeof(void *))
|
2009-05-02 03:41:03 +00:00
|
|
|
|
|
|
|
struct VOICE_PROCESSED
|
|
|
|
{
|
2016-08-24 21:15:05 +00:00
|
|
|
VOICE_PROCESSED()
|
|
|
|
{
|
|
|
|
memset(this, 0, sizeof(VOICE_PROCESSED));
|
|
|
|
}
|
|
|
|
~VOICE_PROCESSED()
|
|
|
|
{
|
|
|
|
}
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
void SetVolume(int right);
|
|
|
|
void StartSound();
|
|
|
|
void VoiceChangeFrequency();
|
|
|
|
void FModChangeFrequency(int ns);
|
|
|
|
void Stop();
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-28 16:14:07 +00:00
|
|
|
SPU_CONTROL_ *GetCtrl();
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
// start save state
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
s32 iSBPos; // mixing stuff
|
|
|
|
s32 spos;
|
|
|
|
s32 sinc;
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
s32 iActFreq; // current psx pitch
|
|
|
|
s32 iUsedFreq; // current pc pitch
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
s32 iStartAddr, iLoopAddr, iNextAddr;
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
ADSRInfoEx ADSRX; // next ADSR settings (will be moved to active on sample start)
|
|
|
|
bool bIgnoreLoop, bNew, bNoise, bReverb, bOn, bStop, bVolChanged;
|
|
|
|
s32 memoffset; // if first core, 0, if second, 0x400
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
// end save state
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-24 21:15:05 +00:00
|
|
|
///////////////////
|
|
|
|
// Sound Buffers //
|
|
|
|
///////////////////
|
2016-08-28 16:14:07 +00:00
|
|
|
u8 *pStart; // start and end addresses
|
2016-08-24 21:15:05 +00:00
|
|
|
u8 *pLoop, *pCurr;
|
2009-05-02 03:41:03 +00:00
|
|
|
|
2016-08-28 16:14:07 +00:00
|
|
|
_SPU_VOICE *pvoice;
|
2009-05-02 03:41:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ADMA
|
|
|
|
{
|
2016-08-28 16:14:07 +00:00
|
|
|
u16 *MemAddr;
|
2016-08-24 21:15:05 +00:00
|
|
|
s32 IntPointer;
|
|
|
|
s32 Index;
|
|
|
|
s32 AmountLeft;
|
|
|
|
s32 Enabled;
|
2009-05-02 03:41:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __SPU2_H__ */
|