This might be a bit slower than expected because it needs to:Nowhk wrote:Code: Select all
for (int envelopeIndex = 0; envelopeIndex < ENVELOPES_CONTAINER_NUM_ENVELOPE_MANAGER; envelopeIndex++) { Envelope &envelope = pEnvelopesContainer->pEnvelopeManager[envelopeIndex]->mEnvelope; VoiceParameters &voiceParameters = envelope.mVoiceParameters[voiceIndex];
- Load a pointer (pEnvelopesContainer)
- (If pEnvelopeManager is a std::vector, it needs to load the pointer to that data)
- Load a pointer from that indexed location (pEnvelopeManager[envelopeIndex])
- Load the indexed voice parameters from there
Generally this kind of indirection (3 or 4 levels instead of 1) is fine for control code (ie stuff that runs per block), but tends to show up on the profiler if it runs per sample... Why not just put all your envelope data inside your voice object?
Another thing is that you could probably have a single 128-sample counter for all of your envelopes instead of one per envelope, this way 127 samples out of 128, no envelope code would run at all!
I'm starting to suspect that there's something slow that you're calling within your per-sample loop and it's just not in the code you're showing us. Something like:
- printf() calls (or cout)
- slow math functions like sqrt() or % or /
- malloc/free or anything that ends up calling that (new/delete, modifying an std::string etc)
- file access
- virtual function calls (ideally your inner per-sample loop should have no function calls at all)
- unaligned objects (for instance if you declare everything with #pragma pack())