jak-project/game/sound/sdshim.cpp

133 lines
2.8 KiB
C++
Raw Permalink Normal View History

2022-05-19 16:54:36 -04:00
#include "sdshim.h"
2022-05-19 16:54:36 -04:00
#include <cstring>
2022-05-19 16:54:36 -04:00
#include "common/common_types.h"
#include "common/util/Assert.h"
2022-05-19 16:54:36 -04:00
#include "game/sound/common/voice.h"
#include "fmt/core.h"
2022-05-19 16:54:36 -04:00
std::shared_ptr<snd::Voice> voices[4];
u8 spu_memory[0x15160 * 10];
2022-05-19 16:54:36 -04:00
static sceSdTransIntrHandler trans_handler[2] = {nullptr, nullptr};
static void* userdata[2] = {nullptr, nullptr};
u32 sceSdGetSwitch(u32 entry) {
// we can ignore this, only used for getting vmix
return 0;
}
snd::Voice* voice_from_entry(u32 entry) {
u32 it = entry & 3;
return voices[it].get();
}
2022-05-19 16:54:36 -04:00
u32 sceSdGetAddr(u32 entry) {
[[maybe_unused]] u32 core = entry & 1;
[[maybe_unused]] u32 voice_id = (entry >> 1) & 0x1f;
auto* voice = voice_from_entry(voice_id);
if (!voice) {
return 0;
}
2022-05-19 16:54:36 -04:00
// u32 core = entry & 1;
// u32 voice->id = (entry >> 1) & 0x1f;
// u32 reg = entry & ~0x3f;
// Only ever used for getting NAX
return voice->GetNax() << 1;
2022-05-19 16:54:36 -04:00
}
void sceSdSetSwitch(u32 entry, u32 value) {
u32 reg = entry & ~0x3f;
u8 voice = 0;
while (value) {
u8 bit = value & 1;
if (bit) {
switch (reg) {
case SD_S_KON:
voice_from_entry(voice)->KeyOn();
break;
case SD_S_KOFF:
voice_from_entry(voice)->KeyOff();
break;
}
}
voice++;
value >>= 1;
}
}
2022-05-19 16:54:36 -04:00
void sceSdSetAddr(u32 entry, u32 value) {
[[maybe_unused]] u32 core = entry & 1;
[[maybe_unused]] u32 voice_id = (entry >> 1) & 0x1f;
auto* voice = voice_from_entry(voice_id);
if (!voice) {
return;
}
2022-05-19 16:54:36 -04:00
u32 reg = entry & ~0x3f;
switch (reg) {
case SD_VA_SSA: {
voice->SetSsa(value >> 1);
2022-05-19 16:54:36 -04:00
} break;
case SD_VA_LSAX: {
voice->SetLsa(value >> 1);
2022-05-19 16:54:36 -04:00
} break;
default:
printf("unknown 0x%x\n", reg);
ASSERT_NOT_REACHED();
break;
2022-05-19 16:54:36 -04:00
}
}
void sceSdSetParam(u32 entry, u32 value) {
[[maybe_unused]] u32 core = entry & 1;
[[maybe_unused]] u32 voice_id = (entry >> 1) & 0x1f;
auto* voice = voice_from_entry(voice_id);
if (!voice) {
return;
}
2022-05-19 16:54:36 -04:00
u32 reg = entry & ~0x3f;
switch (reg) {
case SD_VP_VOLL: {
voice->SetVolumeL(value);
2022-05-19 16:54:36 -04:00
} break;
case SD_VP_VOLR: {
voice->SetVolumeR(value);
2022-05-19 16:54:36 -04:00
} break;
case SD_VP_PITCH: {
voice->SetPitch(value);
2022-05-19 16:54:36 -04:00
} break;
case SD_VP_ADSR1: {
voice->SetAsdr1(value);
2022-05-19 16:54:36 -04:00
} break;
case SD_VP_ADSR2: {
voice->SetAsdr2(value);
2022-05-19 16:54:36 -04:00
} break;
default: {
} break;
}
}
void sceSdSetTransIntrHandler(s32 channel, sceSdTransIntrHandler handler, void* data) {
trans_handler[channel] = handler;
userdata[channel] = data;
}
u32 sceSdVoiceTrans(s32 channel, s32 mode, void* iop_addr, u32 spu_addr, u32 size) {
memcpy(&spu_memory[spu_addr], iop_addr, size);
if (trans_handler[channel] != nullptr) {
trans_handler[channel](channel, userdata);
}
return size;
}