Re: PositionSyncedStepLFO - help?
Posted: Sun Dec 02, 2012 12:30 pm
Looking good - you're picking up DSP coding pretty quick there!.
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...
The modulus function does work as expected, so you can still do...
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.