Integrate CStreamAudioManager globals

This commit is contained in:
Jack Andersen 2017-01-15 23:14:54 -10:00
parent 01c31b4fc5
commit d66d9a24f4
3 changed files with 69 additions and 12 deletions

View File

@ -238,7 +238,7 @@ struct SDSPStream
m_booVoice = CAudioSys::GetVoiceEngine()->allocateNewMonoVoice(32000.0, &m_booCallback); m_booVoice = CAudioSys::GetVoiceEngine()->allocateNewMonoVoice(32000.0, &m_booCallback);
} }
static void PreallocateAllStreams() static void Initialize()
{ {
for (int i=0 ; i<4 ; ++i) for (int i=0 ; i<4 ; ++i)
{ {
@ -299,6 +299,20 @@ struct SDSPStream
m_booVoice->setMonoChannelLevels(nullptr, coefs, true); m_booVoice->setMonoChannelLevels(nullptr, coefs, true);
} }
static void UpdateVolume(u32 id, u8 vol)
{
u32 idx = FindStreamIdx(id);
if (idx == -1)
return;
SDSPStream& stream = g_Streams[idx];
stream.UpdateStreamVolume(vol);
if (SDSPStream* left = stream.x8_stereoLeft)
left->UpdateStreamVolume(vol);
if (SDSPStream* right = stream.xc_stereoRight)
right->UpdateStreamVolume(vol);
}
void SilenceStream() void SilenceStream()
{ {
if (!x0_active || xe8_silent) if (!x0_active || xe8_silent)
@ -324,7 +338,9 @@ struct SDSPStream
void StopStream() void StopStream()
{ {
x0_active = false;
m_booVoice->stop(); m_booVoice->stop();
m_file = std::experimental::nullopt;
} }
static bool IsStreamActive(u32 id) static bool IsStreamActive(u32 id)
@ -404,9 +420,9 @@ class CDSPStreamManager
public: public:
enum class EState enum class EState
{ {
Zero, Looping,
One, Oneshot,
Two Preparing
}; };
private: private:
@ -518,17 +534,17 @@ public:
{ {
u32 idx = FindClaimedStreamIdx(handle); u32 idx = FindClaimedStreamIdx(handle);
if (idx == -1) if (idx == -1)
return EState::One; return EState::Oneshot;
CDSPStreamManager& stream = g_Streams[idx]; CDSPStreamManager& stream = g_Streams[idx];
switch (stream.x70_26_headerReadState) switch (stream.x70_26_headerReadState)
{ {
case 0: case 0:
return EState::One; return EState::Oneshot;
case 2: case 2:
return EState(!stream.x0_header.xc_loop_flag); return EState(!stream.x0_header.xc_loop_flag);
default: default:
return EState::Two; return EState::Preparing;
} }
} }
@ -613,8 +629,6 @@ public:
return; return;
} }
x70_26_headerReadState = 2; x70_26_headerReadState = 2;
u32 companion = -1; u32 companion = -1;
@ -626,14 +640,29 @@ public:
if (companion != -1) if (companion != -1)
{ {
/* Stereo */ /* Stereo */
CDSPStreamManager& companionStream = g_Streams[companion];
if (companionStream.x70_24_unclaimed ||
companionStream.x70_26_headerReadState == 0 ||
(companionStream.x71_companionRight != selfIdx &&
companionStream.x72_companionLeft != selfIdx))
{
*this = CDSPStreamManager();
return;
}
if (companionStream.x70_26_headerReadState == 1)
return;
if (companionStream.x71_companionRight != -1)
AllocateStream(companion);
else
AllocateStream(selfIdx);
} }
else else
{ {
/* Mono */ /* Mono */
AllocateStream(selfIdx); AllocateStream(selfIdx);
} }
} }
static bool StartHeaderRead(CDSPStreamManager& stream) static bool StartHeaderRead(CDSPStreamManager& stream)
@ -756,7 +785,26 @@ public:
static void UpdateVolume(u32 handle, u8 volume) static void UpdateVolume(u32 handle, u8 volume)
{ {
u32 idx = FindClaimedStreamIdx(handle);
if (idx == -1)
return;
CDSPStreamManager& stream = g_Streams[idx];
stream.x73_volume = volume;
if (stream.x7c_streamId == -1)
return;
SDSPStream::UpdateVolume(stream.x7c_streamId, volume);
}
static void Initialize()
{
SDSPStream::Initialize();
for (int i=0 ; i<4 ; ++i)
{
CDSPStreamManager& stream = g_Streams[i];
stream = CDSPStreamManager();
}
} }
}; };
@ -948,7 +996,7 @@ void CStreamAudioManager::UpdateDSP(bool oneshot, float dt)
else else
{ {
if (p.x10_playState != EPlayerState::Stopped && if (p.x10_playState != EPlayerState::Stopped &&
CDSPStreamManager::GetStreamState(p.x20_internalHandle) == CDSPStreamManager::EState::One && CDSPStreamManager::GetStreamState(p.x20_internalHandle) == CDSPStreamManager::EState::Oneshot &&
CDSPStreamManager::CanStop(p.x20_internalHandle)) CDSPStreamManager::CanStop(p.x20_internalHandle))
{ {
StopStreaming(oneshot); StopStreaming(oneshot);
@ -1018,6 +1066,11 @@ void CStreamAudioManager::Update(float dt)
UpdateDSPStreamers(dt); UpdateDSPStreamers(dt);
} }
void CStreamAudioManager::Initialize()
{
CDSPStreamManager::Initialize();
}
u8 CStreamAudioManager::g_MusicVolume = 0x7f; u8 CStreamAudioManager::g_MusicVolume = 0x7f;
u8 CStreamAudioManager::g_SfxVolume = 0x7f; u8 CStreamAudioManager::g_SfxVolume = 0x7f;
bool CStreamAudioManager::g_MusicUnmute = true; bool CStreamAudioManager::g_MusicUnmute = true;

View File

@ -25,6 +25,7 @@ public:
static void FadeBackIn(bool oneshot, float fadeTime); static void FadeBackIn(bool oneshot, float fadeTime);
static void TemporaryFadeOut(bool oneshot, float fadeTime); static void TemporaryFadeOut(bool oneshot, float fadeTime);
static void Update(float dt); static void Update(float dt);
static void Initialize();
}; };
} }

