This is sweet, found a way to reduce cpu when the envelope generator stops.

Studiowaves
Studiowaves Member Posts: 197 Tri
edited March 7 in Building With Reaktor

I took a look into and envelope generator "ahdsr" hoping to find a way to detect the end of the envelope and discovered the init. As soon as the release stage is finished the init changes states. Here's a way to tap it and shut off external oscillators etc. when the envelope is over.

This is inside the env generator.

Notice the process module on the far bottom right. This is its internals modules.

Notice the output I added that says "idle", attached to the phase process. This is the inside of the phase Process.

The idle goes even deeper into the Stage Switch as shown here.

Notice the idle output is connected to a merge and a pair of latches. I added this to detect the finish of the envelope. The merge produces a 1 when the envelope is running and the exact moment it stops the final release phase the merge switches to a 0. The idle ends up here, but I also have 6 independent env generators. The oscillator modules attach to the bundle outputs.

Notice the pickup distributions labeled stp1 thru stp6. These are the "idle taps for the six envelope generators. Let's focus on OP1, it's a master on/off switch and has a value of 1 when the oscillator is on. So now the stp1 also needs to be a 1 to turn oscillator module 1 on. I could have used a logic "AND" in place of the multiplier but it may use more cpu; not sure. Anyway the external oscillator module turns on the instant the envelope generator starts and shuts off immediately when it's finished. The CPU with 20 voices dropped significantly with the technique. It's an overall improvement as some envelopes are very short and it beats running the oscillators at full power, 100 percent of the time. I hope it comes in handy!

This is the final connections. The SR router pack is shown above and notice the distribution bundle SR1 out of the pack and the lower left pickup of the module labeled SR1.

The final destination is shown here. Notice the SR distribution outlet on the bottom left. When it shuts down all internal modules attached to the SR.C buss stop. The Rst on the bottom left starts the oscillators at 0 phase angle for perfect sync when the module starts, but I'm not going into that.

Hope you enjoyed this little discovery, so far it seems to work perfect. 😀

