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