Core: Move audio code into AudioInterfaceHandler
This commit is contained in:
parent
fcdda04da5
commit
c28bc27c27
|
@ -19,8 +19,14 @@ AudioInterfaceHandler::AudioInterfaceHandler(CN64System & System, CRegisters & R
|
|||
m_System(System),
|
||||
m_Reg(Reg),
|
||||
m_Plugins(System.GetPlugins()),
|
||||
m_PC(Reg.m_PROGRAM_COUNTER)
|
||||
m_PC(Reg.m_PROGRAM_COUNTER),
|
||||
m_Status(0),
|
||||
m_SecondBuff(0),
|
||||
m_BytesPerSecond(0),
|
||||
m_CountsPerByte(System.AiCountPerBytes()),
|
||||
m_FramesPerSecond(60)
|
||||
{
|
||||
SystemReset();
|
||||
System.RegisterCallBack(CN64SystemCB_Reset, this, (CN64System::CallBackFunction)stSystemReset);
|
||||
System.RegisterCallBack(CN64SystemCB_LoadedGameState, this, (CN64System::CallBackFunction)stLoadedGameState);
|
||||
}
|
||||
|
@ -38,7 +44,7 @@ bool AudioInterfaceHandler::Read32(uint32_t Address, uint32_t & Value)
|
|||
case 0x04500004:
|
||||
if (bFixedAudio())
|
||||
{
|
||||
Value = m_Audio.GetLength();
|
||||
Value = GetLength();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -55,7 +61,7 @@ bool AudioInterfaceHandler::Read32(uint32_t Address, uint32_t & Value)
|
|||
case 0x0450000C:
|
||||
if (bFixedAudio())
|
||||
{
|
||||
Value = m_Audio.GetStatus();
|
||||
Value = GetStatus();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -118,7 +124,7 @@ bool AudioInterfaceHandler::Write32(uint32_t Address, uint32_t Value, uint32_t M
|
|||
AI_LEN_REG = (AI_LEN_REG & ~Mask) | (MaskedValue);
|
||||
if (bFixedAudio())
|
||||
{
|
||||
m_Audio.LenChanged();
|
||||
LenChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -139,7 +145,7 @@ bool AudioInterfaceHandler::Write32(uint32_t Address, uint32_t Value, uint32_t M
|
|||
m_Plugins->Audio()->DacrateChanged(m_System.SystemType());
|
||||
if (bFixedAudio())
|
||||
{
|
||||
m_Audio.SetFrequency(AI_DACRATE_REG, m_System.SystemType());
|
||||
SetFrequency(AI_DACRATE_REG, m_System.SystemType());
|
||||
}
|
||||
break;
|
||||
case 0x04500014: AI_DACRATE_REG = (AI_BITRATE_REG & ~Mask) | (MaskedValue); break;
|
||||
|
@ -154,43 +160,144 @@ bool AudioInterfaceHandler::Write32(uint32_t Address, uint32_t Value, uint32_t M
|
|||
|
||||
void AudioInterfaceHandler::TimerInterrupt(void)
|
||||
{
|
||||
m_Audio.InterruptTimerDone();
|
||||
WriteTrace(TraceAudio, TraceDebug, "Start (m_SecondBuff = %d)", m_SecondBuff);
|
||||
m_Status &= ~AI_STATUS_FIFO_FULL;
|
||||
g_Reg->MI_INTR_REG |= MI_INTR_AI;
|
||||
g_Reg->CheckInterrupts();
|
||||
if (m_SecondBuff != 0)
|
||||
{
|
||||
g_SystemTimer->SetTimer(CSystemTimer::AiTimerInterrupt, m_SecondBuff * m_CountsPerByte, false);
|
||||
m_SecondBuff = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Status &= ~AI_STATUS_DMA_BUSY;
|
||||
}
|
||||
WriteTrace(TraceAudio, TraceDebug, "Done");
|
||||
}
|
||||
|
||||
void AudioInterfaceHandler::TimerBusy(void)
|
||||
{
|
||||
m_Audio.BusyTimerDone();
|
||||
WriteTrace(TraceAudio, TraceDebug, "Start (m_SecondBuff = %d)", m_SecondBuff);
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
m_Status &= ~AI_STATUS_DMA_BUSY;
|
||||
}
|
||||
|
||||
void AudioInterfaceHandler::SetViIntr(uint32_t VI_INTR_TIME)
|
||||
{
|
||||
m_Audio.SetViIntr(VI_INTR_TIME);
|
||||
double CountsPerSecond = (uint32_t)((double)VI_INTR_TIME * m_FramesPerSecond);
|
||||
if (m_BytesPerSecond != 0 && (g_System->AiCountPerBytes() == 0))
|
||||
{
|
||||
m_CountsPerByte = (int32_t)((double)CountsPerSecond / (double)m_BytesPerSecond);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioInterfaceHandler::SetFrequency(uint32_t Dacrate, uint32_t System)
|
||||
{
|
||||
m_Audio.SetFrequency(Dacrate, System);
|
||||
WriteTrace(TraceAudio, TraceDebug, "(Dacrate: %X System: %d): AI_BITRATE_REG = %X", Dacrate, System, g_Reg->AI_BITRATE_REG);
|
||||
uint32_t Frequency;
|
||||
|
||||
switch (System)
|
||||
{
|
||||
case SYSTEM_PAL: Frequency = 49656530 / (Dacrate + 1); break;
|
||||
case SYSTEM_MPAL: Frequency = 48628316 / (Dacrate + 1); break;
|
||||
default: Frequency = 48681812 / (Dacrate + 1); break;
|
||||
}
|
||||
|
||||
//nBlockAlign = 16 / 8 * 2;
|
||||
m_BytesPerSecond = Frequency * 4;
|
||||
//m_BytesPerSecond = 194532;
|
||||
//m_BytesPerSecond = 128024;
|
||||
|
||||
m_FramesPerSecond = System == SYSTEM_PAL ? 50 : 60;
|
||||
}
|
||||
|
||||
void AudioInterfaceHandler::LoadedGameState(void)
|
||||
{
|
||||
if (bFixedAudio())
|
||||
{
|
||||
m_Audio.SetFrequency(m_Reg.AI_DACRATE_REG, SystemType());
|
||||
SetFrequency(m_Reg.AI_DACRATE_REG, SystemType());
|
||||
}
|
||||
}
|
||||
|
||||
void AudioInterfaceHandler::SystemReset(void)
|
||||
{
|
||||
m_Audio.Reset();
|
||||
m_SecondBuff = 0;
|
||||
m_BytesPerSecond = 0;
|
||||
m_CountsPerByte = g_System->AiCountPerBytes();
|
||||
if (m_CountsPerByte == 0)
|
||||
{
|
||||
m_CountsPerByte = 500;
|
||||
}
|
||||
m_FramesPerSecond = 60;
|
||||
}
|
||||
|
||||
uint32_t AudioInterfaceHandler::GetLength(void)
|
||||
{
|
||||
return m_Audio.GetLength();
|
||||
WriteTrace(TraceAudio, TraceDebug, "Start (m_SecondBuff = %d)", m_SecondBuff);
|
||||
uint32_t TimeLeft = g_SystemTimer->GetTimer(CSystemTimer::AiTimerInterrupt), Res = 0;
|
||||
if (TimeLeft > 0)
|
||||
{
|
||||
Res = (TimeLeft / m_CountsPerByte)&~7;
|
||||
}
|
||||
WriteTrace(TraceAudio, TraceDebug, "Done (res = %d, TimeLeft = %d)", Res, TimeLeft);
|
||||
return Res;
|
||||
}
|
||||
|
||||
uint32_t AudioInterfaceHandler::GetStatus(void)
|
||||
{
|
||||
return m_Audio.GetStatus();
|
||||
WriteTrace(TraceAudio, TraceDebug, "m_Status = %X", m_Status);
|
||||
return m_Status;
|
||||
}
|
||||
|
||||
void AudioInterfaceHandler::LenChanged()
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Start (g_Reg->AI_LEN_REG = %d)", g_Reg->AI_LEN_REG);
|
||||
if (g_Reg->AI_LEN_REG != 0)
|
||||
{
|
||||
if (g_Reg->AI_LEN_REG >= 0x40000)
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Ignoring write, to large (%X)", g_Reg->AI_LEN_REG);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Status |= AI_STATUS_DMA_BUSY;
|
||||
uint32_t AudioLeft = g_SystemTimer->GetTimer(CSystemTimer::AiTimerInterrupt);
|
||||
if (m_SecondBuff == 0)
|
||||
{
|
||||
if (AudioLeft == 0)
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Set timer AI_LEN_REG: %d m_CountsPerByte: %d", g_Reg->AI_LEN_REG, m_CountsPerByte);
|
||||
g_SystemTimer->SetTimer(CSystemTimer::AiTimerInterrupt, g_Reg->AI_LEN_REG * m_CountsPerByte, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Increasing second buffer (m_SecondBuff %d Increase: %d)", m_SecondBuff, g_Reg->AI_LEN_REG);
|
||||
m_SecondBuff += g_Reg->AI_LEN_REG;
|
||||
m_Status |= AI_STATUS_FIFO_FULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Reset timer to 0");
|
||||
g_SystemTimer->StopTimer(CSystemTimer::AiTimerBusy);
|
||||
g_SystemTimer->StopTimer(CSystemTimer::AiTimerInterrupt);
|
||||
m_SecondBuff = 0;
|
||||
m_Status = 0;
|
||||
}
|
||||
|
||||
if (g_Plugins->Audio()->AiLenChanged != nullptr)
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Calling plugin AiLenChanged");
|
||||
g_Plugins->Audio()->AiLenChanged();
|
||||
WriteTrace(TraceAudio, TraceDebug, "Plugin AiLenChanged Done");
|
||||
}
|
||||
WriteTrace(TraceAudio, TraceDebug, "Done");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
#include "MemoryHandler.h"
|
||||
#include <Project64-core/N64System/Mips/Audio.h>
|
||||
#include <Project64-core\Settings\DebugSettings.h>
|
||||
#include <Project64-core\Settings\GameSettings.h>
|
||||
#include <Project64-core\Logging.h>
|
||||
|
@ -34,7 +33,6 @@ private:
|
|||
class CRegisters;
|
||||
class CN64System;
|
||||
class CPlugins;
|
||||
class CAudio;
|
||||
|
||||
class AudioInterfaceHandler :
|
||||
public MemoryHandler,
|
||||
|
@ -67,10 +65,15 @@ private:
|
|||
|
||||
void LoadedGameState(void);
|
||||
void SystemReset(void);
|
||||
void LenChanged();
|
||||
|
||||
CN64System & m_System;
|
||||
CRegisters & m_Reg;
|
||||
CPlugins * m_Plugins;
|
||||
CAudio m_Audio;
|
||||
uint32_t & m_PC;
|
||||
uint32_t m_Status;
|
||||
uint32_t m_SecondBuff;
|
||||
uint32_t m_BytesPerSecond;
|
||||
int32_t m_CountsPerByte;
|
||||
int32_t m_FramesPerSecond;
|
||||
};
|
||||
|
|
|
@ -1,146 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include <Project64-core/N64System/Mips/Audio.h>
|
||||
#include <Project64-core/N64System/SystemGlobals.h>
|
||||
#include <Project64-core/N64System/N64System.h>
|
||||
|
||||
CAudio::CAudio()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
CAudio::~CAudio()
|
||||
{
|
||||
}
|
||||
|
||||
void CAudio::Reset()
|
||||
{
|
||||
m_SecondBuff = 0;
|
||||
m_Status = 0;
|
||||
m_BytesPerSecond = 0;
|
||||
m_CountsPerByte = g_System->AiCountPerBytes(); // Should be calculated, see below, instead allow from user settings
|
||||
if (m_CountsPerByte == 0) m_CountsPerByte = 500; // If the user has no defined value, grant a default and we will calculate
|
||||
m_FramesPerSecond = 60;
|
||||
}
|
||||
|
||||
uint32_t CAudio::GetLength()
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Start (m_SecondBuff = %d)", m_SecondBuff);
|
||||
uint32_t TimeLeft = g_SystemTimer->GetTimer(CSystemTimer::AiTimerInterrupt), Res = 0;
|
||||
if (TimeLeft > 0)
|
||||
{
|
||||
Res = (TimeLeft / m_CountsPerByte)&~7;
|
||||
}
|
||||
WriteTrace(TraceAudio, TraceDebug, "Done (res = %d, TimeLeft = %d)", Res, TimeLeft);
|
||||
return Res;
|
||||
}
|
||||
|
||||
uint32_t CAudio::GetStatus()
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "m_Status = %X", m_Status);
|
||||
return m_Status;
|
||||
}
|
||||
|
||||
void CAudio::LenChanged()
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Start (g_Reg->AI_LEN_REG = %d)", g_Reg->AI_LEN_REG);
|
||||
if (g_Reg->AI_LEN_REG != 0)
|
||||
{
|
||||
if (g_Reg->AI_LEN_REG >= 0x40000)
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Ignoring write, to large (%X)", g_Reg->AI_LEN_REG);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Status |= ai_busy;
|
||||
uint32_t AudioLeft = g_SystemTimer->GetTimer(CSystemTimer::AiTimerInterrupt);
|
||||
if (m_SecondBuff == 0)
|
||||
{
|
||||
if (AudioLeft == 0)
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Set timer AI_LEN_REG: %d m_CountsPerByte: %d", g_Reg->AI_LEN_REG, m_CountsPerByte);
|
||||
g_SystemTimer->SetTimer(CSystemTimer::AiTimerInterrupt, g_Reg->AI_LEN_REG * m_CountsPerByte, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Increasing second buffer (m_SecondBuff %d Increase: %d)", m_SecondBuff, g_Reg->AI_LEN_REG);
|
||||
m_SecondBuff += g_Reg->AI_LEN_REG;
|
||||
m_Status |= ai_full;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Reset timer to 0");
|
||||
g_SystemTimer->StopTimer(CSystemTimer::AiTimerBusy);
|
||||
g_SystemTimer->StopTimer(CSystemTimer::AiTimerInterrupt);
|
||||
m_SecondBuff = 0;
|
||||
m_Status = 0;
|
||||
}
|
||||
|
||||
if (g_Plugins->Audio()->AiLenChanged != nullptr)
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Calling plugin AiLenChanged");
|
||||
g_Plugins->Audio()->AiLenChanged();
|
||||
WriteTrace(TraceAudio, TraceDebug, "Plugin AiLenChanged Done");
|
||||
}
|
||||
WriteTrace(TraceAudio, TraceDebug, "Done");
|
||||
}
|
||||
|
||||
void CAudio::InterruptTimerDone()
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Start (m_SecondBuff = %d)", m_SecondBuff);
|
||||
m_Status &= ~ai_full;
|
||||
g_Reg->MI_INTR_REG |= MI_INTR_AI;
|
||||
g_Reg->CheckInterrupts();
|
||||
if (m_SecondBuff != 0)
|
||||
{
|
||||
g_SystemTimer->SetTimer(CSystemTimer::AiTimerInterrupt, m_SecondBuff * m_CountsPerByte, false);
|
||||
m_SecondBuff = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Status &= ~ai_busy;
|
||||
}
|
||||
WriteTrace(TraceAudio, TraceDebug, "Done");
|
||||
}
|
||||
|
||||
void CAudio::BusyTimerDone()
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "Start (m_SecondBuff = %d)", m_SecondBuff);
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
m_Status &= ~ai_busy;
|
||||
}
|
||||
|
||||
void CAudio::SetViIntr(uint32_t VI_INTR_TIME)
|
||||
{
|
||||
double CountsPerSecond = (uint32_t)((double)VI_INTR_TIME * m_FramesPerSecond);
|
||||
if (m_BytesPerSecond != 0 && (g_System->AiCountPerBytes() == 0))
|
||||
{
|
||||
m_CountsPerByte = (int32_t)((double)CountsPerSecond / (double)m_BytesPerSecond);
|
||||
}
|
||||
}
|
||||
|
||||
void CAudio::SetFrequency(uint32_t Dacrate, uint32_t System)
|
||||
{
|
||||
WriteTrace(TraceAudio, TraceDebug, "(Dacrate: %X System: %d): AI_BITRATE_REG = %X", Dacrate, System, g_Reg->AI_BITRATE_REG);
|
||||
uint32_t Frequency;
|
||||
|
||||
switch (System)
|
||||
{
|
||||
case SYSTEM_PAL: Frequency = 49656530 / (Dacrate + 1); break;
|
||||
case SYSTEM_MPAL: Frequency = 48628316 / (Dacrate + 1); break;
|
||||
default: Frequency = 48681812 / (Dacrate + 1); break;
|
||||
}
|
||||
|
||||
//nBlockAlign = 16 / 8 * 2;
|
||||
m_BytesPerSecond = Frequency * 4;
|
||||
//m_BytesPerSecond = 194532;
|
||||
//m_BytesPerSecond = 128024;
|
||||
|
||||
m_FramesPerSecond = System == SYSTEM_PAL ? 50 : 60;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class CAudio
|
||||
{
|
||||
enum
|
||||
{
|
||||
ai_full = 0x80000000,
|
||||
ai_busy = 0x40000000,
|
||||
};
|
||||
public:
|
||||
CAudio();
|
||||
~CAudio();
|
||||
|
||||
uint32_t GetLength();
|
||||
uint32_t GetStatus();
|
||||
void LenChanged();
|
||||
void InterruptTimerDone();
|
||||
void BusyTimerDone();
|
||||
void Reset();
|
||||
void SetViIntr(uint32_t VI_INTR_TIME);
|
||||
void SetFrequency(uint32_t Dacrate, uint32_t System);
|
||||
|
||||
private:
|
||||
CAudio(const CAudio&);
|
||||
CAudio& operator=(const CAudio&);
|
||||
|
||||
uint32_t m_SecondBuff;
|
||||
uint32_t m_Status;
|
||||
uint32_t m_BytesPerSecond;
|
||||
int32_t m_CountsPerByte;
|
||||
int32_t m_FramesPerSecond;
|
||||
};
|
|
@ -61,7 +61,6 @@
|
|||
<ClCompile Include="N64System\MemoryHandler\RDRAMRegistersHandler.cpp" />
|
||||
<ClCompile Include="N64System\MemoryHandler\SPRegistersHandler.cpp" />
|
||||
<ClCompile Include="N64System\MemoryHandler\VideoInterfaceHandler.cpp" />
|
||||
<ClCompile Include="N64System\Mips\Audio.cpp" />
|
||||
<ClCompile Include="N64System\Mips\Disk.cpp" />
|
||||
<ClCompile Include="N64System\Mips\Dma.cpp" />
|
||||
<ClCompile Include="N64System\Mips\Eeprom.cpp" />
|
||||
|
@ -165,7 +164,6 @@
|
|||
<ClInclude Include="N64System\MemoryHandler\RDRAMRegistersHandler.h" />
|
||||
<ClInclude Include="N64System\MemoryHandler\SPRegistersHandler.h" />
|
||||
<ClInclude Include="N64System\MemoryHandler\VideoInterfaceHandler.h" />
|
||||
<ClInclude Include="N64System\Mips\Audio.h" />
|
||||
<ClInclude Include="N64System\Mips\Disk.h" />
|
||||
<ClInclude Include="N64System\Mips\Dma.h" />
|
||||
<ClInclude Include="N64System\Mips\Eeprom.h" />
|
||||
|
|
|
@ -243,9 +243,6 @@
|
|||
<ClCompile Include="N64System\Recompiler\SectionInfo.cpp">
|
||||
<Filter>Source Files\N64 System\Recompiler</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="N64System\Mips\Audio.cpp">
|
||||
<Filter>Source Files\N64 System\Mips</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="N64System\Mips\Dma.cpp">
|
||||
<Filter>Source Files\N64 System\Mips</Filter>
|
||||
</ClCompile>
|
||||
|
@ -566,9 +563,6 @@
|
|||
<ClInclude Include="N64System\Recompiler\SectionInfo.h">
|
||||
<Filter>Header Files\N64 System\Recompiler</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="N64System\Mips\Audio.h">
|
||||
<Filter>Header Files\N64 System\Mips</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="N64System\Mips\Dma.h">
|
||||
<Filter>Header Files\N64 System\Mips</Filter>
|
||||
</ClInclude>
|
||||
|
|
Loading…
Reference in New Issue