Zelda Ucode partly working without Premix hack.

The code is still completely wrong, and it only outputs some sound,
but the mess is confined to the Zelda Ucode implementation.
This commit is contained in:
magumagu 2014-03-26 13:53:42 -07:00
parent 8dad1be319
commit 4fafa954a1
4 changed files with 20 additions and 44 deletions

View File

@ -290,32 +290,14 @@ void CUCode_Zelda::HandleMail_NormalVersion(u32 _uMail)
m_SyncFlags[n] = _uMail & 0xFFFF;
m_bSyncInProgress = false;
// Normally, we should mix to the buffers used by the game.
// We don't do it currently for a simple reason:
// if the game runs fast all the time, then it's OK,
// but if it runs slow, sound can become choppy.
// This problem won't happen when mixing to the buffer
// provided by MixAdd(), because the size of this buffer
// is automatically adjusted if the game runs slow.
#if 0
if (m_SyncFlags[n] & 0x8000)
{
for (; m_CurVoice < m_MaxVoice; m_CurVoice++)
{
if (m_CurVoice >= m_NumVoices)
break;
MixVoice(m_CurVoice);
}
}
else
#endif
m_CurVoice = m_MaxVoice;
m_CurVoice = m_MaxVoice;
if (m_CurVoice >= m_NumVoices)
{
m_CurBuffer++;
MixAudio();
m_rMailHandler.PushMail(DSP_SYNC);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
m_rMailHandler.PushMail(0xF355FF00 | m_CurBuffer);
@ -555,9 +537,6 @@ u32 CUCode_Zelda::GetUpdateMs()
void CUCode_Zelda::DoState(PointerWrap &p)
{
// It's bad if we try to save during Mix()
std::lock_guard<std::mutex> lk(m_csMix);
p.Do(m_AFCCoefTable);
p.Do(m_MiscTable);

View File

@ -125,7 +125,6 @@ public:
void HandleMail_LightVersion(u32 _uMail);
void HandleMail_SMSVersion(u32 _uMail);
void HandleMail_NormalVersion(u32 _uMail);
void Update(int cycles) override;
void CopyPBsFromRAM();
@ -290,4 +289,6 @@ private:
// Renders a voice and mixes it into LeftBuffer, RightBuffer
void RenderAddVoice(ZeldaVoicePB& PB, s32* _LeftBuffer, s32* _RightBuffer, int _Size);
void MixAudio();
};

View File

@ -738,18 +738,14 @@ ContinueWithBlock:
PB.NeedsReset = 0;
}
}
#if 0
// size is in stereo samples.
void CUCode_Zelda::MixAdd(short *_Buffer, int _Size)
void CUCode_Zelda::MixAudio()
{
std::lock_guard<std::mutex> lk(m_csMix);
// Safety check
if (_Size > 256 * 1024 - 8)
_Size = 256 * 1024 - 8;
const int BufferSamples = 5 * 16;
// Final mix buffers
memset(m_LeftBuffer, 0, _Size * sizeof(s32));
memset(m_RightBuffer, 0, _Size * sizeof(s32));
memset(m_LeftBuffer, 0, BufferSamples * sizeof(s32));
memset(m_RightBuffer, 0, BufferSamples * sizeof(s32));
// For each PB...
for (u32 i = 0; i < m_NumVoices; i++)
@ -769,23 +765,24 @@ void CUCode_Zelda::MixAdd(short *_Buffer, int _Size)
if (pb.KeyOff != 0)
continue;
RenderAddVoice(pb, m_LeftBuffer, m_RightBuffer, _Size);
RenderAddVoice(pb, m_LeftBuffer, m_RightBuffer, BufferSamples);
WritebackVoicePB(m_VoicePBsAddr + (i * 0x180), pb);
}
// Post processing, final conversion.
for (int i = 0; i < _Size; i++)
s16* left_buffer = (s16*)HLEMemory_Get_Pointer(m_LeftBuffersAddr);
s16* right_buffer = (s16*)HLEMemory_Get_Pointer(m_RightBuffersAddr);
left_buffer += m_CurBuffer * BufferSamples;
right_buffer += m_CurBuffer * BufferSamples;
for (int i = 0; i < BufferSamples; i++)
{
s32 left = (s32)_Buffer[0] + m_LeftBuffer[i];
s32 right = (s32)_Buffer[1] + m_RightBuffer[i];
s32 left = m_LeftBuffer[i];
s32 right = m_RightBuffer[i];
MathUtil::Clamp(&left, -32768, 32767);
_Buffer[0] = (short)left;
left_buffer[i] = Common::swap16((short)left);
MathUtil::Clamp(&right, -32768, 32767);
_Buffer[1] = (short)right;
_Buffer += 2;
right_buffer[i] = Common::swap16((short)right);
}
}
#endif

View File

@ -94,7 +94,6 @@ protected:
void DoStateShared(PointerWrap &p);
CMailHandler& m_rMailHandler;
std::mutex m_csMix;
enum EDSP_Codes
{