View File

@ -8,6 +8,7 @@
#include "Graphics/Shaders/CCameraBlurFilter.hpp" #include "Graphics/Shaders/CCameraBlurFilter.hpp"
#include "Graphics/Shaders/CXRayBlurFilter.hpp" #include "Graphics/Shaders/CXRayBlurFilter.hpp"
#include "Character/CCharLayoutInfo.hpp" #include "Character/CCharLayoutInfo.hpp"
#include "Audio/CStreamAudioManager.hpp"
#include "CGBASupport.hpp" #include "CGBASupport.hpp"
#include "CBasics.hpp" #include "CBasics.hpp"
@ -35,6 +36,7 @@ CGameArchitectureSupport::CGameArchitectureSupport(CMain& parent, boo::IAudioVoi
{ {
g_GuiSys = &x44_guiSys; g_GuiSys = &x44_guiSys;
x30_inputGenerator.startScanning(); x30_inputGenerator.startScanning();
CStreamAudioManager::Initialize();
g_Main->ResetGameState(); g_Main->ResetGameState();
std::shared_ptr<CIOWin> splash = std::make_shared<CSplashScreen>(CSplashScreen::ESplashScreen::Nintendo); std::shared_ptr<CIOWin> splash = std::make_shared<CSplashScreen>(CSplashScreen::ESplashScreen::Nintendo);
@ -160,6 +162,7 @@ bool CMain::Proc()
{ {
CGBASupport::GlobalPoll(); CGBASupport::GlobalPoll();
xe8_b24_finished = m_archSupport->Update(); xe8_b24_finished = m_archSupport->Update();
CStreamAudioManager::Update(1.f / 60.f);
return xe8_b24_finished; return xe8_b24_finished;
} }