if a channel (0 - 11) should be updated, return it's index, otherwise return -1
| 40 | struct RoundRobinProcessor { |
| 41 | // if a channel (0 - 11) should be updated, return it's index, otherwise return -1 |
| 42 | int process(float sampleTime, float period, int numActiveChannels) { |
| 43 | |
| 44 | if (numActiveChannels == 0 || period <= 0) { |
| 45 | return -1; |
| 46 | } |
| 47 | |
| 48 | time += sampleTime; |
| 49 | |
| 50 | if (time > period) { |
| 51 | time -= period; |
| 52 | |
| 53 | // special case: when there's only one channel, the below logic (which looks for when active channel changes) |
| 54 | // wont fire. as we've completed a period, return an "update channel 0" value |
| 55 | if (numActiveChannels == 1) { |
| 56 | return 0; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | int currentActiveChannel = numActiveChannels * time / period; |
| 61 | |
| 62 | if (currentActiveChannel != previousActiveChannel) { |
| 63 | previousActiveChannel = currentActiveChannel; |
| 64 | return currentActiveChannel; |
| 65 | } |
| 66 | |
| 67 | // if we've got this far, no updates needed (-1) |
| 68 | return -1; |
| 69 | } |
| 70 | private: |
| 71 | float time = 0.f; |
| 72 | int previousActiveChannel = -1; |
nothing calls this directly
no outgoing calls
no test coverage detected