mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Use SoundDirection rather than a boolean
This commit is contained in:
parent
dda79df12d
commit
82fd9ce120
|
@ -11,7 +11,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
|
|
||||||
gba.sound.enable();
|
gba.sound.enable();
|
||||||
|
|
||||||
let sweep_settings = gba::sound::SweepSettings::new(3, false, 7);
|
let sweep_settings = sound::SweepSettings::new(3, sound::SoundDirection::Decrease, 7);
|
||||||
gba.sound.channel1().play_sound(&sweep_settings);
|
gba.sound.channel1().play_sound(&sweep_settings);
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
|
|
|
@ -31,38 +31,18 @@ impl Sound {
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct Channel1 {}
|
pub struct Channel1 {}
|
||||||
|
|
||||||
pub struct SweepSettings {
|
pub enum SoundDirection {
|
||||||
number_of_sweep_shifts: u8,
|
Increase,
|
||||||
increase_sweep: bool,
|
Decrease,
|
||||||
sweep_time: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SweepSettings {
|
|
||||||
pub fn new(number_of_sweep_shifts: u8, increase_sweep: bool, sweep_time: u8) -> Self {
|
|
||||||
assert!(
|
|
||||||
number_of_sweep_shifts < 8,
|
|
||||||
"Number of sweep shifts must be less than 8"
|
|
||||||
);
|
|
||||||
assert!(sweep_time < 8, "Sweep time must be less than 8");
|
|
||||||
|
|
||||||
SweepSettings {
|
|
||||||
number_of_sweep_shifts,
|
|
||||||
increase_sweep,
|
|
||||||
sweep_time,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SoundDirection {
|
||||||
fn as_bits(&self) -> u16 {
|
fn as_bits(&self) -> u16 {
|
||||||
((self.number_of_sweep_shifts as u16) & 0b111)
|
match &self {
|
||||||
| ((self.increase_sweep as u16) << 3)
|
SoundDirection::Increase => 1,
|
||||||
| ((self.sweep_time as u16) & 0b111) << 4
|
SoundDirection::Decrease => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SweepSettings {
|
|
||||||
fn default() -> Self {
|
|
||||||
SweepSettings::new(0, true, 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Channel1 {
|
impl Channel1 {
|
||||||
|
@ -72,3 +52,41 @@ impl Channel1 {
|
||||||
CHANNEL_1_FREQUENCY_CONTROL.set(0b1_0_000_01000000000);
|
CHANNEL_1_FREQUENCY_CONTROL.set(0b1_0_000_01000000000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct SweepSettings {
|
||||||
|
number_of_sweep_shifts: u8,
|
||||||
|
sound_direction: SoundDirection,
|
||||||
|
sweep_time: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SweepSettings {
|
||||||
|
pub fn new(
|
||||||
|
number_of_sweep_shifts: u8,
|
||||||
|
sound_direction: SoundDirection,
|
||||||
|
sweep_time: u8,
|
||||||
|
) -> Self {
|
||||||
|
assert!(
|
||||||
|
number_of_sweep_shifts < 8,
|
||||||
|
"Number of sweep shifts must be less than 8"
|
||||||
|
);
|
||||||
|
assert!(sweep_time < 8, "Sweep time must be less than 8");
|
||||||
|
|
||||||
|
SweepSettings {
|
||||||
|
number_of_sweep_shifts,
|
||||||
|
sound_direction,
|
||||||
|
sweep_time,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_bits(&self) -> u16 {
|
||||||
|
((self.number_of_sweep_shifts as u16) & 0b111)
|
||||||
|
| (self.sound_direction.as_bits() << 3)
|
||||||
|
| ((self.sweep_time as u16) & 0b111) << 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for SweepSettings {
|
||||||
|
fn default() -> Self {
|
||||||
|
SweepSettings::new(0, SoundDirection::Increase, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue