Skip to content

Commit

Permalink
Implemented command 01 (download data and mix to MAIN/AUXA/AUXB with …
Browse files Browse the repository at this point in the history
…volume control). Fixes missing weapon sounds in Metroid Prime 2.
  • Loading branch information
delroth committed Nov 28, 2012
1 parent 4cf2856 commit 04b1ee0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
35 changes: 34 additions & 1 deletion Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.cpp
Expand Up @@ -108,7 +108,16 @@ void CUCode_AX::HandleCommandList()
SetupProcessing(HILO_TO_32(addr));
break;

case CMD_UNK_01: curr_idx += 5; break;
case CMD_DL_AND_VOL_MIX:
{
addr_hi = m_cmdlist[curr_idx++];
addr_lo = m_cmdlist[curr_idx++];
u16 vol_main = m_cmdlist[curr_idx++];
u16 vol_auxa = m_cmdlist[curr_idx++];
u16 vol_auxb = m_cmdlist[curr_idx++];
DownloadAndMixWithVolume(HILO_TO_32(addr), vol_main, vol_auxa, vol_auxb);
break;
}

case CMD_PB_ADDR:
addr_hi = m_cmdlist[curr_idx++];
Expand Down Expand Up @@ -333,6 +342,30 @@ void CUCode_AX::SetupProcessing(u32 init_addr)
}
}

void CUCode_AX::DownloadAndMixWithVolume(u32 addr, u16 vol_main, u16 vol_auxa, u16 vol_auxb)
{
int* buffers_main[3] = { m_samples_left, m_samples_right, m_samples_surround };
int* buffers_auxa[3] = { m_samples_auxA_left, m_samples_auxA_right, m_samples_auxA_surround };
int* buffers_auxb[3] = { m_samples_auxB_left, m_samples_auxB_right, m_samples_auxB_surround };
int** buffers[3] = { buffers_main, buffers_auxa, buffers_auxb };
u16 volumes[3] = { vol_main, vol_auxa, vol_auxb };

for (u32 i = 0; i < 3; ++i)
{
int* ptr = (int*)HLEMemory_Get_Pointer(addr);
s16 volume = (s16)volumes[i];
for (u32 j = 0; j < 3; ++j)
{
int* buffer = buffers[i][j];
for (u32 k = 0; k < 5 * 32; ++k)
{
s64 sample = 2 * (s32)Common::swap32(*ptr++) * volume;
buffer[k] += (s32)(sample >> 16);
}
}
}
}

void CUCode_AX::ProcessPBList(u32 pb_addr)
{
// Samples per millisecond. In theory DSP sampling rate can be changed from
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h
Expand Up @@ -131,6 +131,7 @@ class CUCode_AX : public IUCode
virtual void HandleCommandList();

void SetupProcessing(u32 init_addr);
void DownloadAndMixWithVolume(u32 addr, u16 vol_main, u16 vol_auxa, u16 vol_auxb);
void ProcessPBList(u32 pb_addr);
void MixAUXSamples(int aux_id, u32 write_addr, u32 read_addr);
void UploadLRS(u32 dst_addr);
Expand All @@ -147,7 +148,7 @@ class CUCode_AX : public IUCode
enum CmdType
{
CMD_SETUP = 0x00,
CMD_UNK_01 = 0x01,
CMD_DL_AND_VOL_MIX = 0x01,
CMD_PB_ADDR = 0x02,
CMD_PROCESS = 0x03,
CMD_MIX_AUXA = 0x04,
Expand Down

0 comments on commit 04b1ee0

Please sign in to comment.