SynthMaker

De-glitched Selector for mono streams...

Archive · 2006 27 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

Shifrin ·

Hey there,

After reading this thread I thought I'd try to fix the Selector so that it no longer glitched when changing. Here's what I've done (note: as the thread title says this is only for mono streams - should I change the streamins/outs in the code module to monoins/outs for better comprehension?!)

And inside the custom module :-

SelSmooth.osm

Basically instead of passing your selection to the Selector, you past it to this module which then deals with fadingout/in. It fades the original signal out and only then does it change the signal with the Selector, and only once the Selector has changed does it fade back in 🙂

No glitches. There's a property to specify the number of samples the fadeout/in will take. Easy to modify it to suit your needs.

Shif.

rlahalla ·

Hmm, this looks very interesting shif. I'm going to play with this a bit when I get back to the SM comp...got me thinking of a lot of cool stuff..big thanks! 🙂

Shifrin ·

Hope it works for you - I've tested it a fair bit!

Uploaded a new .osm/updated the second image - I changed the streamins/outs to monoins/outs as this can only be used for mono signals. Shortened the code too. Let me know any bugs you find!

Shif.

Shifrin ·

One other thing, I said no glitches but that is of course dependant on how many samples you use for the fading out/in! At 44100 somewhere around 50 samples works for me 😉

Shif.

Shifrin ·

A slight modification of the Selector Smoother module for stereo signals :-

SelSmoothStereo.osm

Shif.

Shifrin ·

Please let me know of any bugs, or ideas to improve this etc 😉

Shif.

rlahalla ·

No glitches yet [44100]...give me a few, and I'll try to break it though 😀

tor ·

hi

here i have another go at this issue. it implements as suggested here two selectors to have a proper cross fade. keep in mind the time logic/ fade control is in green. i also think this is more cpu friendly

you can easily modify it to any number of inputs

hope you like it tor

infuzion ·

Neat approach! But for some reason, when I change it to 500ms, I expect a smooth fade-in, the second sound seems to hit in at least 50% volume.

tor ·

thanks for letting me know. i see now that the selectorthat is spposed to be faded in is activated just before the fade is reset. so i must give it a differen approach. i made a quick fix. but there is still some small popps/noise that is unwanted. it is way better than the selector alone though 🙂

will look closer later. need some sleep here. but the thought of using poly for the fader/timing stuff could be cpu efficient and more precise if done right?

tor

infuzion ·

IMHO, you will never eliminate pops & clicks with the selector due to recompiling. Either create the VST without Selectors, or just put them in places where you use it when not playing audio.

trogluddite ·

infuzion wrote: IMHO, you will never eliminate pops & clicks with the selector due to recompiling.

The only way with selectors is; fade to zero->switch->fade up - no pops or clicks, but certainly a noticeable brief moment of silence. It's even possible that a sufficiently large schematic would cause pops due to the re-compile/stage(0)s hogging the CPU and interrupting the audio streams. If all switched modules are written in assembly it is possible to have execution jump over blocks of assembly when inactive - but using the jumping routine on several effects will naturally carry some CPU overhead.

tor ·

hmmmm..... what if a multiplier with 0 value halted the signal just like a dead end.... would save a lot of CPU and make mixers work like a selector 😀

stw ·

trogluddite wrote: infuzion wrote: IMHO, you will never eliminate pops & clicks with the selector due to recompiling.

The only way with selectors is; fade to zero->switch->fade up - no pops or clicks, but certainly a noticeable brief moment of silence.

I doubt that and go with infuzion here. When i started with SM i once spent alot of time to find a way for eliminate the clicks. But i failed. I remeber to have tested it at last only with a dead end selector and couldn't get rid of the disruptions. However i made the expreience that it also depends on the choosen audio driver how loud or if the clicks are hearable at all. IIRC asio drivers are more prone than direct sound drivers.

trogluddite ·

trogluddite wrote: fade to zero->switch->fade up

Sorry, I should have been more exact - I was meaning to fade up and down the main output - just like the 'soft-start' relay used in many power amps. I've had a little success with this method, but it adds a whole level of complexity to a schematic - which only gets worse as you add more selectors, as they all need 2 way communication with the 'soft-start' components.

In any other case, stw iand infuzion are quite right - doing the 'smoothing' further 'upstream' in the schematic can cause clicks because you have no idea what values might be sent to the output from parts of the schematic 'downstream' of the switch - or how many samples will be 'interrupted' by the re-compiling.

tor wrote: hmmmm..... what if a multiplier with 0 value halted the signal just like a dead end.... would save a lot of CPU and make mixers work like a selector

