Play-/tools/SpuTest/Test.cpp

76 lines
2.2 KiB
C++
Raw Normal View History

2020-12-29 12:34:47 -05:00
#include "Test.h"
#include <vector>
#include <cassert>
2020-12-29 12:47:39 -05:00
#include <cstring>
2020-12-29 12:34:47 -05:00
#include "Ps2Const.h"
CTest::CTest()
: m_ram(new uint8[PS2::SPU_RAM_SIZE])
, m_spuCore0(m_ram, PS2::SPU_RAM_SIZE, 0)
, m_spuCore1(m_ram, PS2::SPU_RAM_SIZE, 1)
, m_spu(m_spuCore0, m_spuCore1)
{
memset(m_ram, 0, PS2::SPU_RAM_SIZE);
}
CTest::~CTest()
{
delete [] m_ram;
}
void CTest::RunSpu(unsigned int ticks)
{
static const unsigned int DST_SAMPLE_RATE = 44100;
unsigned int blockSize = ticks * 2;
std::vector<int16> samples(blockSize);
m_spuCore0.Render(samples.data(), blockSize, DST_SAMPLE_RATE);
m_spuCore1.Render(samples.data(), blockSize, DST_SAMPLE_RATE);
}
2020-12-30 16:31:00 -05:00
uint32 CTest::GetCoreRegister(unsigned int coreIndex, uint32 address)
{
assert(coreIndex == 0);
return m_spu.ReadRegister(address);
}
2020-12-29 12:34:47 -05:00
void CTest::SetCoreRegister(unsigned int coreIndex, uint32 address, uint32 value)
{
assert(coreIndex == 0);
m_spu.WriteRegister(address, value);
}
2020-12-30 16:31:00 -05:00
uint32 CTest::GetCoreAddress(unsigned int coreIndex, uint32 registerAddress)
{
assert((registerAddress & 0x2) == 0);
uint32 addrHi = GetCoreRegister(coreIndex, registerAddress + 0);
uint32 addrLo = GetCoreRegister(coreIndex, registerAddress + 2);
return (addrHi << 17) | (addrLo << 1);
}
2020-12-29 12:34:47 -05:00
void CTest::SetCoreAddress(unsigned int coreIndex, uint32 registerAddress, uint32 targetAddress)
{
assert((registerAddress & 0x2) == 0);
SetCoreRegister(coreIndex, registerAddress + 0, (targetAddress >> 17) & 0xFFFE);
SetCoreRegister(coreIndex, registerAddress + 2, (targetAddress >> 1) & 0xFFFE);
}
void CTest::SetVoiceRegister(unsigned int coreIndex, uint32 voiceIndex, uint32 address, uint32 value)
{
uint32 voiceAddress = address + (voiceIndex * 0x10);
SetCoreRegister(coreIndex, voiceAddress, value);
}
2020-12-30 16:31:00 -05:00
uint32 CTest::GetVoiceAddress(unsigned int coreIndex, unsigned int voiceIndex, uint32 registerAddress)
{
uint32 voiceAddress = registerAddress + (voiceIndex * 12);
return GetCoreAddress(coreIndex, voiceAddress);
}
void CTest::SetVoiceAddress(unsigned int coreIndex, unsigned int voiceIndex, uint32 registerAddress, uint32 targetAddress)
2020-12-29 12:34:47 -05:00
{
uint32 voiceAddress = registerAddress + (voiceIndex * 12);
SetCoreAddress(coreIndex, voiceAddress, targetAddress);
}