Skip to content

Commit

Permalink
refactor: restructure folder
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Oct 7, 2024
1 parent ad26e7e commit f8d5dce
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 43 deletions.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions src/apu/channels/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
mod envelope;
mod length_counter;
mod sequencer;
mod sweep;
mod timer;

pub use envelope::Envelope;
pub use length_counter::LengthCounter;
pub use sequencer::Sequencer;
pub use sweep::Sweep;
pub use timer::Timer;

pub trait Channel {
fn write_register(&mut self, address: u16, value: u8);
fn raw_sample(&self) -> u8;
fn is_active(&self) -> bool;
fn is_mute(&self) -> bool;
fn set_enabled(&mut self, value: bool);

fn get_sample(&self) -> f32 {
match self.is_mute() {
true => 0.0,
false => self.raw_sample() as f32,
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 2 additions & 15 deletions src/apu/channels/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
mod common;
mod noise;
mod pulse;
mod triangle;

pub use common::Channel;
pub use noise::Noise;
pub use pulse::Pulse;
pub use triangle::Triangle;

pub trait Channel {
fn write_register(&mut self, address: u16, value: u8);
fn raw_sample(&self) -> u8;
fn is_active(&self) -> bool;
fn is_mute(&self) -> bool;
fn set_enabled(&mut self, value: bool);

fn get_sample(&self) -> f32 {
match self.is_mute() {
true => 0.0,
false => self.raw_sample() as f32,
}
}
}
9 changes: 2 additions & 7 deletions src/apu/channels/noise.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
// https://www.nesdev.org/wiki/APU_Noise

use crate::{
apu::{
envelope::Envelope,
frame_counter::{ClockFrame, Frame},
length_counter::LengthCounter,
timer::Timer,
},
apu::frame_counter::{ClockFrame, Frame},
utils::{BitFlag, Clock},
};

use super::Channel;
use super::common::{Channel, Envelope, LengthCounter, Timer};

const PERIODS: [u16; 16] = [
4, 8, 16, 32, 64, 96, 128, 160, 202, 254, 380, 508, 762, 1016, 2034, 4068,
Expand Down
11 changes: 2 additions & 9 deletions src/apu/channels/pulse.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
// https://www.nesdev.org/wiki/APU_Pulse

use crate::{
apu::{
envelope::Envelope,
frame_counter::{ClockFrame, Frame},
length_counter::LengthCounter,
sequencer::Sequencer,
sweep::Sweep,
timer::Timer,
},
apu::frame_counter::{ClockFrame, Frame},
utils::{BitFlag, Clock},
};

use super::Channel;
use super::common::{Channel, Envelope, LengthCounter, Sequencer, Sweep, Timer};

const WAVEFORMS: [[u8; 8]; 4] = [
[0, 1, 0, 0, 0, 0, 0, 0],
Expand Down
9 changes: 2 additions & 7 deletions src/apu/channels/triangle.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
// https://www.nesdev.org/wiki/APU_Triangle

use crate::{
apu::{
frame_counter::{ClockFrame, Frame},
length_counter::LengthCounter,
sequencer::Sequencer,
timer::Timer,
},
apu::frame_counter::{ClockFrame, Frame},
utils::{BitFlag, Clock},
};

use super::Channel;
use super::common::{Channel, LengthCounter, Sequencer, Timer};

#[rustfmt::skip]
const WAVEFORMS: [u8; 32] = [
Expand Down
5 changes: 0 additions & 5 deletions src/apu/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// https://www.nesdev.org/wiki/APU

mod channels;
mod envelope;
mod frame_counter;
mod length_counter;
mod sequencer;
mod sweep;
mod timer;

use channels::{Channel, Noise, Pulse, Triangle};
use frame_counter::{ClockFrame, FrameCounter};
Expand Down

0 comments on commit f8d5dce

Please sign in to comment.