I have been messing with doing just that - sadly it can only be done when everything is made in assembly, but the necessary instructions use very little CPU. Will post up my latest experiment when I get home from work.

sunsynth ·

Hey Luddite,

Will post up my latest experiment when I get home from work.

I know u have no power in ur home now sometimes 😉 but... please show us ur newest 'experiment'

Cheers, Walter

trogluddite ·

sunsynth wrote: I know u have no power in ur home now sometimes

Almost ready to take the covers off everything (plaster dust, yuk!) - lucky I have a mains socket upstairs to charge my netbook! (should have put the files on there to carry on working, doh!)

But (from memory 😕 ) here's what I've been doing...

streamin input; streamin gain; streamout output;

pslld xmm0,32; //quick way to set a register to zero (no memory access) movaps output,xmm0; //make sure output is zero when bypass is activated mov eax, gain[0]; and eax, 2130706432; //quicker than cmp? (value should also bypass when gain is denormal) jz bypass; //bypass if gain=0

//MAIN CODE movaps xmm0,input; //... //... //(assuming final output value is in xmm0) mulps xmm0,gain; movaps output,xmm0; //END OF MAIN CODE

bypass: //label for jump

Basically, when gain=0, the effect is bypassed, leaving only 3-4 CPU cycles running for the 'bypass' code.

Note that this only really works perfectly for simple linear, non-recursive effects - if there's any kind of feedback or buffering, then values will be trapped in the buffer variables/arrays, and will still be there when the effect is next enabled. I'd like to make it so that the bypass doesn't happen until the output also dips below a threshold (looking for zero's is no good, as exponential decays never reach zero). But this has proven rather tricky, as any arbitrary audio signal can still contain numbers beneath the threshold, making the effect 'stutter' - and adding an averaging filter adds even more CPU cycles, which rather defeats the object of the exercise!

sunsynth ·

Thanks dude...

I'm near finishing our energy-saving measures project... 😈 😇 Man - i have 2 work hard near the end of it now - tons of stones 2 move... 😝

trogluddite ·

sunsynth wrote: I'm near finishing our energy-saving measures project... 😈 😇 Man - i have 2 work hard near the end of it now - tons of stones 2 move...

Lifting stones never seemed to save me any energy! 😈 😉 Anyway, I am now back in action, yay! 🙂 And I think I have something interesting in the 'Auto-shutdown' experiments...

streamin in; streamin select; //1=On, 0=Off streamout out;

float coeff=1e-09; int active=0;

pslld xmm0,32; //Quick zero - value passed to out when effect is bypassed mov eax,select[0]; add eax,out[0]; and eax,1610612736; //Leave top two bits of float exponent add eax,active[0]; shr eax,2; mov active[0],eax; jz bypass;

//MAIN movaps xmm0,in; mulps xmm0,select; subps xmm0,out; mulps xmm0,coeff; addps xmm0,out; //END MAIN (output must be in xmm0!!)

bypass: //Jump here when bypassed movaps out,xmm0;

Sorry this is just a text post - many things are in "safe places" after the building work - including the USB stick I use to transfer from my music PC to my internet machine. EDIT: Schematic file posted further down the thread

This one only bypasses the main code when select' is off (zero) and the audio output ('out') has decayed below a threshold for several samples. Some words of explanation...

1) The value of xmm0 is passed around the main routine when bypassed - so the 'out' variable is no longer zero'd prior to running the main code. This now makes feedback possible.

2) The 'MAIN' code here is just a very simple one-pole low pass filter; a good example for watching the output values decay. It's important that the input value is multiplied by the 'select' parameter - otherwise the output might never decay away, and the automatic turning off won't work

3) The tricksy bit... and eax,1610612736 For a float value this masks off all but the top two bits of the exponent. These two bits will only ever be zero if the ABS(float value) is less than 2^-64 (=about 1e-19) The masked number is then added to the current value of 'active' 'active' is then shifted right by two bits, making room for the two masked bits from the next iteration. If any bits in 'active' are set, then MAIN runs, otherwise it is bypassed. Because of the right shift, it takes 15 samples for any true bits to clear from 'active' - so intermittent zero crossings in the output waveform shouldn't cause the decay tails to be cut short, the signal has to be reliably below the threshold before the bypass engages.

