Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Position Synced StepLFO

Post any examples or modules that you want to share here

Re: PositionSyncedStepLFO - help?

Postby trogluddite » Sun Dec 02, 2012 12:30 pm

Looking good - you're picking up DSP coding pretty quick there!.
Nubeat7 wrote:tricky thing was the " round down to int for stream"

Rounding is a bit of a funny one in code, the function you need is 'rndint(x)'. The trouble is that it uses the standard rounding built into the CPU - and because PC's used to be used mostly by businesses, that's usually what is known as 'bankers rounding'. This is a form of 'round to nearest' except that exactly half-way values round alternately up and down. e.g. rndint(6.5) = 6, but rndint(7.5) = 8.
To always round down, you first have to subtract a number which is nearly 0.5, but not quite - which for our 32bit float numbers ends up being 0.49999997 (six 'nines' there); that's the number that's less than 0.5 by only one bit, so as close as you can get without actually being 0.5.

So to always round down...

Code: Select all
y = rndint(x-0.49999997);


The modulus function does work as expected, so you can still do...

Code: Select all
bar_loop = bars % loop_length.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1727
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: PositionSyncedStepLFO - help?

Postby Nubeat7 » Sun Dec 02, 2012 3:33 pm

thanks trog, hmm about the rounding down, i tried it with your way too but it didn`t work, i think its because you get values less than the int to be rounded.... am not really shure why it don`t work, the thing is when it should jump to 16 (4bars) the impulse is coming at 20 not at 16....

so the way how it works (don`t ask me why :)) is to round the value -> divide the not rounded value with the rounded value -> if it is less than 1 subtract 0.5 from not rounded value and round it ! so it is always rounded down when it would be rounded up but you never round a value which is less than the int where it should be rounded to

so i needed to code it like this:
Code: Select all
streamin floating;
streamout rndintfl;

float x,y,z,sub,rnd;

x = rndint(floating);
y = floating/x;
z = y < 1 & 1;
sub = z*0.5;
rnd = floating-sub;
rndintfl = rndint(rnd);

Attachments
rounddown.jpg
rounddown.jpg (39.29 KiB) Viewed 26557 times
Last edited by Nubeat7 on Mon Dec 03, 2012 12:49 pm, edited 1 time in total.
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: PositionSyncedStepLFO - help?

Postby Nubeat7 » Sun Dec 02, 2012 8:32 pm

after finishing the code, this is the the finished version, from my point, notice that it only works correct in 4/4 atm! you can also find the codes for the "special rndint" to round streams down or up ....

edit: check first file for latest version!
Last edited by Nubeat7 on Fri May 29, 2015 9:14 pm, edited 1 time in total.
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: PositionSyncedStepLFO - help?

Postby trogluddite » Wed Dec 05, 2012 12:50 am

Nubeat7 wrote:thanks trog, hmm about the rounding down, i tried it with your way too but it didn`t work

Sorry, my bad! :oops:
I was thinking of another situation when interpolating sample counters, where you have to keep the integer indexes in the right order for the lowest CPU - as you say, my "fix" just moves the "0.5" problem bang onto the integers, so that whole numbers don't always round properly. Very silly mistake! :roll:
For proper rounding down, there is a simpler way...
Code: Select all
rounded = rndint(x)
rounded = rounded - 1 & (rounded > x)

If the rounded value is greater then the number you started with, then it must have rounded up - in which case, just subtract one. This will use way less CPU, as divides are one of the most greedy operations you can do, and the DSP code rounding is also not always very efficient (so that it can support CPU's without SSE2).
And of course, you can round up by doing the opposite - add one if the rounded number is less than the start value.

I tested it this time! :D
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1727
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: PositionSyncedStepLFO - help?

Postby Nubeat7 » Fri Dec 07, 2012 9:07 pm

ahh, :D great that there is an easier way, always asking myself why i don`t see the easy ways first :) thanks!
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: PositionSyncedStepLFO - help?

Postby Nubeat7 » Tue Dec 11, 2012 9:25 pm

hmmm, but! like you can see at this schematic it is not working correctly! looks like it is still rounding up too !

i tried also a second way with the subtract method, looks that it is not working or did i confuse something in the code?

only the dividing method changes the int exactly in the same moment the float changes to the next int...
Attachments
round down.fsm
(19.95 KiB) Downloaded 1385 times
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: PositionSyncedStepLFO - help?

Postby Nubeat7 » Mon May 06, 2013 9:23 pm

ok, i tried to optimize the code via assembler and could reduce around 12 cycles and 4 variables,
buti only did delete the useless cycles so i think there is more space to optimise, just don`t know where to start, at the end the code is not very complex but this rounding thing is still very strange, but i couldn`t get it work correct in a different way

edit: check first file for latest version!
Last edited by Nubeat7 on Fri May 29, 2015 9:14 pm, edited 1 time in total.
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: PositionSyncedStepLFO - help?

Postby Tronic » Tue May 07, 2013 12:22 pm

for me in the module, PPQ to Ramp, in the Totalizer section,
there is an error:

//Totaliser
addps xmm0,xmm1;
//addps xmm0,negHalf; //**// this must be removed
movaps Ramp,xmm0;

otherwise when it resets, the value will start from -0.5, not from 0.

then, so the Trog trick, work good.

Code: Select all
rounded = rndint(x)
rounded = rounded - 1 & (rounded > x)
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: PositionSyncedStepLFO - help?

Postby Nubeat7 » Tue May 07, 2013 6:12 pm

ah yeah, thats interesting but i think it was not the reason, anyway i tried it again and this time i win :o

think i did something wrong all the time i tried before :?

so thanks for figuring this out and motivating me to try it again:)

so here is it with trogs rounding method, i also could eliminate a few cycles, is there still more to optimise?

edit: saved some cycles more with SSE2 rounding method, from trogs asm optimizing toolkit
edit: check first file for latest version!
Last edited by Nubeat7 on Fri May 29, 2015 9:15 pm, edited 2 times in total.
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: PositionSyncedStepLFO - help?

Postby Drnkhobo » Tue May 07, 2013 9:53 pm

Nice Nubeat7!!

:lol:
Drnkhobo
 
Posts: 312
Joined: Sun Aug 19, 2012 7:13 pm
Location: ZA

PreviousNext

Return to User Examples

Who is online

Users browsing this forum: No registered users and 43 guests