sdl2: Add silent mode

Former-commit-id: b8e3a8809501f32f819b74a1e4dd094d77a4b367
Former-commit-id: 027be1f05ae9f274e6a3527d209ac5ff696d8c56
This commit is contained in:
Michel Heily 2021-06-09 00:49:34 +03:00
parent 67c071595a
commit 2ec52fb722
3 changed files with 19 additions and 2 deletions

View file

@ -11,6 +11,10 @@ struct GbaAudioCallback {
spec: AudioSpec, spec: AudioSpec,
} }
pub struct DummyAudioPlayer {}
impl AudioInterface for DummyAudioPlayer {}
pub struct Sdl2AudioPlayer { pub struct Sdl2AudioPlayer {
_device: AudioDevice<GbaAudioCallback>, _device: AudioDevice<GbaAudioCallback>,
producer: Producer<StereoSample<i16>>, producer: Producer<StereoSample<i16>>,
@ -87,3 +91,8 @@ pub fn create_audio_player(sdl: &sdl2::Sdl) -> Sdl2AudioPlayer {
producer: producer.unwrap(), producer: producer.unwrap(),
} }
} }
pub fn create_dummy_player() -> DummyAudioPlayer {
info!("Dummy audio device");
DummyAudioPlayer {}
}

View file

@ -34,6 +34,9 @@ args:
- debug: - debug:
long: debug long: debug
help: Use the custom debugger help: Use the custom debugger
- silent:
long: silent
help: Do not output sound
- with_gdbserver: - with_gdbserver:
long: with-gdbserver long: with-gdbserver
help: Start with experimental gdbserver help: Start with experimental gdbserver

View file

@ -36,7 +36,7 @@ mod audio;
mod input; mod input;
mod video; mod video;
use audio::create_audio_player; use audio::{create_audio_player, create_dummy_player};
use input::create_input; use input::create_input;
use video::{create_video_interface, SCREEN_HEIGHT, SCREEN_WIDTH}; use video::{create_video_interface, SCREEN_HEIGHT, SCREEN_WIDTH};
@ -131,6 +131,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let skip_bios = matches.occurrences_of("skip_bios") != 0; let skip_bios = matches.occurrences_of("skip_bios") != 0;
let debug = matches.occurrences_of("debug") != 0; let debug = matches.occurrences_of("debug") != 0;
let silent = matches.occurrences_of("silent") != 0;
let with_gdbserver = matches.occurrences_of("with_gdbserver") != 0; let with_gdbserver = matches.occurrences_of("with_gdbserver") != 0;
info!("Initializing SDL2 context"); info!("Initializing SDL2 context");
@ -183,7 +184,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}; };
let video = Rc::new(RefCell::new(create_video_interface(canvas))); let video = Rc::new(RefCell::new(create_video_interface(canvas)));
let audio = Rc::new(RefCell::new(create_audio_player(&sdl_context))); let audio: Rc<RefCell<dyn AudioInterface>> = 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 input = Rc::new(RefCell::new(create_input()));
let mut savestate_path = get_savestate_path(&Path::new(&rom_path)); let mut savestate_path = get_savestate_path(&Path::new(&rom_path));