dasp icon indicating copy to clipboard operation
dasp copied to clipboard

add pulse wave signal source functions to the signal module

Open ifacodes opened this issue 4 years ago • 3 comments

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.

ifacodes avatar Feb 05 '21 06:02 ifacodes

turns out VS Code can be really finicky when mass changing the name of things :/

ifacodes avatar Feb 05 '21 17:02 ifacodes

What about making the duty cycle a parameter? Seems unnecessarily restrictive to have multiple implementations with fixed values.

jdanford avatar Mar 25 '21 19:03 jdanford

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?

mitchmindtree avatar Aug 04 '21 17:08 mitchmindtree