diff --git a/core/src/cartridge/backup/eeprom.rs b/core/src/cartridge/backup/eeprom.rs index 71f8cd1..826282f 100644 --- a/core/src/cartridge/backup/eeprom.rs +++ b/core/src/cartridge/backup/eeprom.rs @@ -35,9 +35,9 @@ impl EepromType { } } -impl Into for EepromAddressBits { - fn into(self) -> usize { - match self { +impl From for usize { + fn from(bits: EepromAddressBits) -> usize { + match bits { EepromAddressBits::Eeprom6bit => 6, EepromAddressBits::Eeprom14bit => 14, } diff --git a/core/src/gpu/sfx.rs b/core/src/gpu/sfx.rs index 692961a..238d2ea 100644 --- a/core/src/gpu/sfx.rs +++ b/core/src/gpu/sfx.rs @@ -65,9 +65,14 @@ impl Gpu { if self.dispcnt.enable_window0 && self.win0.contains_y(y) { let win = WindowInfo::new(WindowType::Win0, self.win0.flags); let backgrounds = filter_window_backgrounds(&sorted_backgrounds, win.flags); - for x in self.win0.left()..self.win0.right() { + for (x, is_occupid) in occupied + .iter_mut() + .enumerate() + .take(self.win0.right()) + .skip(self.win0.left()) + { self.finalize_pixel(x, y, &win, &backgrounds, backdrop_color); - occupied[x] = true; + *is_occupid = true; occupied_count += 1; } } @@ -77,12 +82,17 @@ impl Gpu { if self.dispcnt.enable_window1 && self.win1.contains_y(y) { let win = WindowInfo::new(WindowType::Win1, self.win1.flags); let backgrounds = filter_window_backgrounds(&sorted_backgrounds, win.flags); - for x in self.win1.left()..self.win1.right() { - if occupied[x] { + for (x, is_occupid) in occupied + .iter_mut() + .enumerate() + .take(self.win0.right()) + .skip(self.win0.left()) + { + if *is_occupid { continue; } self.finalize_pixel(x, y, &win, &backgrounds, backdrop_color); - occupied[x] = true; + *is_occupid = true; occupied_count += 1; } } @@ -95,8 +105,8 @@ impl Gpu { let win_obj = WindowInfo::new(WindowType::WinObj, self.winobj_flags); let win_obj_backgrounds = filter_window_backgrounds(&sorted_backgrounds, win_obj.flags); - for x in 0..DISPLAY_WIDTH { - if occupied[x] { + for (x, is_occupid) in occupied.iter().enumerate().take(DISPLAY_WIDTH) { + if *is_occupid { continue; } let obj_entry = self.obj_buffer_get(x, y); diff --git a/core/src/lib.rs b/core/src/lib.rs index 65c25bf..512af24 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -64,7 +64,7 @@ pub trait VideoInterface { fn render(&mut self, buffer: &[u32]) {} } -pub type StereoSample = (T, T); +pub type StereoSample = [T; 2]; pub trait AudioInterface { fn get_sample_rate(&self) -> i32 { diff --git a/core/src/sound/dsp.rs b/core/src/sound/dsp.rs index b0d7893..bc4bd8f 100644 --- a/core/src/sound/dsp.rs +++ b/core/src/sound/dsp.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; const PI: f32 = std::f32::consts::PI; pub trait Resampler { - fn feed(&mut self, s: StereoSample, output: &mut Vec>); + fn feed(&mut self, s: &StereoSample, output: &mut Vec>); } #[derive(Serialize, Deserialize, Clone, Debug)] @@ -22,15 +22,15 @@ fn cosine_interpolation(y1: f32, y2: f32, phase: f32) -> f32 { } impl Resampler for CosineResampler { - fn feed(&mut self, s: StereoSample, output: &mut Vec>) { + fn feed(&mut self, s: &StereoSample, output: &mut Vec>) { while self.phase < 1.0 { - let left = cosine_interpolation(self.last_in_sample.0, s.0, self.phase); - let right = cosine_interpolation(self.last_in_sample.1, s.1, self.phase); - output.push((left, right)); + let left = cosine_interpolation(self.last_in_sample[0], s[0], self.phase); + let right = cosine_interpolation(self.last_in_sample[1], s[1], self.phase); + output.push([left, right]); self.phase += self.in_freq / self.out_freq; } self.phase -= 1.0; - self.last_in_sample = s; + self.last_in_sample = *s; } } diff --git a/core/src/sound/mod.rs b/core/src/sound/mod.rs index 86525e4..f0ee16a 100644 --- a/core/src/sound/mod.rs +++ b/core/src/sound/mod.rs @@ -307,14 +307,14 @@ impl SoundController { return; } - const FIFO_INDEX_TO_REG: [u32; 2] = [REG_FIFO_A, REG_FIFO_B]; - for fifo in 0..2 { + static FIFO_INDEX_TO_REG: [u32; 2] = [REG_FIFO_A, REG_FIFO_B]; + for (fifo, reg) in FIFO_INDEX_TO_REG.iter().enumerate() { let dma = &mut self.dma_sound[fifo]; if timer_id == dma.timer_select { dma.value = dma.fifo.read(); if dma.fifo.count() <= 16 { - dmac.notify_sound_fifo(FIFO_INDEX_TO_REG[fifo]); + dmac.notify_sound_fifo(*reg); } } } @@ -322,9 +322,9 @@ impl SoundController { #[inline] fn on_sample(&mut self, audio_device: &AudioDeviceRcRefCell) -> FutureEvent { - let mut sample = [0f32; 2]; + let mut sample = [0f32, 0f32]; - for channel in 0..=1 { + for (channel, out_sample) in sample.iter_mut().enumerate() { let mut dma_sample = 0; for dma in &mut self.dma_sound { if dma.is_stereo_channel_enabled(channel) { @@ -334,14 +334,13 @@ impl SoundController { } apply_bias(&mut dma_sample, self.sound_bias.bit_range(0..10) as i16); - sample[channel] = dma_sample as i32 as f32; + *out_sample = dma_sample as i32 as f32; } - let stereo_sample = (sample[0], sample[1]); - self.resampler.feed(stereo_sample, &mut self.output_buffer); + self.resampler.feed(&sample, &mut self.output_buffer); let mut audio = audio_device.borrow_mut(); - self.output_buffer.drain(..).for_each(|(left, right)| { + self.output_buffer.drain(..).for_each(|[left, right]| { audio.push_sample(&[ (left.round() as i16) * (std::i16::MAX / 512), (right.round() as i16) * (std::i16::MAX / 512), diff --git a/platform/rustboyadvance-sdl2/src/audio.rs b/platform/rustboyadvance-sdl2/src/audio.rs index 5a746ee..8a48db6 100644 --- a/platform/rustboyadvance-sdl2/src/audio.rs +++ b/platform/rustboyadvance-sdl2/src/audio.rs @@ -28,7 +28,7 @@ impl AudioCallback for GbaAudioCallback { let sample_count = out_samples.len() / 2; for i in 0..sample_count { - if let Some((left, right)) = self.consumer.pop() { + if let Some([left, right]) = self.consumer.pop() { out_samples[2 * i] = left; out_samples[2 * i + 1] = right; } else { @@ -46,7 +46,7 @@ impl AudioInterface for Sdl2AudioPlayer { fn push_sample(&mut self, sample: &[i16]) { #![allow(unused_must_use)] - self.producer.push((sample[0], sample[1])); + self.producer.push([sample[0], sample[1]]); } }