AudioCommon: Move sound stream variables to Core::System.

This commit is contained in:
Admiral H. Curtiss
2022-08-31 21:44:21 +02:00
parent 9195e1a9b8
commit c310e504cb
10 changed files with 139 additions and 51 deletions

View File

@ -956,10 +956,12 @@ void UpdateTitle(u64 elapsed_ms)
}
// Update the audio timestretcher with the current speed
if (g_sound_stream)
auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
if (sound_stream)
{
Mixer* pMixer = g_sound_stream->GetMixer();
pMixer->UpdateSpeed((float)Speed / 100);
Mixer* mixer = sound_stream->GetMixer();
mixer->UpdateSpeed((float)Speed / 100);
}
Host_UpdateTitle(message);

View File

@ -48,6 +48,7 @@ This file mainly deals with the [Drive I/F], however [AIDFR] controls
#include "Core/HW/ProcessorInterface.h"
#include "Core/HW/SystemTimers.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
namespace AudioInterface
{
@ -126,7 +127,9 @@ void DoState(PointerWrap& p)
p.Do(s_aid_sample_rate_divisor);
p.Do(s_cpu_cycles_per_sample);
g_sound_stream->GetMixer()->DoState(p);
auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
sound_stream->GetMixer()->DoState(p);
}
static void GenerateAudioInterrupt();
@ -155,8 +158,10 @@ void Init()
event_type_ai = CoreTiming::RegisterEvent("AICallback", Update);
g_sound_stream->GetMixer()->SetDMAInputSampleRateDivisor(GetAIDSampleRateDivisor());
g_sound_stream->GetMixer()->SetStreamInputSampleRateDivisor(GetAISSampleRateDivisor());
auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
sound_stream->GetMixer()->SetDMAInputSampleRateDivisor(GetAIDSampleRateDivisor());
sound_stream->GetMixer()->SetStreamInputSampleRateDivisor(GetAISSampleRateDivisor());
}
void Shutdown()
@ -182,6 +187,9 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
s_control.AIINTVLD = tmp_ai_ctrl.AIINTVLD;
}
auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
// Set frequency of streaming audio
if (tmp_ai_ctrl.AISFR != s_control.AISFR)
{
@ -191,7 +199,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
s_control.AISFR = tmp_ai_ctrl.AISFR;
s_ais_sample_rate_divisor =
tmp_ai_ctrl.AISFR ? Get48KHzSampleRateDivisor() : Get32KHzSampleRateDivisor();
g_sound_stream->GetMixer()->SetStreamInputSampleRateDivisor(s_ais_sample_rate_divisor);
sound_stream->GetMixer()->SetStreamInputSampleRateDivisor(s_ais_sample_rate_divisor);
s_cpu_cycles_per_sample = static_cast<u64>(SystemTimers::GetTicksPerSecond()) *
s_ais_sample_rate_divisor / Mixer::FIXED_SAMPLE_RATE_DIVIDEND;
}
@ -203,7 +211,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
s_control.AIDFR = tmp_ai_ctrl.AIDFR;
s_aid_sample_rate_divisor =
tmp_ai_ctrl.AIDFR ? Get32KHzSampleRateDivisor() : Get48KHzSampleRateDivisor();
g_sound_stream->GetMixer()->SetDMAInputSampleRateDivisor(s_aid_sample_rate_divisor);
sound_stream->GetMixer()->SetDMAInputSampleRateDivisor(s_aid_sample_rate_divisor);
}
// Streaming counter
@ -240,7 +248,9 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
mmio->Register(base | AI_VOLUME_REGISTER, MMIO::DirectRead<u32>(&s_volume.hex),
MMIO::ComplexWrite<u32>([](u32, u32 val) {
s_volume.hex = val;
g_sound_stream->GetMixer()->SetStreamingVolume(s_volume.left, s_volume.right);
auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
sound_stream->GetMixer()->SetStreamingVolume(s_volume.left, s_volume.right);
}));
mmio->Register(base | AI_SAMPLE_COUNTER, MMIO::ComplexRead<u32>([](u32) {

View File

@ -34,6 +34,7 @@
#include "Core/IOS/DI/DI.h"
#include "Core/IOS/IOS.h"
#include "Core/Movie.h"
#include "Core/System.h"
#include "DiscIO/Blob.h"
#include "DiscIO/DiscUtils.h"
@ -312,7 +313,10 @@ static void DTKStreamingCallback(DIInterruptType interrupt_type, const std::vect
// Send audio to the mixer.
std::vector<s16> temp_pcm(s_pending_samples * 2, 0);
ProcessDTKSamples(&temp_pcm, audio_data);
g_sound_stream->GetMixer()->PushStreamingSamples(temp_pcm.data(), s_pending_samples);
auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
sound_stream->GetMixer()->PushStreamingSamples(temp_pcm.data(), s_pending_samples);
if (s_stream && AudioInterface::IsPlaying())
{

View File

@ -30,6 +30,7 @@
#include "Core/HW/SystemTimers.h"
#include "Core/Host.h"
#include "Core/NetPlayProto.h"
#include "Core/System.h"
namespace HW::GBA
{
@ -403,7 +404,10 @@ void Core::SetSampleRates()
m_core->setAudioBufferSize(m_core, SAMPLES);
blip_set_rates(m_core->getAudioChannel(m_core, 0), m_core->frequency(m_core), SAMPLE_RATE);
blip_set_rates(m_core->getAudioChannel(m_core, 1), m_core->frequency(m_core), SAMPLE_RATE);
g_sound_stream->GetMixer()->SetGBAInputSampleRateDivisors(
auto& system = ::Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
sound_stream->GetMixer()->SetGBAInputSampleRateDivisors(
m_device_number, Mixer::FIXED_SAMPLE_RATE_DIVIDEND / SAMPLE_RATE);
}
@ -436,7 +440,10 @@ void Core::SetAVStream()
std::vector<s16> buffer(SAMPLES * 2);
blip_read_samples(left, &buffer[0], SAMPLES, 1);
blip_read_samples(right, &buffer[1], SAMPLES, 1);
g_sound_stream->GetMixer()->PushGBASamples(core->m_device_number, &buffer[0], SAMPLES);
auto& system = ::Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
sound_stream->GetMixer()->PushGBASamples(core->m_device_number, &buffer[0], SAMPLES);
};
m_core->setAVStream(m_core, &m_stream);
}

View File

@ -11,6 +11,7 @@
#include "Common/MathUtil.h"
#include "Core/ConfigManager.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/System.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
@ -141,11 +142,14 @@ void SpeakerLogic::SpeakerData(const u8* data, int length, float speaker_pan)
const u32 l_volume = std::min(u32(std::min(1.f - speaker_pan, 1.f) * volume), 255u);
const u32 r_volume = std::min(u32(std::min(1.f + speaker_pan, 1.f) * volume), 255u);
g_sound_stream->GetMixer()->SetWiimoteSpeakerVolume(l_volume, r_volume);
auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
sound_stream->GetMixer()->SetWiimoteSpeakerVolume(l_volume, r_volume);
// ADPCM sample rate is thought to be x2.(3000 x2 = 6000).
const unsigned int sample_rate = sample_rate_dividend / reg_data.sample_rate;
g_sound_stream->GetMixer()->PushWiimoteSpeakerSamples(
sound_stream->GetMixer()->PushWiimoteSpeakerSamples(
samples.get(), sample_length, Mixer::FIXED_SAMPLE_RATE_DIVIDEND / (sample_rate * 2));
#ifdef WIIMOTE_SPEAKER_DUMP

View File

@ -3,12 +3,18 @@
#include "Core/System.h"
#include <memory>
#include "AudioCommon/SoundStream.h"
#include "Core/Config/MainSettings.h"
namespace Core
{
struct System::Impl
{
std::unique_ptr<SoundStream> m_sound_stream;
bool m_sound_stream_running = false;
bool m_audio_dump_started = false;
};
System::System() : m_impl{std::make_unique<Impl>()}
@ -22,4 +28,34 @@ void System::Initialize()
m_separate_cpu_and_gpu_threads = Config::Get(Config::MAIN_CPU_THREAD);
m_mmu_enabled = Config::Get(Config::MAIN_MMU);
}
SoundStream* System::GetSoundStream() const
{
return m_impl->m_sound_stream.get();
}
void System::SetSoundStream(std::unique_ptr<SoundStream> sound_stream)
{
m_impl->m_sound_stream = std::move(sound_stream);
}
bool System::IsSoundStreamRunning() const
{
return m_impl->m_sound_stream_running;
}
void System::SetSoundStreamRunning(bool running)
{
m_impl->m_sound_stream_running = running;
}
bool System::IsAudioDumpStarted() const
{
return m_impl->m_audio_dump_started;
}
void System::SetAudioDumpStarted(bool started)
{
m_impl->m_audio_dump_started = started;
}
} // namespace Core

View File

@ -5,6 +5,8 @@
#include <memory>
class SoundStream;
namespace Core
{
// Central class that encapsulates the running system.
@ -31,6 +33,13 @@ public:
bool IsDualCoreMode() const { return m_separate_cpu_and_gpu_threads; }
bool IsMMUMode() const { return m_mmu_enabled; }
SoundStream* GetSoundStream() const;
void SetSoundStream(std::unique_ptr<SoundStream> sound_stream);
bool IsSoundStreamRunning() const;
void SetSoundStreamRunning(bool running);
bool IsAudioDumpStarted() const;
void SetAudioDumpStarted(bool started);
private:
System();