From 2ec52fb7220e1ac283f23e5f03dd610451bfa6a7 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Wed, 9 Jun 2021 00:49:34 +0300 Subject: [PATCH] sdl2: Add silent mode Former-commit-id: b8e3a8809501f32f819b74a1e4dd094d77a4b367 Former-commit-id: 027be1f05ae9f274e6a3527d209ac5ff696d8c56 --- platform/rustboyadvance-sdl2/src/audio.rs | 9 +++++++++ platform/rustboyadvance-sdl2/src/cli.yml | 3 +++ platform/rustboyadvance-sdl2/src/main.rs | 9 +++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/platform/rustboyadvance-sdl2/src/audio.rs b/platform/rustboyadvance-sdl2/src/audio.rs index b1b2c67..5a746ee 100644 --- a/platform/rustboyadvance-sdl2/src/audio.rs +++ b/platform/rustboyadvance-sdl2/src/audio.rs @@ -11,6 +11,10 @@ struct GbaAudioCallback { spec: AudioSpec, } +pub struct DummyAudioPlayer {} + +impl AudioInterface for DummyAudioPlayer {} + pub struct Sdl2AudioPlayer { _device: AudioDevice, producer: Producer>, @@ -87,3 +91,8 @@ pub fn create_audio_player(sdl: &sdl2::Sdl) -> Sdl2AudioPlayer { producer: producer.unwrap(), } } + +pub fn create_dummy_player() -> DummyAudioPlayer { + info!("Dummy audio device"); + DummyAudioPlayer {} +} diff --git a/platform/rustboyadvance-sdl2/src/cli.yml b/platform/rustboyadvance-sdl2/src/cli.yml index 88d71da..dae9712 100644 --- a/platform/rustboyadvance-sdl2/src/cli.yml +++ b/platform/rustboyadvance-sdl2/src/cli.yml @@ -34,6 +34,9 @@ args: - debug: long: debug help: Use the custom debugger + - silent: + long: silent + help: Do not output sound - with_gdbserver: long: with-gdbserver help: Start with experimental gdbserver diff --git a/platform/rustboyadvance-sdl2/src/main.rs b/platform/rustboyadvance-sdl2/src/main.rs index 7c73728..2b9ff5f 100644 --- a/platform/rustboyadvance-sdl2/src/main.rs +++ b/platform/rustboyadvance-sdl2/src/main.rs @@ -36,7 +36,7 @@ mod audio; mod input; mod video; -use audio::create_audio_player; +use audio::{create_audio_player, create_dummy_player}; use input::create_input; use video::{create_video_interface, SCREEN_HEIGHT, SCREEN_WIDTH}; @@ -131,6 +131,7 @@ fn main() -> Result<(), Box> { let skip_bios = matches.occurrences_of("skip_bios") != 0; let debug = matches.occurrences_of("debug") != 0; + let silent = matches.occurrences_of("silent") != 0; let with_gdbserver = matches.occurrences_of("with_gdbserver") != 0; info!("Initializing SDL2 context"); @@ -183,7 +184,11 @@ fn main() -> Result<(), Box> { }; let video = Rc::new(RefCell::new(create_video_interface(canvas))); - let audio = Rc::new(RefCell::new(create_audio_player(&sdl_context))); + let audio: Rc> = if silent { + Rc::new(RefCell::new(create_dummy_player())) + } else { + Rc::new(RefCell::new(create_audio_player(&sdl_context))) + }; let input = Rc::new(RefCell::new(create_input())); let mut savestate_path = get_savestate_path(&Path::new(&rom_path));