- Edited
I'm sending various parameters from PD on my laptop to Bela (C++)over OSC. The basic syntax is: the parameter label ('fmSynth' for example) and the value (a float or int). There are about 250 different labels. My challenge is: what's the best way to convert the OSC transmissions to local variables on the Bela.
My initial method has been to use an unordered map:
std::unordered_map<std::string, float> state
Setting a received parameter/value (between call to renders, when the code looks for new OSC messages) looks like this:
state[parameter] = value;
And retrieving it looks like this:
auto it = state.find(parameter);
if(it!= state.end()) {
return it->second;
}
This seems to work well logically, however, after I retrieve more than a few parameters for each sample processed, the CPU usage shoots up 50% and I start to get buffer underruns.
Any suggestion? I'm trying to avoid an approach where I have to compare each incoming parameter to a known variable and end up with 250 'if' statements. In reflection, perhaps I could use more specific OSC addresses ('audio/fmSynth', for example)? Ultimately performance is the most important for me, even if it requires more code than less. Thanks!