159 const VArray<float> × = params.readonly_single_input<
float>(0,
"Time");
160 const VArray<bool> &all_channels_varray = params.readonly_single_input<
bool>(1,
162 const VArray<int> &channels = params.readonly_single_input<
int>(2,
"Channel");
163 const VArray<float> &lows = params.readonly_single_input<
float>(3,
"Low");
164 const VArray<float> &highs = params.readonly_single_input<
float>(4,
"High");
165 MutableSpan<float> amplitudes = params.uninitialized_single_output<
float>(5,
"Amplitude");
167 const std::optional<bool> all_channels_value = all_channels_varray.get_if_single();
168 const std::optional<float> channel_value = channels.get_if_single();
169 const bool constant_channel = all_channels_value ==
true ||
170 (all_channels_value.has_value() && channel_value.has_value());
176 if (constant_channel) {
180 key.
channel = *all_channels_value ? std::nullopt : channel_value;
181 const std::shared_ptr<const bke::bSoundFrequencySampler>
sampler =
187 mask.foreach_index([&](
const int i) {
188 const float time = times[i];
189 const float low = lows[i];
190 const float high = highs[i];
191 const float amplitude =
sampler->sample(
192 time, low, high, time_interpolation, frequency_interpolation);
193 amplitudes[i] = amplitude;
200 constexpr int channel_array_size = 6;
201 std::array<Vector<int>, channel_array_size> indices_by_channel;
204 mask.foreach_index([&](
const int i) {
205 const bool all_channels = all_channels_varray[i];
207 indices_with_all_channels.
append(i);
210 const int channel = channels[i];
211 if (channel >= 0 && channel < channel_array_size) {
212 indices_by_channel[channel].append(i);
215 indices_with_different_channel.
add(channel, i);
221 auto sample_indices_in_channel = [&](
const Span<int> indices,
222 const std::optional<int> channel) {
230 const std::shared_ptr<const bke::bSoundFrequencySampler>
sampler =
233 amplitudes.fill_indices(indices, 0.0f);
236 for (
const int i : indices) {
237 const float time = times[i];
238 const float low = lows[i];
239 const float high = highs[i];
240 const float amplitude =
sampler->sample(
241 time, low, high, time_interpolation, frequency_interpolation);
242 amplitudes[i] = amplitude;
246 sample_indices_in_channel(indices_with_all_channels, std::nullopt);
247 for (
const int channel :
IndexRange(channel_array_size)) {
248 sample_indices_in_channel(indices_by_channel[channel], channel);
250 for (
const auto item : indices_with_different_channel.
items()) {
251 sample_indices_in_channel(item.value, item.key);