Clippy fixes

Former-commit-id: 6107b2249a5b5e42eb5add5f6a0c37c373d77147
Former-commit-id: 1387473cc566db7eb898222b319cc1bcfde886f5
This commit is contained in:
Michel Heily 2022-09-08 23:02:00 +03:00
parent a289900f6a
commit 4c5d35c5d1
6 changed files with 37 additions and 28 deletions

View file

@ -35,9 +35,9 @@ impl EepromType {
}
}
impl Into<usize> for EepromAddressBits {
fn into(self) -> usize {
match self {
impl From<EepromAddressBits> for usize {
fn from(bits: EepromAddressBits) -> usize {
match bits {
EepromAddressBits::Eeprom6bit => 6,
EepromAddressBits::Eeprom14bit => 14,
}

View file

@ -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);

View file

@ -64,7 +64,7 @@ pub trait VideoInterface {
fn render(&mut self, buffer: &[u32]) {}
}
pub type StereoSample<T> = (T, T);
pub type StereoSample<T> = [T; 2];
pub trait AudioInterface {
fn get_sample_rate(&self) -> i32 {

View file

@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
const PI: f32 = std::f32::consts::PI;
pub trait Resampler {
fn feed(&mut self, s: StereoSample<f32>, output: &mut Vec<StereoSample<f32>>);
fn feed(&mut self, s: &StereoSample<f32>, output: &mut Vec<StereoSample<f32>>);
}
#[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<f32>, output: &mut Vec<StereoSample<f32>>) {
fn feed(&mut self, s: &StereoSample<f32>, output: &mut Vec<StereoSample<f32>>) {
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;
}
}

View file

@ -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),

View file

@ -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]]);
}
}