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
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
rnd optimization
31 posts
• Page 1 of 4 • 1, 2, 3, 4
rnd optimization
I'm trying to get back some of CPU in one of my projects, because adding a bunch of options added also some load too.
Here is a simple random generator. Used once - does not takes too much. But used in 20 copies or more - starts to generate few percentage load. Yes, must be stream (accurate) version.
My guess is, that - if this sort of random generator was made in one code and had multiple mono4 outputs - it would work faster. But this code does not looks like the best choice for copy/paste.
So my question is - any ideas how to make a simple random generator like this one, but with multiple mono4 outputs, and with with possibility to quickly add new outputs?
Any ideas how to reduce seeds amount in such design (righ now, there is 1 external/random seed pack per 1 output; I'd like to have just 1 external pack per multiple outputs if possible).
p.s.: can be hoped even more; but hop does not makes any change if multiple codes are in use.
Here is a simple random generator. Used once - does not takes too much. But used in 20 copies or more - starts to generate few percentage load. Yes, must be stream (accurate) version.
My guess is, that - if this sort of random generator was made in one code and had multiple mono4 outputs - it would work faster. But this code does not looks like the best choice for copy/paste.
So my question is - any ideas how to make a simple random generator like this one, but with multiple mono4 outputs, and with with possibility to quickly add new outputs?
Any ideas how to reduce seeds amount in such design (righ now, there is 1 external/random seed pack per 1 output; I'd like to have just 1 external pack per multiple outputs if possible).
p.s.: can be hoped even more; but hop does not makes any change if multiple codes are in use.
- Attachments
-
- rnd-gen.fsm
- (1.02 KiB) Downloaded 969 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: rnd optimization
I don't think you've set the hop code right.
That's your code:
this line is excuted every sample, which doesn't make sense:
every other line is only execute once every 128 sample... that means you reduce the Samplerate to fs/128 with massive aliasing. I think it should look like this:
That's your code:
- Code: Select all
streamin seed; // (0-1)
streamout out;
float rand=0.600001,lastseed;
rand = rand + (seed - rand)&(seed!=lastseed);
hop(128){
rand = rand*3;
rand = rand - (rand>2)&1;
rand = rand - (rand>1)&1;
out = abs((rand*2-1));
lastseed = seed;}
this line is excuted every sample, which doesn't make sense:
- Code: Select all
rand = rand + (seed - rand)&(seed!=lastseed);
every other line is only execute once every 128 sample... that means you reduce the Samplerate to fs/128 with massive aliasing. I think it should look like this:
- Code: Select all
streamin seed;
streamout out;
float rand=0.600001;
float lastseed;
hop(128){
rand = rand + (seed - rand)&(seed!=lastseed);
lastseed = seed;
}
rand = rand*3;
rand = rand - (rand>2)&1;
rand = rand - (rand>1)&1;
out = rand;
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: rnd optimization
Generally this code produces only random numbers, not sound.
Numbers are "latched" in long time periods (once per 0.01 to 7200 seconds) via separate module.
Numbers then are converted into various values.
Now the thing is - there are multiple (let say 10-60, depends on project) mono4 receivers. Right now, each receiver has it's own random number generator, but this means - a lot of codes with rnd formula.
My guess is, that having one larger code with multiple rnd outputs - would save 2-6 percent of CPU core at my 2GHz.
Thanks for note on hop.
I'm not good in this stuff yet.
Numbers are "latched" in long time periods (once per 0.01 to 7200 seconds) via separate module.
Numbers then are converted into various values.
Now the thing is - there are multiple (let say 10-60, depends on project) mono4 receivers. Right now, each receiver has it's own random number generator, but this means - a lot of codes with rnd formula.
My guess is, that having one larger code with multiple rnd outputs - would save 2-6 percent of CPU core at my 2GHz.
Thanks for note on hop.
I'm not good in this stuff yet.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: rnd optimization
Take a look MyCo what I mean.
I extracted only the rnd/get part.
If instead of having multiple rnd's I would have only one - I probably could save some usable CPU size, which seems to be crucial, because all projects operate on the threshold of glitchability.
I extracted only the rnd/get part.
If instead of having multiple rnd's I would have only one - I probably could save some usable CPU size, which seems to be crucial, because all projects operate on the threshold of glitchability.
- Attachments
-
- module.fsm
- (4.33 KiB) Downloaded 974 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: rnd optimization
When you rely on the separate seeds per channel, you have do duplicate the code. It doesn't matter if the code is in one box or in several... the overall code length will be the same.
Why don't you use Ruby?
Why don't you use Ruby?
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: rnd optimization
Generally I made this section in SM some time ago. And now I'm reviewing some parts, to see where can I get some CPU back. I don't how to make it in ruby, but more important - I have no idea whether making it in ruby - will save CPU.
Could you make a multi mono4out randomizer in ruby as an example? I'd like to check whether it will help here. Generally it can be slow (resolution is 100Hz), but it should produce a lot of paralel, irregular to eachother ("random"), (0-1) values. Reducing the seed (input) component would be nice, because now during start - a lot of seeds are retriggered.
As for codes - I think (not tested), that the result might be related to the amount of codes per schematic in first place, not the code content/size. What I was thinking - was some "lighter" code (for easier copy/paste) to produce rnd results.
Could you make a multi mono4out randomizer in ruby as an example? I'd like to check whether it will help here. Generally it can be slow (resolution is 100Hz), but it should produce a lot of paralel, irregular to eachother ("random"), (0-1) values. Reducing the seed (input) component would be nice, because now during start - a lot of seeds are retriggered.
As for codes - I think (not tested), that the result might be related to the amount of codes per schematic in first place, not the code content/size. What I was thinking - was some "lighter" code (for easier copy/paste) to produce rnd results.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: rnd optimization
Hey MyCo, I was thinking about something more in terms of code based solutions.
Only 1 random generator, but values sent to multiple outputs in a circular way (buffer like). 1st value sent to 1st out, 2nd value sent to 2nd out,... N-th value sent to N-th out, and next value sent to output 1 again, and so on. Thus - you would then have only one more input, to provide info on how long the queue should be. Smaller hop will compensate the rest.
Do you know how to make it?
Only 1 random generator, but values sent to multiple outputs in a circular way (buffer like). 1st value sent to 1st out, 2nd value sent to 2nd out,... N-th value sent to N-th out, and next value sent to output 1 again, and so on. Thus - you would then have only one more input, to provide info on how long the queue should be. Smaller hop will compensate the rest.
Do you know how to make it?
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: rnd optimization
From what I see, page 120 of SM users guide suggests, that "buffering" arrays of randoms should be possible. Thus - one code, multiple outputs. I also see, that in code there is a "rand" command for randomise (in my code it was mixed with something?); does it have a seed value?
MyCo?
//edit:
I'm slowly getting with something like this. From what I understand, "rand" command generates random numbers. So I would have now to add "seed" to "rand" (possible to whole array at once?), and make the output "minus 1" if results are higher than 1 (possible to whole array at once?).
One thing that I'm missing: how to make this thing running, to continuously produce new arrays?
MyCo?
//edit:
I'm slowly getting with something like this. From what I understand, "rand" command generates random numbers. So I would have now to add "seed" to "rand" (possible to whole array at once?), and make the output "minus 1" if results are higher than 1 (possible to whole array at once?).
One thing that I'm missing: how to make this thing running, to continuously produce new arrays?
- Attachments
-
- module-001.fsm
- (3.92 KiB) Downloaded 946 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: rnd optimization
Here is a stream random generator, that only randomizes when there is a trigger signal. As long as there is no trigger, at doesn't consume much CPU, because it jumps over the main code. This can only be done in Assembler, so I've used it for the main part.
I had to add a different timer to make this work. The one in the schematic produces only 1 sample long impulses on overflow.
I had to add a different timer to make this work. The one in the schematic produces only 1 sample long impulses on overflow.
- Attachments
-
- Stream Impulse Random (MyCo).fsm
- (2.22 KiB) Downloaded 965 times
Last edited by MyCo on Wed Jun 12, 2013 11:54 am, edited 1 time in total.
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: rnd optimization
Thanks, nice work.
I just made a brief test on RNDs via schematic/FS mode. In basic project - my old design consumes 5.4% of CPU while yours - only 1.5%. These 4% mean a lot here (3-4 live units more, or many more slow modulators). But these were raw tests; I'm excited to see this in action in the whole project.
Few questions.
What is the output range in your design? I see values going beyond 1 (I guess the upper range is 3?), but I don't know what is the min value here.
What is the purpose of setting the seed in (0.2,0.7) range? (or it does not matter for whitenoise-like distribution?).
I just made a brief test on RNDs via schematic/FS mode. In basic project - my old design consumes 5.4% of CPU while yours - only 1.5%. These 4% mean a lot here (3-4 live units more, or many more slow modulators). But these were raw tests; I'm excited to see this in action in the whole project.
Few questions.
What is the output range in your design? I see values going beyond 1 (I guess the upper range is 3?), but I don't know what is the min value here.
What is the purpose of setting the seed in (0.2,0.7) range? (or it does not matter for whitenoise-like distribution?).
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
31 posts
• Page 1 of 4 • 1, 2, 3, 4
Who is online
Users browsing this forum: No registered users and 100 guests