diff options
author | Arisotura <thetotalworm@gmail.com> | 2023-11-04 14:20:58 +0100 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2023-11-04 14:20:58 +0100 |
commit | 76976fef3038918ad01a9dbda4c0e5d9bebef9af (patch) | |
tree | bf9a8b62f760a1f4f945599032bcef4d8fd7bd57 /src/SPU.h | |
parent | ac38faef1409553c016a2a8c9a8cf74f2e5e0249 (diff) |
convert SPU to OOP
Diffstat (limited to 'src/SPU.h')
-rw-r--r-- | src/SPU.h | 118 |
1 files changed, 76 insertions, 42 deletions
@@ -20,51 +20,30 @@ #define SPU_H #include "Savestate.h" +#include "Platform.h" -namespace SPU -{ - -bool Init(); -void DeInit(); -void Reset(); -void Stop(); - -void DoSavestate(Savestate* file); - -void SetPowerCnt(u32 val); - -// 0=none 1=linear 2=cosine 3=cubic -void SetInterpolation(int type); - -void SetBias(u16 bias); -void SetDegrade10Bit(bool enable); -void SetApplyBias(bool enable); - -void Mix(u32 dummy); - -void TrimOutput(); -void DrainOutput(); -void InitOutput(); -int GetOutputSize(); -void Sync(bool wait); -int ReadOutput(s16* data, int samples); -void TransferOutput(); +class SPU; -u8 Read8(u32 addr); -u16 Read16(u32 addr); -u32 Read32(u32 addr); -void Write8(u32 addr, u8 val); -void Write16(u32 addr, u16 val); -void Write32(u32 addr, u32 val); - -class Channel +class SPUChannel { public: - Channel(u32 num); - ~Channel(); + SPUChannel(u32 num); + ~SPUChannel(); void Reset(); void DoSavestate(Savestate* file); + static const s8 ADPCMIndexTable[8]; + static const u16 ADPCMTable[89]; + static const s16 PSGTable[8][8]; + + static s16 InterpCos[0x100]; + static s16 InterpCubic[0x100][4]; + static bool InterpInited; + + // audio interpolation is an improvement upon the original hardware + // (which performs no interpolation) + int InterpType; + u32 Num; u32 Cnt; @@ -164,11 +143,11 @@ private: u32 (*BusRead32)(u32 addr); }; -class CaptureUnit +class SPUCaptureUnit { public: - CaptureUnit(u32 num); - ~CaptureUnit(); + SPUCaptureUnit(u32 num); + ~SPUCaptureUnit(); void Reset(); void DoSavestate(Savestate* file); @@ -221,6 +200,61 @@ private: void (*BusWrite32)(u32 addr, u32 val); }; -} +class SPU +{ +public: + SPU(); + ~SPU(); + void Reset(); + void DoSavestate(Savestate* file); + + void Stop(); + + void SetPowerCnt(u32 val); + + // 0=none 1=linear 2=cosine 3=cubic + void SetInterpolation(int type); + + void SetBias(u16 bias); + void SetDegrade10Bit(bool enable); + void SetApplyBias(bool enable); + + void Mix(u32 dummy); + + void TrimOutput(); + void DrainOutput(); + void InitOutput(); + int GetOutputSize(); + void Sync(bool wait); + int ReadOutput(s16* data, int samples); + void TransferOutput(); + + u8 Read8(u32 addr); + u16 Read16(u32 addr); + u32 Read32(u32 addr); + void Write8(u32 addr, u8 val); + void Write16(u32 addr, u16 val); + void Write32(u32 addr, u32 val); + +private: + static const u32 OutputBufferSize = 2*2048; + s16 OutputBackbuffer[2 * OutputBufferSize]; + u32 OutputBackbufferWritePosition; + + s16 OutputFrontBuffer[2 * OutputBufferSize]; + u32 OutputFrontBufferWritePosition; + u32 OutputFrontBufferReadPosition; + + Platform::Mutex* AudioLock; + + u16 Cnt; + u8 MasterVolume; + u16 Bias; + bool ApplyBias; + bool Degrade10Bit; + + SPUChannel* Channels[16]; + SPUCaptureUnit* Capture[2]; +}; #endif // SPU_H |