From 13c4cb78e3f1351c9f6d9e669391d705021f1717 Mon Sep 17 00:00:00 2001 From: Ignacio Sanchez Gines <863613+drhelius@users.noreply.github.com> Date: Sat, 13 Jan 2024 01:24:59 +0100 Subject: [PATCH] Fix AY8910 volume --- platforms/desktop-shared/emu.cpp | 6 +++--- platforms/desktop-shared/emu.h | 2 +- platforms/desktop-shared/gui.cpp | 4 ++-- src/Audio.cpp | 22 ++++++++++------------ src/Audio.h | 4 ++-- src/GearcolecoCore.cpp | 11 ----------- src/GearcolecoCore.h | 2 -- 7 files changed, 18 insertions(+), 33 deletions(-) diff --git a/platforms/desktop-shared/emu.cpp b/platforms/desktop-shared/emu.cpp index f1a86bf..8db1d3f 100644 --- a/platforms/desktop-shared/emu.cpp +++ b/platforms/desktop-shared/emu.cpp @@ -185,10 +185,10 @@ void emu_dissasemble_rom(void) gearcoleco->SaveDisassembledROM(); } -void emu_audio_volume(float volume) +void emu_audio_mute(bool mute) { - audio_enabled = (volume > 0.0f); - gearcoleco->SetSoundVolume(volume); + audio_enabled = !mute; + gearcoleco->GetAudio()->Mute(mute); } void emu_audio_reset(void) diff --git a/platforms/desktop-shared/emu.h b/platforms/desktop-shared/emu.h index aca8fc2..c627a73 100644 --- a/platforms/desktop-shared/emu.h +++ b/platforms/desktop-shared/emu.h @@ -57,7 +57,7 @@ EXTERN bool emu_is_empty(void); EXTERN bool emu_is_bios_loaded(void); EXTERN void emu_reset(Cartridge::ForceConfiguration config); EXTERN void emu_dissasemble_rom(void); -EXTERN void emu_audio_volume(float volume); +EXTERN void emu_audio_mute(bool mute); EXTERN void emu_audio_reset(void); EXTERN bool emu_is_audio_enabled(void); EXTERN void emu_palette(GC_Color* palette); diff --git a/platforms/desktop-shared/gui.cpp b/platforms/desktop-shared/gui.cpp index 111b988..e9edb1a 100644 --- a/platforms/desktop-shared/gui.cpp +++ b/platforms/desktop-shared/gui.cpp @@ -101,7 +101,7 @@ void gui_init(void) update_palette(); - emu_audio_volume(config_audio.enable ? 1.0f: 0.0f); + emu_audio_mute(!config_audio.enable); strcpy(bios_path, config_emulator.bios_path.c_str()); strcpy(savefiles_path, config_emulator.savefiles_path.c_str()); @@ -717,7 +717,7 @@ static void main_menu(void) if (ImGui::MenuItem("Enable Audio", "", &config_audio.enable)) { - emu_audio_volume(config_audio.enable ? 1.0f: 0.0f); + emu_audio_mute(!config_audio.enable); } if (ImGui::MenuItem("Sync With Emulator", "", &config_audio.sync)) diff --git a/src/Audio.cpp b/src/Audio.cpp index 163ba3b..1b7c882 100644 --- a/src/Audio.cpp +++ b/src/Audio.cpp @@ -29,6 +29,7 @@ Audio::Audio() m_bPAL = false; InitPointer(m_pAY8910); InitPointer(m_pSGMBuffer); + m_bMute = false; } Audio::~Audio() @@ -54,6 +55,7 @@ void Audio::Init() //m_pBuffer->bass_freq(100); m_pApu->output(m_pBuffer->center(), m_pBuffer->left(), m_pBuffer->right()); + m_pApu->volume(0.6); m_pSGMBuffer = new s16[GC_AUDIO_BUFFER_SIZE]; @@ -65,24 +67,16 @@ void Audio::Reset(bool bPAL) { m_bPAL = bPAL; m_pApu->reset(); + m_pApu->volume(0.6); m_pBuffer->clear(); m_pBuffer->clock_rate(m_bPAL ? GC_MASTER_CLOCK_PAL : GC_MASTER_CLOCK_NTSC); m_ElapsedCycles = 0; m_pAY8910->Reset(m_bPAL ? GC_MASTER_CLOCK_PAL : GC_MASTER_CLOCK_NTSC); } -void Audio::SetSampleRate(int rate) +void Audio::Mute(bool mute) { - if (rate != m_iSampleRate) - { - m_iSampleRate = rate; - m_pBuffer->set_sample_rate(m_iSampleRate); - } -} - -void Audio::SetVolume(float volume) -{ - m_pApu->volume(volume); + m_bMute = mute; } void Audio::EndFrame(s16* pSampleBuffer, int* pSampleCount) @@ -100,7 +94,10 @@ void Audio::EndFrame(s16* pSampleBuffer, int* pSampleCount) for (int i=0; iLoadState(stream); m_pApu->reset(); + m_pApu->volume(0.6); m_pBuffer->clear(); } diff --git a/src/Audio.h b/src/Audio.h index 2a124cf..94cbede 100644 --- a/src/Audio.h +++ b/src/Audio.h @@ -32,8 +32,7 @@ class Audio ~Audio(); void Init(); void Reset(bool bPAL); - void SetSampleRate(int rate); - void SetVolume(float volume); + void Mute(bool mute); void WriteAudioRegister(u8 value); void SGMWrite(u8 value); u8 SGMRead(); @@ -54,6 +53,7 @@ class Audio u8 m_SGMRegister; u8 m_SGMRegisters[16]; s16* m_pSGMBuffer; + bool m_bMute; }; inline void Audio::Tick(unsigned int clockCycles) diff --git a/src/GearcolecoCore.cpp b/src/GearcolecoCore.cpp index fe06f62..a05a875 100644 --- a/src/GearcolecoCore.cpp +++ b/src/GearcolecoCore.cpp @@ -307,17 +307,6 @@ void GearcolecoCore::ResetSound() m_pAudio->Reset(m_pCartridge->IsPAL()); } -void GearcolecoCore::SetSoundSampleRate(int rate) -{ - Log("Gearcoleco sound sample rate: %d", rate); - m_pAudio->SetSampleRate(rate); -} - -void GearcolecoCore::SetSoundVolume(float volume) -{ - m_pAudio->SetVolume(volume); -} - void GearcolecoCore::SaveRam() { SaveRam(NULL); diff --git a/src/GearcolecoCore.h b/src/GearcolecoCore.h index 901bac3..5cf1aca 100644 --- a/src/GearcolecoCore.h +++ b/src/GearcolecoCore.h @@ -51,8 +51,6 @@ class GearcolecoCore void ResetROM(Cartridge::ForceConfiguration* config = NULL); void ResetROMPreservingRAM(Cartridge::ForceConfiguration* config = NULL); void ResetSound(); - void SetSoundSampleRate(int rate); - void SetSoundVolume(float volume); void SaveRam(); void SaveRam(const char* szPath, bool fullPath = false); void LoadRam();