cargo fmt
This commit is contained in:
parent
57b8438144
commit
93e38d49ef
@ -4,7 +4,7 @@ use sound::{AudioComponent, AudioModule};
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum EnvelopeDirection {
|
||||
Increase,
|
||||
Decrease
|
||||
Decrease,
|
||||
}
|
||||
|
||||
impl Default for EnvelopeDirection {
|
||||
@ -15,7 +15,7 @@ impl Default for EnvelopeDirection {
|
||||
|
||||
/// Represents a volume envelope for the sound channels
|
||||
#[derive(Default, Debug)]
|
||||
pub struct VolumeEnvelope{
|
||||
pub struct VolumeEnvelope {
|
||||
/// Accessible via the corresponding memory location, used as template
|
||||
/// when the sound is enabled
|
||||
register_value: u8,
|
||||
|
||||
@ -1,15 +1,21 @@
|
||||
// Implement the length counter
|
||||
use std::fmt::Debug;
|
||||
use sound::{AudioComponent, AudioModule};
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct LengthCounter<T> where T: Default + Debug {
|
||||
pub struct LengthCounter<T>
|
||||
where
|
||||
T: Default + Debug,
|
||||
{
|
||||
// Do we need an additional enabled flag?
|
||||
counter: T,
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
impl<T> LengthCounter<T> where T: Default + Debug {
|
||||
impl<T> LengthCounter<T>
|
||||
where
|
||||
T: Default + Debug,
|
||||
{
|
||||
pub fn set_length(&mut self, value: T) {
|
||||
self.counter = value;
|
||||
}
|
||||
@ -19,8 +25,7 @@ impl<T> LengthCounter<T> where T: Default + Debug {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl AudioModule<u8> for LengthCounter<u16> {
|
||||
impl AudioModule<u8> for LengthCounter<u16> {
|
||||
fn transform(&self, sample: u8) -> u8 {
|
||||
if self.enabled {
|
||||
if self.counter > 0 {
|
||||
@ -44,7 +49,7 @@ impl AudioComponent for LengthCounter<u16> {
|
||||
|
||||
// TODO: Is the same as above, there is something we should be able to do about
|
||||
// this
|
||||
impl AudioModule<u8> for LengthCounter<u8> {
|
||||
impl AudioModule<u8> for LengthCounter<u8> {
|
||||
fn transform(&self, sample: u8) -> u8 {
|
||||
if self.enabled {
|
||||
if self.counter > 0 {
|
||||
|
||||
@ -33,7 +33,6 @@ pub struct SquareWaveGenerator {
|
||||
|
||||
// Current sweep clock cycle
|
||||
sweep_clock: u8,
|
||||
|
||||
// sweep_freq_shadow: f32,
|
||||
}
|
||||
|
||||
@ -73,17 +72,13 @@ impl SquareWaveGenerator {
|
||||
if self.sweep_clock >= self.sweep_change_period {
|
||||
self.sweep_clock = 0;
|
||||
let change = self.frequency / (2f32.powi(self.sweep_change as _));
|
||||
self.frequency += if self.sweep_dec {
|
||||
change
|
||||
} else {
|
||||
-change
|
||||
};
|
||||
self.frequency += if self.sweep_dec { change } else { -change };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
pub fn reset(&mut self) {
|
||||
self.time = 0f32;
|
||||
}
|
||||
|
||||
@ -99,21 +94,21 @@ impl SquareWaveGenerator {
|
||||
} else {
|
||||
0
|
||||
}
|
||||
},
|
||||
}
|
||||
DutyCycle::Duty1 => {
|
||||
if temp < 0.25 {
|
||||
255
|
||||
} else {
|
||||
0
|
||||
}
|
||||
},
|
||||
}
|
||||
DutyCycle::Duty2 => {
|
||||
if temp < 0.5 {
|
||||
255
|
||||
} else {
|
||||
0
|
||||
}
|
||||
},
|
||||
}
|
||||
DutyCycle::Duty3 => {
|
||||
if temp < 0.75 {
|
||||
255
|
||||
|
||||
@ -50,7 +50,7 @@ impl WaveGenerator {
|
||||
self.update_frequency();
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
pub fn reset(&mut self) {
|
||||
self.time = 0f32;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user