Need some help with additive Impulse and Bipulse wave shape functions

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
Hey everyone see here: https://meettechniek.info/additional/ad ... hesis.html (https://meettechniek.info/additional/additive-synthesis.html)

There is a Impulse wave shape made from adding sine-waves together, now I have made the basic Square, Triangle, and Saw functions, those are easy:

Code: Select all (#)

float getSquare(float phase, float resolution)
{
    resolution *= 2.f;
    float yr = sinf(phase);
    for(float h = 3.f; h < resolution; h += 2.f)
        yr += sinf(phase*h)/h;
    return yr;
}

float getSawtooth(float phase, float resolution)
{
    float yr = sinf(phase);
    for(float h = 2.f; h <= resolution; h += 1.f)
        yr += sinf(phase*h)/h;
    return yr;
}

float getTriangle(float phase, float resolution)
{
    resolution *= 2.f;
    float yr = sinf(phase);
    float sign = -1.f;
    for(float h = 3.f; h <= resolution; h += 2.f)
    {
        yr += (sinf(phase*h) / (h*h)) * sign;
        sign *= -1.f;
    }
    return yr;
}
But I am not so good with making the Impulse and Bipulse functions, basically I just need the function to take in phase and resolution (resolution = how many additive iterations) and output an amplitude for that phase of the waveshape.

This is for a FOSS tone generator I am working on, details I can provide in DM, if anyone is good with this kind of thing I would appreciate your help in this matter greatly, and would love to credit you in my FOSS project as such.

Technically each shape only needs to produce up to 30 additions, so the solution provided could just be a table/array of the 30 different harmonics that need to be added together, it doesn't have to be 100% generated by math like I am doing above. Execution speed is priority.

Here is an Impulse reconstructed from the website above to 10 harmonics: (realistically all it needs)

Code: Select all (#)

float getImpulse(float phase, float resolution)
{
    float yr = 0.f;
    if(resolution >= 0){yr += sinf(phase * Hz(100.f));}
    if(resolution >= 1){yr -= cosf(phase * Hz(200.f)) * 0.9f;}
    if(resolution >= 2){yr -= sinf(phase * Hz(300.f)) * 0.8f;}
    if(resolution >= 3){yr += cosf(phase * Hz(400.f)) * 0.7f;}
    if(resolution >= 4){yr += sinf(phase * Hz(500.f)) * 0.6f;}
    if(resolution >= 5){yr -= cosf(phase * Hz(600.f)) * 0.5f;}
    if(resolution >= 6){yr -= sinf(phase * Hz(700.f)) * 0.4f;}
    if(resolution >= 7){yr += cosf(phase * Hz(800.f)) * 0.3f;}
    if(resolution >= 8){yr += sinf(phase * Hz(900.f)) * 0.2f;}
    if(resolution >= 9){yr -= cosf(phase * Hz(1000.f))* 0.1f;}
    return yr;
}

Post

Hi, it's simpler than you may expect. You can construct a PWM wave by summing a sawtooth wave with another phase-shifted, inverted sawtooth:

https://www.desmos.com/calculator/allqll7jwe

Image

Post

Wow thank you so much, that is amazing!

Post

NP. Thinking of synths:
It is pretty crazy that both parallel, detuned sawtooth waves and a modulated PWM wave are essentially the same thing: comb-filtering. (Sorry if inverted comb-filtering has a different name). They do sound very similar, after all.

Post Reply

Return to “DSP and Plugin Development”