| 146 | } |
| 147 | |
| 148 | static inline |
| 149 | float applyModel(DynamicModel* model, float sample, const float param1, const float param2) |
| 150 | { |
| 151 | const bool input_skip = model->input_skip; |
| 152 | const float input_gain = model->input_gain; |
| 153 | const float output_gain = model->output_gain; |
| 154 | |
| 155 | sample *= input_gain; |
| 156 | |
| 157 | std::visit( |
| 158 | [&sample, input_skip, output_gain, param1, param2] (auto&& custom_model) |
| 159 | { |
| 160 | using ModelType = std::decay_t<decltype (custom_model)>; |
| 161 | |
| 162 | if constexpr (ModelType::input_size == 1) |
| 163 | { |
| 164 | float* out = &sample; |
| 165 | if (input_skip) |
| 166 | { |
| 167 | sample += custom_model.forward(out); |
| 168 | sample *= output_gain; |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | sample = custom_model.forward(out) * output_gain; |
| 173 | } |
| 174 | } |
| 175 | else if constexpr (ModelType::input_size == 2) |
| 176 | { |
| 177 | float inArray1 alignas(RTNEURAL_DEFAULT_ALIGNMENT)[2] = {sample, param1}; |
| 178 | if (input_skip) |
| 179 | { |
| 180 | sample += custom_model.forward(inArray1); |
| 181 | sample *= output_gain; |
| 182 | } |
| 183 | else |
| 184 | { |
| 185 | sample = custom_model.forward(inArray1) * output_gain; |
| 186 | } |
| 187 | } |
| 188 | else if constexpr (ModelType::input_size == 3) |
| 189 | { |
| 190 | float inArray2 alignas(RTNEURAL_DEFAULT_ALIGNMENT)[3] = {sample, param1, param2}; |
| 191 | if (input_skip) |
| 192 | { |
| 193 | sample += custom_model.forward(inArray2); |
| 194 | sample *= output_gain; |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | sample = custom_model.forward(inArray2) * output_gain; |
| 199 | } |
| 200 | } |
| 201 | }, |
| 202 | model->variant |
| 203 | ); |
| 204 | |
| 205 | return sample; |