ArrayArrayArrayArray BrainModular BrainModular Users Forum 2017-12-18T00:38:30+02:00 https://www.brainmodular.com/forums/app.php/feed/topic/6025 2017-12-18T00:38:30+02:00 2017-12-18T00:38:30+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=6025&p=38797#p38797 <![CDATA[slowing down in onProcess]]> I'll try that asap. definitely going somewhere with this next module !
stay tune.

Olivar

Statistics: Posted by oli_lab — 17 Dec 2017, 23:38


]]>
2017-12-18T00:13:52+02:00 2017-12-18T00:13:52+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=6025&p=38796#p38796 <![CDATA[slowing down in onProcess]]> Statistics: Posted by 23fx23 — 17 Dec 2017, 23:13


]]>
2017-12-17T22:40:27+02:00 2017-12-17T22:40:27+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=6025&p=38795#p38795 <![CDATA[slowing down in onProcess]]>
If you use system time by checking it in every bloc, its more efficient to count blocs since it uses less CPU instructions.

You can use sample rate and bloc size to work out how many blocs make up the time interval, then just set a counter to the value and subtract 1 every bloc until the value gets to zero, then do the action and reset the bloc counter.
An example of counting blocs with interval approximately 0.1 seconds:

void ModuleClass::onInitModule (MasterInfo* pMasterInfo, ModuleInfo* pModuleInfo)
{
double interval_secs = 0.1; // Use double data type since sdkGetSampleRate returns double

int numblocs = (sdkGetSampleRate() / (double)sdkGetBlocSize()) * interval_secs; // "int" numblocs to truncate result

counter = numblocs;
}

void ModuleClass::onProcess(void)
{
if (--counter == 0) {
doAction();
counter = numblocs;
}
}

This is not always accurate due to rounding off to get an exact number of blocs. If you need it to be accurate on average over time, you can keep track of the truncated fraction and use it to adjust the bloc count.

If exact timing is required (perhaps part way through a bloc), a timer might be required (thread timer / windows timer, etc). If you use a callback timer the callback might be in a different thread so you might need thread protection (mutexes, etc.)

Hope that helps.

Statistics: Posted by sm_jamieson — 17 Dec 2017, 21:40


]]>
2017-12-17T18:59:23+02:00 2017-12-17T18:59:23+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=6025&p=38794#p38794 <![CDATA[slowing down in onProcess]]> I'm trying to build a physics engine for a new module,
most of the updates are done inside callback (record, play, mouse, inputs...)

but still the physics should be computed regularly even so there is no callbacks called back.

so some computation should be done in the onProcess() loop

what would be the best option(s) to have the physic engine tamed to reasonable speed ?

- just leave it as it is in the onProcess to be computed each time onProcess is called ?
- use samplerate and blocksize to have the computing done once every "n" blocks ?
- using system time ?

if someone is willing to share some code that just does that, it will be cool !

thanx

Olivar

Statistics: Posted by oli_lab — 17 Dec 2017, 17:59


]]>
BrainModular BrainModular Users Forum 2017-12-18T00:38:30+02:00 https://www.brainmodular.com/forums/app.php/feed/topic/6025 2017-12-18T00:38:30+02:00 2017-12-18T00:38:30+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=6025&p=38797#p38797 <![CDATA[slowing down in onProcess]]> I'll try that asap. definitely going somewhere with this next module !
stay tune.

Olivar

Statistics: Posted by oli_lab — 17 Dec 2017, 23:38


]]>
2017-12-18T00:13:52+02:00 2017-12-18T00:13:52+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=6025&p=38796#p38796 <![CDATA[slowing down in onProcess]]> Statistics: Posted by 23fx23 — 17 Dec 2017, 23:13


]]>
2017-12-17T22:40:27+02:00 2017-12-17T22:40:27+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=6025&p=38795#p38795 <![CDATA[slowing down in onProcess]]>
If you use system time by checking it in every bloc, its more efficient to count blocs since it uses less CPU instructions.

You can use sample rate and bloc size to work out how many blocs make up the time interval, then just set a counter to the value and subtract 1 every bloc until the value gets to zero, then do the action and reset the bloc counter.
An example of counting blocs with interval approximately 0.1 seconds:

void ModuleClass::onInitModule (MasterInfo* pMasterInfo, ModuleInfo* pModuleInfo)
{
double interval_secs = 0.1; // Use double data type since sdkGetSampleRate returns double

int numblocs = (sdkGetSampleRate() / (double)sdkGetBlocSize()) * interval_secs; // "int" numblocs to truncate result

counter = numblocs;
}

void ModuleClass::onProcess(void)
{
if (--counter == 0) {
doAction();
counter = numblocs;
}
}

This is not always accurate due to rounding off to get an exact number of blocs. If you need it to be accurate on average over time, you can keep track of the truncated fraction and use it to adjust the bloc count.

If exact timing is required (perhaps part way through a bloc), a timer might be required (thread timer / windows timer, etc). If you use a callback timer the callback might be in a different thread so you might need thread protection (mutexes, etc.)

Hope that helps.

Statistics: Posted by sm_jamieson — 17 Dec 2017, 21:40


]]>
2017-12-17T18:59:23+02:00 2017-12-17T18:59:23+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=6025&p=38794#p38794 <![CDATA[slowing down in onProcess]]> I'm trying to build a physics engine for a new module,
most of the updates are done inside callback (record, play, mouse, inputs...)

but still the physics should be computed regularly even so there is no callbacks called back.

so some computation should be done in the onProcess() loop

what would be the best option(s) to have the physic engine tamed to reasonable speed ?

- just leave it as it is in the onProcess to be computed each time onProcess is called ?
- use samplerate and blocksize to have the computing done once every "n" blocks ?
- using system time ?

if someone is willing to share some code that just does that, it will be cool !

thanx

Olivar

Statistics: Posted by oli_lab — 17 Dec 2017, 17:59


]]>