10 std::shared_ptr<Kinesis::Stochastic::Weights> require_table(std::shared_ptr<Kinesis::Stochastic::Weights> table)
13 error<std::invalid_argument>(
15 std::source_location::current(),
16 "CombineOperator: null weights table");
24 const auto self = weak_from_this().lock();
26 m_body(self,
slots(),
static_cast<uint32_t
>(frames));
52 const auto num_frames =
static_cast<uint32_t
>(frames);
54 for (
auto& slot :
slots()) {
55 const bool active = slot.active;
56 auto block = slot.prepare_block(num_frames);
60 for (uint32_t i = 0; i < num_frames; ++i) {
67 const double level = slot.level;
68 for (uint32_t i = 0; i < num_frames; ++i) {
69 block[i] = active ? level : 0.0;
77 , m_inputs(
std::move(inputs))
78 , m_values(m_inputs.
size(), 0.0)
79 , m_kernel(function ?
Kernel([function =
std::move(function)](const
std::vector<double>&
values,
std::span<double>) {
88 , m_inputs(
std::move(inputs))
89 , m_values(m_inputs.
size(), 0.0)
90 , m_coefficients(
std::move(coefficients))
91 , m_kernel(function ?
Kernel([function =
std::move(function)](const
std::vector<double>&
values,
std::span<double> coefs) {
92 return function(
values, coefs);
100 if (param.size() < 2 || param.front() !=
'c') {
105 const auto digits = param.substr(1);
106 const auto [end, error] = std::from_chars(digits.data(), digits.data() + digits.size(),
index);
107 if (error != std::errc {} || end != digits.data() + digits.size()) {
136 const auto num_frames =
static_cast<uint32_t
>(frames);
139 auto out = target.prepare_block(num_frames);
141 for (uint32_t frame = 0; frame < num_frames; ++frame) {
142 for (
size_t i = 0; i <
m_inputs.size(); ++i) {
143 const size_t input_index =
m_inputs[i];
145 m_values[i] = frame == 0 ? target.level :
out[frame - 1];
147 m_values[i] = all[input_index].block.size() > frame
148 ? all[input_index].block[frame]
149 : all[input_index].level;
154 target.set_active(
out[frame] > 0.5);
158 if (num_frames > 0) {
159 target.level =
out[num_frames - 1];
164 : m_weights(
std::make_shared<Kinesis::Stochastic::Weights>(slot_count,
std::
max<size_t>(1, output_count)))
165 , m_outputs(
std::
max<size_t>(1, output_count))
166 , m_values(slot_count, 0.0)
168 for (
size_t row = 0; row < slot_count; ++row) {
169 (*m_weights)(row, 0) = 1.0;
174 : m_weights(require_table(
std::move(table)))
175 , m_outputs(
std::
max<size_t>(1, m_weights->cols()))
176 , m_values(m_weights->
rows(), 0.0)
183 error<std::out_of_range>(
185 std::source_location::current(),
186 "CombineOperator::weight: ({}, {}) outside the weights table ({} x {})",
194 const auto num_frames =
static_cast<uint32_t
>(frames);
207 for (uint32_t frame = 0; frame < num_frames; ++frame) {
208 for (
size_t m = 0; m <
count; ++m) {
209 m_values[m] = all[m].block.size() > frame ? all[m].block[frame] : all[m].level;
212 for (
size_t o = 0; o <
m_outputs.size(); ++o) {
219 for (
size_t m = 0; m <
count; ++m) {
std::vector< float > * out
std::vector< std::byte > values
Proxy for one cell with atomic load and store.
void process(float frames) override
Process for one batch cycle.
std::vector< double > m_scratch
std::vector< double > m_block
bool has_combine() const noexcept
std::span< const double > get_output_block(size_t index) const override
void process(float frames) override
Process for one batch cycle.
Output & output(size_t index)
CombineOperator(size_t slot_count, size_t output_count=1)
std::shared_ptr< Kinesis::Stochastic::Weights > m_weights
Kinesis::Stochastic::Weights::Cell weight(size_t slot, size_t output)
One weight cell, readable and assignable from any thread.
std::vector< double > m_values
std::vector< Output > m_outputs
std::vector< double > m_coefficients
std::vector< double > m_values
static std::optional< size_t > coefficient_index(std::string_view param)
std::optional< double > query_state(std::string_view query) const override
DeriveOperator(size_t target, std::vector< size_t > inputs, Function function)
std::function< double(std::span< const double >, std::span< double >)> CoefFunction
std::function< double(std::span< const double >)> Function
void process(float frames) override
Process for one batch cycle.
std::vector< size_t > m_inputs
void set_parameter(std::string_view param, double value) override
Set one coefficient.
std::function< double(const std::vector< double > &, std::span< double >)> Kernel
std::span< RelationSlot > slots() const noexcept
double parameter(std::string_view name) const
Value of a mapped or set parameter.
void process(float frames) override
Process for one batch cycle.
std::map< std::string, double, std::less<> > m_parameters
std::optional< double > query_state(std::string_view query) const override
Query operator internal state.
void set_parameter(std::string_view param, double value) override
Set operator parameter.
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Init
Engine/subsystem initialization.
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
void extract_node_samples(const std::shared_ptr< Nodes::Node > &node, std::vector< double > &buffer, size_t &buffer_pos, size_t num_samples)
Extract num_samples from node into buffer using snapshot guard.