From ea917e77c2879204c3f4885ab33b600b34041aed Mon Sep 17 00:00:00 2001 From: Sour Date: Tue, 5 Nov 2024 18:19:54 +0900 Subject: [PATCH] SMS: Fixed crackling in audio in PAL mode --- Core/SMS/SmsConsole.cpp | 5 +++-- Core/SMS/SmsPsg.cpp | 9 +++++++++ Core/SMS/SmsPsg.h | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Core/SMS/SmsConsole.cpp b/Core/SMS/SmsConsole.cpp index c332a718..3ae67e92 100644 --- a/Core/SMS/SmsConsole.cpp +++ b/Core/SMS/SmsConsole.cpp @@ -54,7 +54,7 @@ LoadRomResult SmsConsole::LoadRom(VirtualFile& romFile) _romFormat = RomFormat::Sms; _model = SmsModel::Sms; } - + _vdp.reset(new SmsVdp()); _memoryManager.reset(new SmsMemoryManager()); _cpu.reset(new SmsCpu()); @@ -74,7 +74,7 @@ LoadRomResult SmsConsole::LoadRom(VirtualFile& romFile) _memoryManager->Init(_emu, this, romData, biosRom, _vdp.get(), _controlManager.get(), _cart.get(), _psg.get(), _fmAudio.get()); _vdp->Init(_emu, this, _cpu.get(), _controlManager.get(), _memoryManager.get()); _cpu->Init(_emu, this, _memoryManager.get()); - + UpdateRegion(true); return LoadRomResult::Success; @@ -186,6 +186,7 @@ void SmsConsole::UpdateRegion(bool forceUpdate) if(_region != region || forceUpdate) { _region = region; _vdp->SetRegion(_model == SmsModel::GameGear ? ConsoleRegion::Ntsc : _region); + _psg->SetRegion(_model == SmsModel::GameGear ? ConsoleRegion::Ntsc : _region); } } diff --git a/Core/SMS/SmsPsg.cpp b/Core/SMS/SmsPsg.cpp index da53404b..54014d9f 100644 --- a/Core/SMS/SmsPsg.cpp +++ b/Core/SMS/SmsPsg.cpp @@ -28,6 +28,15 @@ SmsPsg::SmsPsg(Emulator* emu, SmsConsole* console) blip_set_rates(_rightChannel, _console->GetMasterClockRate(), SmsPsg::SampleRate); } +void SmsPsg::SetRegion(ConsoleRegion region) +{ + blip_clear(_leftChannel); + blip_clear(_rightChannel); + + blip_set_rates(_leftChannel, _console->GetMasterClockRate(), SmsPsg::SampleRate); + blip_set_rates(_rightChannel, _console->GetMasterClockRate(), SmsPsg::SampleRate); +} + void SmsPsg::RunNoise(SmsNoiseChannelState& noise) { if(noise.Timer == 0 || --noise.Timer == 0) { diff --git a/Core/SMS/SmsPsg.h b/Core/SMS/SmsPsg.h index 2e8503f5..0fbb4068 100644 --- a/Core/SMS/SmsPsg.h +++ b/Core/SMS/SmsPsg.h @@ -35,6 +35,8 @@ public: SmsPsgState& GetState() { return _state; } + void SetRegion(ConsoleRegion region); + void Run(); void PlayQueuedAudio();