Skip to content

Commit

Permalink
Fix AY8910 volume
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 13, 2024
1 parent 8ef188f commit 13c4cb7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 33 deletions.
6 changes: 3 additions & 3 deletions platforms/desktop-shared/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion platforms/desktop-shared/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions platforms/desktop-shared/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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))
Expand Down
22 changes: 10 additions & 12 deletions src/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Audio::Audio()
m_bPAL = false;
InitPointer(m_pAY8910);
InitPointer(m_pSGMBuffer);
m_bMute = false;
}

Audio::~Audio()
Expand All @@ -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];

Expand All @@ -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)
Expand All @@ -100,7 +94,10 @@ void Audio::EndFrame(s16* pSampleBuffer, int* pSampleCount)

for (int i=0; i<count; i++)
{
pSampleBuffer[i] = m_pSampleBuffer[i] + m_pSGMBuffer[i];
if (m_bMute)
pSampleBuffer[i] = 0;
else
pSampleBuffer[i] = m_pSampleBuffer[i] + m_pSGMBuffer[i];
}
}

Expand All @@ -123,5 +120,6 @@ void Audio::LoadState(std::istream& stream)
m_pAY8910->LoadState(stream);

m_pApu->reset();
m_pApu->volume(0.6);
m_pBuffer->clear();
}
4 changes: 2 additions & 2 deletions src/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions src/GearcolecoCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/GearcolecoCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 13c4cb7

Please sign in to comment.