engine that generates a burst when triggered
| 64 | |
| 65 | // engine that generates a burst when triggered |
| 66 | struct BurstEngine { |
| 67 | |
| 68 | dsp::PulseGenerator eocOutput; // for generating EOC trigger |
| 69 | dsp::PulseGenerator burstOutput; // for generating triggers for each occurance of the burst |
| 70 | dsp::Timer burstTimer; // for timing how far through the current burst we are |
| 71 | |
| 72 | float timings[MAX_REPETITIONS + 1] = {}; // store timings (calculated once on burst trigger) |
| 73 | |
| 74 | int triggersOccurred = 0; // how many triggers have been |
| 75 | int triggersRequested = 0; // how many bursts have been requested (fixed over course of burst) |
| 76 | bool active = true; // is there a burst active |
| 77 | bool wasInhibited = false; // was this burst inhibited (i.e. just the first trigger sent) |
| 78 | |
| 79 | std::tuple<float, float, bool> process(float sampleTime) { |
| 80 | |
| 81 | if (active) { |
| 82 | burstTimer.process(sampleTime); |
| 83 | } |
| 84 | |
| 85 | bool eocTriggered = false; |
| 86 | if (burstTimer.time > timings[triggersOccurred]) { |
| 87 | if (triggersOccurred < triggersRequested) { |
| 88 | burstOutput.reset(); |
| 89 | burstOutput.trigger(TRIGGER_TIME); |
| 90 | } |
| 91 | else if (triggersOccurred == triggersRequested) { |
| 92 | eocOutput.reset(); |
| 93 | eocOutput.trigger(TRIGGER_TIME); |
| 94 | active = false; |
| 95 | eocTriggered = true; |
| 96 | } |
| 97 | triggersOccurred++; |
| 98 | } |
| 99 | |
| 100 | const float burstOut = burstOutput.process(sampleTime); |
| 101 | // NOTE: we don't get EOC if the burst was inhibited |
| 102 | const float eocOut = eocOutput.process(sampleTime) * !wasInhibited; |
| 103 | return std::make_tuple(burstOut, eocOut, eocTriggered); |
| 104 | } |
| 105 | |
| 106 | void trigger(int numBursts, int multDiv, float baseTimeWindow, float distribution, bool inhibitBurst, bool includeOriginalTrigger) { |
| 107 | |
| 108 | active = true; |
| 109 | wasInhibited = inhibitBurst; |
| 110 | |
| 111 | // the window in which the burst fits is a multiple (or division) of the base tempo |
| 112 | int divisions = multDiv + (multDiv > 0 ? 1 : multDiv < 0 ? -1 : 0); // skip 2/-2 |
| 113 | float actualTimeWindow = baseTimeWindow; |
| 114 | if (divisions > 0) { |
| 115 | actualTimeWindow = baseTimeWindow * divisions; |
| 116 | } |
| 117 | else if (divisions < 0) { |
| 118 | actualTimeWindow = baseTimeWindow / (-divisions); |
| 119 | } |
| 120 | |
| 121 | // calculate the times at which triggers should fire, will be skewed by distribution |
| 122 | const float power = 1 + std::abs(distribution) * 2; |
| 123 | for (int i = 0; i <= numBursts; ++i) { |
nothing calls this directly
no outgoing calls
no test coverage detected