2 #include <Fx/Types.hpp>
4 #include <halp/audio.hpp>
5 #include <halp/callback.hpp>
6 #include <halp/controls.hpp>
7 #include <halp/meta.hpp>
15 halp_meta(name,
"Envelope")
16 halp_meta(c_name,
"Envelope")
17 halp_meta(category,
"Audio")
18 halp_meta(author,
"ossia score")
19 halp_meta(manual_url,
"https://ossia.io/score-docs/processes/analysis.html#envelope")
20 halp_meta(description,
"Converts an audio signal into RMS and peak values")
21 halp_meta(uuid,
"95F44151-13EF-4537-8189-0CC243341269");
26 halp::dynamic_audio_bus<
"in", FP> audio;
30 halp::callback<
"rms", multichannel_output_type> rms;
31 halp::callback<
"peak", multichannel_output_type> peak;
34 halp_flag(deprecated);
36 static auto get(
const avnd::span<FP>& chan)
42 for(
auto sample : chan)
44 max = std::max(max, std::abs(sample));
45 rms += sample * sample;
50 return std::make_pair(rms, max);
54 return std::make_pair(FP{}, FP{});
58 void operator()(
int d)
60 auto& audio = inputs.audio;
61 switch(audio.channels)
66 auto [rms, peak] = get(audio.channel(0, d));
72 multichannel_output_vector peak_vec;
73 peak_vec.reserve(audio.channels);
74 multichannel_output_vector rms_vec;
75 rms_vec.reserve(audio.channels);
76 for(
int i = 0; i < audio.channels; i++)
78 auto [rms, peak] = get(audio.channel(i, d));
79 rms_vec.push_back(rms);
80 peak_vec.push_back(peak);
83 outputs.peak(peak_vec);
Definition: score-plugin-fx/Fx/Envelope.hpp:14