| 66 | } |
| 67 | |
| 68 | void process(const ProcessArgs& args) override { |
| 69 | |
| 70 | float strength = 1.0f; |
| 71 | if (inputs[STRENGTH_INPUT].isConnected()) { |
| 72 | strength = std::sqrt(clamp(inputs[STRENGTH_INPUT].getVoltage() / 10.0f, 0.0f, 1.0f)); |
| 73 | } |
| 74 | |
| 75 | // only calculate gains/decays every 16 samples |
| 76 | if (cvDivider.process()) { |
| 77 | for (int i = 0; i < 4; i++) { |
| 78 | gains[i] = std::pow(params[VOL_PARAMS + i].getValue(), 2.f) * strength; |
| 79 | |
| 80 | float fallCv = inputs[CV_INPUTS + i].getVoltage() * 0.05f + params[DECAY_PARAMS + i].getValue(); |
| 81 | envs[i].decayTime = rescale(std::pow(clamp(fallCv, 0.f, 1.0f), 2.f), 0.f, 1.f, minDecayTime, maxDecayTime); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | float_4 mix[4] = {}; |
| 86 | int maxPolyphonyChannels = 1; |
| 87 | |
| 88 | // Mixer channels |
| 89 | for (int i = 0; i < 4; i++) { |
| 90 | |
| 91 | if (trigger[i].process(rescale(inputs[TRIG_INPUTS + i].getVoltage(), 0.1f, 2.f, 0.f, 1.f))) { |
| 92 | envs[i].trigger(); |
| 93 | } |
| 94 | // if choke is enabled, and current channel is odd and left channel is in attack |
| 95 | if ((i % 2) && params[CHOKE_PARAMS + i / 2].getValue() && envs[i - 1].stage == ADEnvelope::STAGE_ATTACK) { |
| 96 | // TODO: is there a more graceful way to choke, e.g. rapid envelope? |
| 97 | // TODO: this will just silence it instantly, maybe switch to STAGE_DECAY and modify fall time |
| 98 | envs[i].stage = ADEnvelope::STAGE_OFF; |
| 99 | } |
| 100 | |
| 101 | envs[i].process(args.sampleTime); |
| 102 | |
| 103 | int polyphonyChannels = 1; |
| 104 | float_4 in[4] = {}; |
| 105 | bool inputIsConnected = inputs[CH_INPUTS + i].isConnected(); |
| 106 | bool inputIsNormed = !inputIsConnected && (i % 2) && inputs[CH_INPUTS + i - 1].isConnected(); |
| 107 | if ((inputIsConnected || inputIsNormed)) { |
| 108 | int channelToReadFrom = inputIsNormed ? CH_INPUTS + i - 1 : CH_INPUTS + i; |
| 109 | polyphonyChannels = inputs[channelToReadFrom].getChannels(); |
| 110 | |
| 111 | // an input only counts towards the main output polyphony count if it's not taken out of the mix |
| 112 | // (i.e. an output is patched in). the final input should always count towards polyphony count. |
| 113 | if (i == CH_INPUTS_LAST || !outputs[CH_OUTPUTS + i].isConnected()) { |
| 114 | maxPolyphonyChannels = std::max(maxPolyphonyChannels, polyphonyChannels); |
| 115 | } |
| 116 | |
| 117 | // only process input audio if envelope is active |
| 118 | if (envs[i].stage != ADEnvelope::STAGE_OFF) { |
| 119 | float gain = gains[i] * envs[i].env; |
| 120 | for (int c = 0; c < polyphonyChannels; c += 4) { |
| 121 | in[c / 4] = inputs[channelToReadFrom].getVoltageSimd<float_4>(c) * gain; |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 |
nothing calls this directly
no test coverage detected