From 6c1ad38f0affa5c69b4984033e9a40e092e5a298 Mon Sep 17 00:00:00 2001 From: Kevin Hamacher Date: Thu, 30 Sep 2021 12:33:14 +0200 Subject: [PATCH] Fix sound once again :) --- shell.nix | 17 +---------------- src/interconnect.rs | 5 ++++- src/sound/mod.rs | 13 ++++++------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/shell.nix b/shell.nix index a238076..0ac516e 100644 --- a/shell.nix +++ b/shell.nix @@ -1,20 +1,6 @@ let moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz); nixpkgs = import { overlays = [ moz_overlay ]; }; - rustNightlyChannelClippy = (nixpkgs.rustChannelOf { date = "2020-01-29"; channel = "nightly"; }).rust.override { - extensions = [ - "rust-src" - "rls-preview" - "rustfmt-preview" - ]; - }; - rustNightlyChannel = nixpkgs.latest.rustChannels.nightly.rust.override { - extensions = [ - "rust-src" - "rls-preview" - "rustfmt-preview" - ]; - }; rustStableChannel = nixpkgs.latest.rustChannels.stable.rust.override { extensions = [ "rust-src" @@ -28,12 +14,11 @@ in stdenv.mkDerivation { name = "moz_overlay_shell"; buildInputs = [ - rustNightlyChannelClippy + rustStableChannel rls rustup pkg-config SDL2 pulseaudio ]; - TELOXIDE_TOKEN = "916718418:AAFFtn9WmqipuKCvwiXZ2cEIA_IuNqlO94I"; } diff --git a/src/interconnect.rs b/src/interconnect.rs index d2dae67..00a1cf0 100644 --- a/src/interconnect.rs +++ b/src/interconnect.rs @@ -369,7 +369,10 @@ impl Interconnect { 0xFF70 => { if self.wram_bank != val { if val > 7 { - panic!("Trying to switch to wram bank {} which is non-existing", val); + panic!( + "Trying to switch to wram bank {} which is non-existing", + val + ); } if val == 0 { self.wram_bank = 1; diff --git a/src/sound/mod.rs b/src/sound/mod.rs index 9e1bdec..63cf79a 100644 --- a/src/sound/mod.rs +++ b/src/sound/mod.rs @@ -379,7 +379,10 @@ impl SoundManager { let mut counter = 0; while !do_exit.load(Ordering::Relaxed) { - for _ in 0..100 { + const N_SAMPLES: usize = 1024; + let mut sample_buffer = [[128u8; 2]; N_SAMPLES]; + + for idx in 0..N_SAMPLES { if let Some((s1, s2)) = { let mut c_obj = obj.lock().unwrap(); @@ -397,14 +400,10 @@ impl SoundManager { // Get sample c_obj.sample() } { - let samps = [[s1, s2]]; - playback.write(&samps[..]); - } else { - let samps = [[128, 128]]; - playback.write(&samps[..]); + sample_buffer[idx] = [s1, s2]; } } - std::thread::sleep(std::time::Duration::from_millis(1)); + playback.write(&sample_buffer[..]); } }) .unwrap(),