Comments

  • ANDREW221231
    ANDREW221231 Member Posts: 131 Tri

    that's probably no small savings with your FM being such and envelope generator hog!!! stuff like that really adds up in core especially if its polyphonic


    any way look at you... goin in knee deep in the envelope framework like a heavy hitter, looking out for what could be improved.... it looks like a handy system (the EG framework) but when i first scoped it out took one look at how much abstraction would need digesting first and turned right around as quick as i came in and never went back


    i guess i'll be learning a thing or two about core optimization soon because it looks like my pitch detector is finally graduated from the building phase

  • Studiowaves
    Studiowaves Member Posts: 197 Tri

    Wasn't hard to figure out because they labeled it "init". So I hooked a panel led to the line and watched the envelope generator on the scope. At the final decay value the light came on. Then it reinitialized the envelope generator and waited for the next gate. At that point the envelope is off so why keep the operator running, it's just a cpu waste and runs up my electric bill. lol

    It did have a timing problem from getting the envelope gens output to it's final destination. So the operators output wasn't yet dead off when the init flag shut off the operator. So I put a band aid on it the basically delayed the shut down a few samples.

    Ya, those env gens are heavy hitters on cpu, I underclocked them with a clock generator and the speed of the clock is adjustable and saved with a patch. Pretty fun getting the cpu down where the sample rate can be clocked at 48k with 20 voices. It does have that gritty sound and the slew of the env gens is plenty fast on attacks running at 2k. I'm gonna try to gate the clock generator next to shut them down. I think the init line I found actually initializes the generator so if I stop the clock when the incoming gate from midi is zero, as is with the key off it might work.

    I'm just happy spring is around the corner. So you've come a long way with you pitch detector. I thought it was pretty cool a while back. I played some music thru it and it worked good enough to tell me what key the music was in. I though that was pretty cool. This fm thing is nothing complicated like that. It's a simple concept, I wouldn't know where to start on something like that. That's pretty cool man, I'm impressed, but being impressed by a dumbshit don't mean much. lol

    Talk later

  • Studiowaves
    Studiowaves Member Posts: 197 Tri

    Had a little bit of a timing issue and that was easily fixed as shown below with a pair of latches on the output of the envelope generator. Notice the clock generator , you can save a lot of cpu by under clocking the generators. Go as low as you can , even at 2k it's hard to tell the difference.

    A simple 1 pole lp filter in the macro outside the env gen smooths the env pretty well. The filter frequency is half the clock gens frequency. The dup filter blocks unnecessary events sent to a single multiplier controlling the volume. The filters clock runs at the audio sample rate but is it worth it?

    Compare the inside of the dup filter to a single multiplier. It looks like it uses more cpu than it's worth. However with 20 voices going it will reduce cpu when the voices is not used but more when it is. So what's a code writer to do. I say ditch it as it uses more cpu when all voices are going. Gotta love core programming.


  • bolabo
    bolabo Member Posts: 63 Tri
    edited March 8

    There's a version of the dup filter that uses less CPU called [Dup Flt'], with the extra ' at the end. But in general, as the dup filter is reading and writing to memory a few times every audio clock it's going to use more CPU cycles than just a single multiply. So probably not saving you anything by using it in your situation.

    A simple 1 pole lp filter in the macro outside the env gen smooths the env pretty well. The filter frequency is half the clock gens frequency. 

    You could also try this smoother for that, to get rid of any jaggies / aliasing -->

    "CR Lin XSmoother"

  • colB
    colB Member Posts: 246 Saw

    Notice the clock generator , you can save a lot of cpu by under clocking the generators. Go as low as you can , even at 2k it's hard to tell the difference.

    That depends. If you are using medium to slow sections on your envelope, then downclocking is fine, but if you are using it to model sounds with fast attack transients, then 2k is likely slow enough to be quite noticeable for e.g. percussive sounds when compared with the same time settings running at audio rate.

  • Studiowaves
    Studiowaves Member Posts: 197 Tri

    I agree, that's exactly what happens. It helps because it works fine on the patches I normally use. Mainly because it's used to back fill a sampler. Most patches blend in pretty good at 2k clock rate, I got bad news working on it tonight, it turns out the init can't be used after all. The attack time doesn't work. Oh well, maybe I can find another way. There's a loop module that in the env gen that does settle down and loop at a near 0 value. It pops out of that as soon as a key is pressed, I might be able to work with that, not sure because the oscillators following the env need to be timed and in sync with the gate on. Otherwise you get a click sound. The init can be used to turn it off though, It pops on when the decay is done. Might be able to use the gate on to start the oscillators and the init to stop it. Sounds pretty straight forward, but not that easy, when the gate turns off and the release starts then you have problems with a simple logic system. I should be able to do it somehow. hopefully.

  • Studiowaves
    Studiowaves Member Posts: 197 Tri

    I tried the smoother, it's a hell of a cpu hog, the simple lpf is fine. Also the logic line "init" stopped working. I was watching it work without resetting the master ensemble clock and forgot those env gens get all screwed up in edit mode. The init is useful to sens the end of the release but it doesn't kick in until after the attack is over. It didn't do that in edit mode and I was fit to be tied when it stopped working. I found a workaround that uses the input gate itself to start the oscillators and the init to stop them.

  • Studiowaves
    Studiowaves Member Posts: 197 Tri

    I tried to use a single clock generator and ran the clock into a macro. It's erratic but then after restarting it was better, them after a complete reboot it was even better. Seems something is out of sync there, perhaps the clock generator frequency is being reported after the clock starts. Who knows, but independent ones work fine. Pretty crazy, I guess you get to a point in core where all hell breaks loose. lol

  • Studiowaves
    Studiowaves Member Posts: 197 Tri

    I tried to use a single clock generator and ran the clock into 6 env gen macros. It did not work, but managed to sync up one time, so I know it was wired correctly. I assume something in primary macro's can't sync up to external clocks unless it's the SR.C

  • Studiowaves
    Studiowaves Member Posts: 197 Tri

    Thanks a lot bolabo, I was able to use the one you suggested. Not sure if I'd ever known it used lower cpu. Hope I can return the favor someday. Today's project is shutting down the clock generator that runs an envelope generator. This is a 50 voice fm synth with 12 oscillators, 12 ahdsr env gens and a few other things. With the dup filters and working with events as much as possible I've manage to run 50 voices at 32k. The dup filters have really been useful. I found a way to shut down the oscillators when the env generators finish the release phase. However shutting the env generators down is not that easy. I need to feed the gens finished flag back to the clock generator and stop it. The feedback flag will need to be latched by the clock generator before it stops the clock and an incoming gate needs to turn the clock on. At this stage if all goes well, the env gen will resume it's last state and pick up where it left off. So the incoming gate has to override the stop flag before in actually arrives at the gate input of the env gen. Not sure how to do that yet but so far so good. Thanks again.

Back To Top