diff --git a/frontends/web/react/components/audio-gb/audio-gb.tsx b/frontends/web/react/components/audio-gb/audio-gb.tsx index 79c52aa0ec2d646cb1a34c7acab5b200bdf68d8d..ae6eb83c7a0388c8b0c5aaa9f07396d8ae647d82 100644 --- a/frontends/web/react/components/audio-gb/audio-gb.tsx +++ b/frontends/web/react/components/audio-gb/audio-gb.tsx @@ -34,10 +34,18 @@ export const AudioGB: FC<AudioGBProps> = ({ const [audioOutput, setAudioOutput] = useState<Record<string, number[]>>( {} ); - const [ch1Enabled, setCh1Enabled] = useState(true); - const [ch2Enabled, setCh2Enabled] = useState(true); - const [ch3Enabled, setCh3Enabled] = useState(true); - const [ch4Enabled, setCh4Enabled] = useState(true); + const [ch1Enabled, setCh1Enabled] = useState( + emulator.instance?.audio_ch1_enabled() ?? true + ); + const [ch2Enabled, setCh2Enabled] = useState( + emulator.instance?.audio_ch2_enabled() ?? true + ); + const [ch3Enabled, setCh3Enabled] = useState( + emulator.instance?.audio_ch3_enabled() ?? true + ); + const [ch4Enabled, setCh4Enabled] = useState( + emulator.instance?.audio_ch4_enabled() ?? true + ); const intervalsRef = useRef<number>(); const intervalsExtraRef = useRef<number>(); @@ -184,7 +192,7 @@ export const AudioGB: FC<AudioGBProps> = ({ "ch1", ["selector", ch1Enabled ? "" : "disabled"], () => { - emulator.instance?.audio_ch1_enabled(!ch1Enabled); + emulator.instance?.set_audio_ch1_enabled(!ch1Enabled); setCh1Enabled(!ch1Enabled); } )} @@ -193,7 +201,7 @@ export const AudioGB: FC<AudioGBProps> = ({ "ch2", ["selector", ch2Enabled ? "" : "disabled"], () => { - emulator.instance?.audio_ch2_enabled(!ch2Enabled); + emulator.instance?.set_audio_ch2_enabled(!ch2Enabled); setCh2Enabled(!ch2Enabled); } )} @@ -202,7 +210,7 @@ export const AudioGB: FC<AudioGBProps> = ({ "ch3", ["selector", ch3Enabled ? "" : "disabled"], () => { - emulator.instance?.audio_ch3_enabled(!ch3Enabled); + emulator.instance?.set_audio_ch3_enabled(!ch3Enabled); setCh3Enabled(!ch3Enabled); } )} @@ -211,7 +219,7 @@ export const AudioGB: FC<AudioGBProps> = ({ "ch4", ["selector", ch4Enabled ? "" : "disabled"], () => { - emulator.instance?.audio_ch4_enabled(!ch4Enabled); + emulator.instance?.set_audio_ch4_enabled(!ch4Enabled); setCh4Enabled(!ch4Enabled); } )} diff --git a/src/gb.rs b/src/gb.rs index da6f95204cfc78e1570aae066afb1da37eb30546..67244e46509261f0fb9694fb8250bba3c1673fb7 100644 --- a/src/gb.rs +++ b/src/gb.rs @@ -557,19 +557,35 @@ impl GameBoy { self.apu_i().ch4_output() } - pub fn audio_ch1_enabled(&mut self, enabled: bool) { + pub fn audio_ch1_enabled(&mut self) -> bool { + self.apu().ch2_enabled() + } + + pub fn set_audio_ch1_enabled(&mut self, enabled: bool) { self.apu().set_ch1_enabled(enabled) } - pub fn audio_ch2_enabled(&mut self, enabled: bool) { + pub fn audio_ch2_enabled(&mut self) -> bool { + self.apu().ch2_enabled() + } + + pub fn set_audio_ch2_enabled(&mut self, enabled: bool) { self.apu().set_ch2_enabled(enabled) } - pub fn audio_ch3_enabled(&mut self, enabled: bool) { + pub fn audio_ch3_enabled(&mut self) -> bool { + self.apu().ch3_enabled() + } + + pub fn set_audio_ch3_enabled(&mut self, enabled: bool) { self.apu().set_ch3_enabled(enabled) } - pub fn audio_ch4_enabled(&mut self, enabled: bool) { + pub fn audio_ch4_enabled(&mut self) -> bool { + self.apu().ch4_enabled() + } + + pub fn set_audio_ch4_enabled(&mut self, enabled: bool) { self.apu().set_ch4_enabled(enabled) }