Description
Hi guys,
Lately I have been playing around with the CPP standalone device in realtime.
The way I do this is pretty close from what we used to do in brian1, that is tell brian to wait untill it is on par with real time. So, in Network::run
, I added this at the beginning of the main loop:
#if REALTIME
rel_time = std::clock()/(double)CLOCKS_PER_SEC - t_start;
// std::cout << "real time: " << rel_time << std::endl;
// std::cout << "brian time: " << clock->t_() << std::endl;
if (rel_time > clock->t_()){
std::cout << "running late: " << rel_time << std::endl;
}
while (rel_time < clock->t_()){
rel_time = std::clock()/(double)CLOCKS_PER_SEC - t_start;
}
#endif
This works fine (appart from what seem to be rounding errors), and I feel that using the #if
syntax is appropriate in this context.
Now, if I want fiddle around with the brian script and re-generate code, I have to redo this modification everytime, its a pain.
I am thinking that this is a straightforward enough change (and somewhat useful feature) to be included in brian2. But to do this cleanly, I have to figure out a way to modify a #define REALTIME (0)
statement at the top of network.cpp
, and as far as I understand, the contents of brianlib
are static (as in not code generated).
So, my question is, do you see an easy way to set a #define REALTIME (1)
conditionally on, say, a brian_prefs.codegen.realtime = True
?
I can upload my realtime brian2 branch if you want to have a look at the modified network.cpp
.
To satisfy you curiosity, the reason why I do this is that with CPP standalone, I can run 128 gammatone channels in realtime with my laptop. Therefore I'm currently trying to make a complete sound input > gammatone > realtime plotting with Qt
chain. Part of this requires some sort of realtime brian2. Any other ideas or remarks about this are welcome!