Monophonic adsr retrigger and getting rid of discontinuity in waveform

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

How can I get an adsr to retrigger like this when it comes to the attack stage Image

instead of this or just continue the attack from the previous level

Image

Post

Cross-fade the old triggered note with the new one.
Or first do a 0.001 sec fade off before starting a new note.
We are the KVR collective. Resistance is futile. You will be assimilated. Image
My MusicCalc is served over https!!

Post

Thank you ill try to do the .001 sec fade off.

Post

Again Thanks for insight I got it looking like this. much better than before I will work on it though.
Image

Post

Use two voices and flip-flop (crossfade) between them. But watch out for fast note repetitions (3 fast notes for example), as you will have to restart one voice regardless of discontinuity.

Post

Thanks but I was able to do it by saving the last value of the oscillator before the new note and adding or subtracting it from the main output until it was zero. So it was sort of cross fading i guess? I got it looking like this in case your curious Image

Post

That does get rid of the discontinuity, but it can also make low frequency noise. What if the signal in question was at 1000hz and on a crest during the retrigger? If you fade from that crest at a rate much much lower than what's in the signal, you will have generated a signal at that low frequency.

Post

Yeah I think I know what you mean I hear a slight bump when rapidly pressing notes. I will do as you suggested.

Post

I made the the two voices but I'm not sure how to flip flop/cross fade without the voices become added together do you have any hints as to how to actually crossfade the voices?

Post

I figured it out had something wrong elsewhere but still have to work on it when rapidly pressing notes I get discontinuity.

Image

Post

Marvinh wrote:I made the the two voices but I'm not sure how to flip flop/cross fade without the voices become added together do you have any hints as to how to actually crossfade the voices?
I would have to see the code in question. It should be an easy problem to solve, since you basically have two voices, each with an amp envelope controlled by one midi event. Build some decision-making logic around the voices which is based on the midi signal, don't try to build the logic into the voice structure.

Post

I literally just had to flip flop the voices while crossfading it works pretty well thank you!

Code: Select all

while (--frames >= 0)
            {
                update();

                if(v==0){
                    o = env->process(vs[v].estate)*osc->process(vs[v].ostate)
                        +env->process(vs[1].estate)*osc->process(vs[1].ostate)*cf;
                }else{
                    o = env->process(vs[v].estate)*osc->process(vs[v].ostate)
                        +env->process(vs[0].estate)*osc->process(vs[0].ostate)*cf;
                }
                
                if(cf>=.000125){
                    cf-=.000125;
                }else{
                    cf = 0.0;
                }
                
                *out1++ = o;
                *out2++ = o;
            }
    
            if (frame<sampleFrames) //next note on/off
            {
                VstInt32 note = notes[event++];
                VstInt32 vel = notes[event++];
                if(vel>0){
                    cf = 1.0;
                    o = 0.0;
                }
                noteOn(note, vel);
            }

/////for the voices in noteOn(note,vel)
v ^= 1;


Post

This part..

Code: Select all

if (frame<sampleFrames) //next note on/off
            {
                VstInt32 note = notes[event++];
                VstInt32 vel = notes[event++];
It's a bad habit to re-declare vars that are used often, especially in tight loops. It's better to declare them once on function entry.

So if note repetition presents a problem, you have two options, use more voices, or use a shorter crossfade time.

Post

Thanks for tips I really appreciate your help.

Post

Is this for a sample player? I was just thinking that, for synths, mono retrigger logic could be designed into the oscillator itself. By doing that, it would be possible to control the signal parameters to provide a more natural transition.

Post Reply

Return to “DSP and Plugin Development”