Skip to content

Commit

Permalink
Front: Better handling for audio player
Browse files Browse the repository at this point in the history
Fixes #59.

If audio option isn't specified, we won't initialize it, and if it was
specified but couldn't initialize it will still work but print an error

Signed-off-by: Amjad Alsharafi <26300843+Amjad50@users.noreply.github.com>
  • Loading branch information
Amjad50 committed Sep 22, 2024
1 parent 8d51934 commit 4583a9e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,22 @@ fn main() {

let mut debugger = Debugger::new();

let mut audio_player = AudioPlayer::<f32>::new(44100, BufferSize::QuarterSecond).unwrap();
if args.audio {
audio_player.play().unwrap();
}
let mut audio_player = if args.audio {
let audio_player = AudioPlayer::<f32>::new(44100, BufferSize::QuarterSecond);

match audio_player {
Ok(p) => {
p.play().expect("Audio device to play");
Some(p)
}
Err(e) => {
log::error!("Failed to initialize audio player: {:?}", e);
None
}
}
} else {
None
};

display.run(move |display, event| {
if let Event::WindowEvent { event, .. } = event {
Expand Down Expand Up @@ -635,7 +647,7 @@ fn main() {
debugger.handle_cpu_state(&mut psx, cpu_state);

let audio_buffer = psx.take_audio_buffer();
if args.audio {
if let Some(audio_player) = &mut audio_player {
audio_player.queue(&audio_buffer);
}
}
Expand Down

0 comments on commit 4583a9e

Please sign in to comment.