Skip to content

Commit

Permalink
Add toggle for actual sound emulation
Browse files Browse the repository at this point in the history
Disabling sound emulation improves performance.
  • Loading branch information
dariusarnold committed Mar 5, 2023
1 parent 08f0d68 commit 29be91c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/game-boy-emulator/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void Emulator::elapse_cycle() {
m_timer->cycle_elapsed_callback(m_state.cycles_m);
m_ppu->cycle_elapsed_callback(m_state.cycles_m);
m_apu->cycle_elapsed_callback(m_state.cycles_m);
if (m_audio_function) {
if (m_audio_function && m_options.sound_enabled) {
m_audio_function(m_apu->get_sample());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/game-boy-emulator/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct EmulatorOptions {
bool fast_forward = false;
// Fast forward multiplier
int game_speed = 1;
bool sound_enabled = true;
// Global sound volume
float volume = 0.1f;
// Allows toggling the output of a channel of the APU on/off for sound debugging purposes.
Expand Down
18 changes: 14 additions & 4 deletions src/game-boy-emulator/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,33 @@ void draw_menubar_settings_speed(EmulatorOptions& options) {
ImGui::EndMenu();
}

namespace {
std::string_view stringify_bool(bool b) {
return b ? "ON" : "OFF";
}
} // namespace

void draw_menubar_settings_sound(EmulatorOptions& options, float volume) {
if (ImGui::MenuItem(
fmt::format("Toggle sound (Now {})", stringify_bool(options.sound_enabled)).c_str())) {
toggle(options.sound_enabled);
}
ImGui::SliderFloat("Volume", &volume, 0, 1);
options.volume = volume;
auto label
= fmt::format("Toggle channel 1 (Now {})", options.apu_channel1_enabled ? "ON" : "OFF");
= fmt::format("Toggle channel 1 (Now {})", stringify_bool(options.apu_channel1_enabled));
if (ImGui::MenuItem(label.c_str())) {
toggle(options.apu_channel1_enabled);
}
label = fmt::format("Toggle channel 2 (Now {})", options.apu_channel2_enabled ? "ON" : "OFF");
label = fmt::format("Toggle channel 2 (Now {})", stringify_bool(options.apu_channel2_enabled));
if (ImGui::MenuItem(label.c_str())) {
toggle(options.apu_channel2_enabled);
}
label = fmt::format("Toggle channel 3 (Now {})", options.apu_channel2_enabled ? "ON" : "OFF");
label = fmt::format("Toggle channel 3 (Now {})", stringify_bool(options.apu_channel2_enabled));
if (ImGui::MenuItem(label.c_str())) {
toggle(options.apu_channel3_enabled);
}
label = fmt::format("Toggle channel 4 (Now {})", options.apu_channel2_enabled ? "ON" : "OFF");
label = fmt::format("Toggle channel 4 (Now {})", stringify_bool(options.apu_channel2_enabled));
if (ImGui::MenuItem(label.c_str())) {
toggle(options.apu_channel4_enabled);
}
Expand Down

0 comments on commit 29be91c

Please sign in to comment.