My Core2 Quad shows only 2-3 cycles for the code when bypassed (though I'm not sure quite believe it - it would certainly be more on a CPU without 'out-of-order' processing).

aliasant ·

That is some nice stuff Trogg!

I did a test with a distortion code I had and when I turned the bypass on it used about 5cycles on my i7920 and when I switched off the bypass it used about 22cycles and the output was the exact same as a parallell signal. It looks as if it works.

trogluddite ·

aliasant wrote: It looks as if it works

I double checked the typing this time! For a distortion, you could also save some cycles by deleting the lines...

add eax,out[0];

...and...

add eax,active[0]; shr eax,2; mov active[0],eax;

...those are only needed if you need the effect to stay on while a decay tails off (e.g. delays and IIR filters).

Some other useful variations...

Ramp 'select' up and down and use it to fade the effect in and out - it will still turn off when the value goes below the threshold - totally kills clicks and pops.

If using the 'out' value checking - you can also 'add eax, out[n]' for the other SSE channels that are being used, so that it checks that all SSE channels are silent before turning off.

Use 'eax, in[n]' (in addition/instead of select[n]) to check when the input level is below threshold. I'm just playing with that at the moment on an effect used as a send on an internal sub-mixer - the delay now turns off if all the sends are off and all the decays have faded away. Because the decays have faded to below 64 bits before the effect turns off, the buffers are effectively empty, so no nasty 'ghost images' when the effect turns back on again!

theod ·

I had to deal with the same problem myself, only I needed to select between two inputs, unporcessed in and in through FX and not multiple ones. I crossfade between the two audio sources instead of crossfading to silence, and then I disconnect the audio in coming from my FX to turn it off (make it stop using CPU). Would you say its a good approach for a two ins only selector? I tried it and doesnt produce the slightest "click". I also take advantage of the fact that 0 = false, 1 = true so a selector of two ins in fact fluctuates between true and false.

DigitalWhiteByte ·

Great Stuff,

I noticed that for the opcode and eax, you can use directly in hexadecimal values​​. in this way,

and eax,1610612736; to and eax,0x60000000; (is the hex value correct?)

should work 😉

trogluddite ·

theod wrote: Would you say its a good approach for a two ins only selector? I tried it and doesnt produce the slightest "click"

Like everything in SM, it depends on the situation. If your schematic has any parts that use stage(0), then the switching will always cause stage(0) parts within mono/mono4 sections to run - possibly a problem if stage(0) is use to initialise variables. Also, in larger schematics, or when the CPU is busy, the switching can still cause a glitch. The 'CPU saving' relies on SM doing a complete scan of the schematic and re-arranging it to run properly in its new configuration (presumably some sort of self-modifying code that re-arranges the jumps and function calls). If this process cannot be completed within one sample cycle, then the audio will be interrupted across the schematic - again the results of that depend on exactly what processing you are doing. I've even known it to cause a splat across all sequencer tracks in a host, due to stalling the soundcard driver if the buffer size is set very small for low latency, though that is rarer on a nice fast CPU! As always, only plenty of testing will tell - if the technique works for your design, then it is a good one!

DWB wrote: and eax,0x60000000

Spot on! - Sometimes I am such a dumb*ss - I spent ages typing 1100000000000000000000000000000 in Windows calculator, and then checking that I had the right number or zeros!!

trogluddite ·

And here's a schematic at last...

This is the complete work so far, which has a crossfade generator module that also goes to sleep when the crossfade is complete. So (give or take a CPU cycle here and there), this is a set of effects that have their inputs multiplexed, but still with many of the benefits of SM's CPU saving, and less of the nasty side effects.

Some more CPU can be saved by deleting the lines of assembly that I've commented ("TEST") - that's there just to make the LEDs work so that there is a nice display of which code is actually running.

The "effects" are just very slow de-zipper filters - they show the way that the auto-bypass doesn't kick in until the effect 'tails' has properly died away. A nice side effect of the way this works is that the effects are never able to pass de-normals on to the next stage of the schematic.

I've put quite a few comments in the schematic, and there is a more details description of how the bypass works a few posts up.

sunsynth ·

Awesome work as usual Luddite 😀

Send u a PM...

theod ·

trogluddite wrote: theod wrote: Would you say its a good approach for a two ins only selector? I tried it and doesnt produce the slightest "click"

Like everything in SM, it depends on the situation. If your schematic has any parts that use stage(0), then the switching will always cause stage(0) parts within mono/mono4 sections to run - possibly a problem if stage(0) is use to initialise variables. ................................. As always, only plenty of testing will tell - if the technique works for your design, then it is a good one!

I havent learnt what "stages" are yet, but Im not sure if a problem I am facing with the above schematic is related to this. Didnt post it here in order not to "hijack" the thread. Here it is if you think you can help: Module not working when receiving automated data - SOLVED

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.