dasp
dasp copied to clipboard
add pulse wave signal source functions to the signal module
I added three pulse wave source functions to the dasp::signal module, that I felt would be useful. I chose to add a selection 12.5%, 25%, and 75% duty cycle pulse waves.
My reasoning for this was due to those 3, (plus 50%, as standard Square Wave) being the most common in chiptune, and old gaming APU's.
Initially I tried extending the signal module in my own project, but came across some difficulty trying to implement it as a trait.
turns out VS Code can be really finicky when mass changing the name of things :/
What about making the duty cycle a parameter? Seems unnecessarily restrictive to have multiple implementations with fixed values.
Thanks for the PR @ifamakes!
I'm also thinking a single type with a duty_cycle
field might allow for a little more flexibility than having different types for each fraction, e.g. something along the lines of:
#[derive(Clone)]
pub struct Pulse<S> {
phase: Phase<S>,
duty_cycle: S,
}
and then have the implementation could look something like:
if phase < self.duty_cycle {
1.0
} else {
-1.0
}
What are your thoughts?