2#include <ossia/dataflow/graph_node.hpp>
3#include <ossia/dataflow/port.hpp>
8struct gain_node final :
public ossia::nonowning_graph_node
15 m_inlets.push_back(&audio_in);
16 m_inlets.push_back(&gain_in);
17 gain_in.target<ossia::value_port>()->type = ossia::decibel_u{};
18 m_outlets.push_back(&audio_out);
21 std::string label() const noexcept
override {
return "gain"; }
22 void run(
const ossia::token_request& t, ossia::exec_state_facade st)
noexcept override
24 auto& vals = gain_in.target<ossia::value_port>()->get_data();
27 ossia::linear{ossia::decibel{ossia::convert<float>(vals.back().value)}}
32 auto& out = *audio_out;
34 const auto [first_pos, N] = st.timings(t);
35 const int64_t last_pos = first_pos + N;
37 const auto channels = in.channels();
38 out.set_channels(channels);
40 for(std::size_t i = 0; i < channels; i++)
42 auto& in_c = in.channel(i);
43 auto& out_c = out.channel(i);
45 const int64_t cur_chan_size = in_c.size();
47 out_c.resize(st.bufferSize());
49 const auto* input = in_c.data();
50 auto* output = out_c.data();
51 if(cur_chan_size < last_pos)
53 for(int64_t j = first_pos; j < cur_chan_size; j++)
54 output[j] = gain * input[j];
56 for(int64_t j = cur_chan_size; j < last_pos; j++)
61 for(int64_t j = first_pos; j < last_pos; j++)
62 output[j] = gain * input[j];
68 ossia::audio_inlet audio_in;
69 ossia::value_inlet gain_in;
70 ossia::audio_outlet audio_out;
OSSIA_INLINE constexpr T clamp(T d, const T min, const T max) noexcept
clamp Returns the value bounded by a min and a max
Definition math.hpp:154