diff --git a/src/dmg/gbSound.cpp b/src/dmg/gbSound.cpp index a96e5311..481afd81 100644 --- a/src/dmg/gbSound.cpp +++ b/src/dmg/gbSound.cpp @@ -38,6 +38,7 @@ static Gb_Apu* gb_apu; static float soundVolume_ = -1; static int prevSoundEnable = -1; +static bool declicking = false; int const chan_count = 4; int const ticks_to_time = 2 * GB_APU_OVERCLOCK; @@ -142,10 +143,11 @@ static void reset_apu() Gb_Apu::mode_t mode = Gb_Apu::mode_dmg; if ( gbHardware & 2 ) mode = Gb_Apu::mode_cgb; - if ( gbHardware & 8 ) + if ( gbHardware & 8 || declicking ) mode = Gb_Apu::mode_agb; gb_apu->reset( mode ); - + gb_apu->reduce_clicks( declicking ); + if ( stereo_buffer ) stereo_buffer->clear(); @@ -179,6 +181,28 @@ static void remake_stereo_buffer() apply_volume(); } +void gbSoundSetDeclicking( bool enable ) +{ + if ( declicking != enable ) + { + declicking = enable; + if ( gb_apu ) + { + // Can't change sound hardware mode without resetting APU, so save/load + // state around mode change + gb_apu_state_t state; + gb_apu->save_state( &state ); + reset_apu(); + if ( gb_apu->load_state( state ) ) { } // ignore error + } + } +} + +bool gbSoundGetDeclicking() +{ + return declicking; +} + void gbSoundReset() { SOUND_CLOCK_TICKS = 20000; // 1/100 second diff --git a/src/dmg/gbSound.h b/src/dmg/gbSound.h index 4bab347f..44b7d1db 100644 --- a/src/dmg/gbSound.h +++ b/src/dmg/gbSound.h @@ -11,6 +11,11 @@ void gbSoundSetQuality( int quality ); extern int soundQuality; // current sound quality +// Manages declicking mode. When enabled, clicks are reduced. Note that clicks +// are normal for GB and GBC sound hardware. +void gbSoundSetDeclicking( bool enable ); +bool gbSoundGetDeclicking(); + // Effects configuration struct gb_effects_config_t {