Overview
When EVENT_INIT_POSTCONNECT is fired, all components in the system have been created, and the Base Sample Rate has been negotiated. It is now available (and non-zero) through time->baseSampleRate. At this point, you may want to precalculate temporal parameters that are dependent on this rate. Note that if you do this in an earlier event, you will get a duff result because the Base Sample Rate is not yet decided. Therefore, EVENT_INIT_POSTCONNECT will be important to you if you have such parameters to precalculate.
Generally, you should assume that all timing information (everything in ComponentTime) is only valid from this event onwards. Therefore, it is strongly recommended that you do all your timing calculations in this event. In current systems, ComponentTime::sampleRate will in fact be valid right from the outset, but if there is demand, a future implementation may violate this assumption. Therefore, best practice is to stick to this approach.
Example
C++ Source Code (against 1199)
...
DOUBLE BaseSamplePeriod ;
DOUBLE ProcessSamplePeriod ;
DOUBLE lambda ;
...
case EVENT_INIT_POSTCONNECT:
{
...
BaseSamplePeriod =
sampleRateToPeriod (time ->baseSampleRate );
BaseSamplePeriod =
((DOUBLE)time ->baseSampleRate .den ) /
((DOUBLE)time ->baseSampleRate .num );
ProcessSamplePeriod =
sampleRateToPeriod (time ->sampleRate );
ProcessSamplePeriod =
time ->samplePeriod * BaseSamplePeriod ;
lambda = exp (-ProcessSamplePeriod / tau );
...
}
case EVENT_RUN_SERVICE:
{
...
DOUBLE timeInSeconds = time ->now * BaseSamplePeriod ;
myState *= lambda ;
...
}
|