Loading...
Searching...
No Matches
score-plugin-analysis/Analysis/Envelope.hpp
1#pragma once
2#include <Analysis/GistState.hpp>
3#include <Analysis/Helpers.hpp>
4#include <halp/audio.hpp>
5#include <halp/callback.hpp>
6#include <halp/controls.hpp>
7#include <halp/meta.hpp>
8
9namespace Analysis
10{
12{
13 halp_meta(name, "RMS")
14 halp_meta(c_name, "RMS")
15 halp_meta(category, "Analysis/Envelope")
16 halp_meta(author, "ossia score, Gist library")
17 halp_meta(manual_url, "https://ossia.io/score-docs/processes/analysis.html#envelope")
18 halp_meta(description, "Get the RMS of a signal")
19 halp_meta(uuid, "5d4057ff-d8d0-4d66-9e0f-55675e3323be");
20
21 struct
22 {
23 audio_in audio;
24 gain_slider gain;
25 gate_slider gate;
26 } inputs;
27 struct
28 {
29 value_out result;
30 } outputs;
31
32 void operator()(int frames)
33 {
34 process<&Gist<double>::rootMeanSquare>(
35 inputs.audio, inputs.gain, inputs.gate, outputs.result, frames);
36 }
37};
38
40{
41 halp_meta(name, "Peak")
42 halp_meta(c_name, "Peak")
43 halp_meta(category, "Analysis/Envelope")
44 halp_meta(author, "ossia score, Gist library")
45 halp_meta(manual_url, "https://ossia.io/score-docs/processes/analysis.html#envelope")
46 halp_meta(description, "Get the peak energy of a signal")
47 halp_meta(uuid, "a14c8ced-25e6-4c89-ac45-63750cbb87fd")
48
49 struct
50 {
51 audio_in audio;
52 gain_slider gain;
53 gate_slider gate;
54 } inputs;
55 struct
56 {
57 value_out result;
58 } outputs;
59
60 void operator()(int frames)
61 {
62 process<&Gist<double>::peakEnergy>(
63 inputs.audio, inputs.gain, inputs.gate, outputs.result, frames);
64 }
65};
66
68{
69 halp_meta(name, "Envelope Follower (audio)")
70 halp_meta(c_name, "EnvelopeFollowerAudio")
71 halp_meta(category, "Analysis/Envelope")
72 halp_meta(author, "Kevin Ferguson")
73 halp_meta(manual_url, "https://ossia.io/score-docs/processes/analysis.html#envelope")
74 halp_meta(
75 description,
76 "Sample-level envelope Follower\n"
77 "(https://kferg.dev/posts/2020/audio-reactive-programming-envelope-followers/)")
78 halp_meta(uuid, "0a262706-1216-44f4-85ca-52f1f25785bc")
79
80 struct inputs
81 {
82 halp::knob_f32<"Millis (up)", halp::range{0., 1000., 50.}> a;
83 halp::knob_f32<"Millis (down)", halp::range{0., 1000., 15.}> b;
84 };
85 struct outputs
86 {
87 };
88 void prepare(halp::setup s) { rate = s.rate; }
89 double rate{48000.};
90 double y{};
91
92 double operator()(double x, struct inputs inputs, outputs) noexcept
93 {
94 using namespace std;
95 const auto abs_x = abs(x);
96 if(rate > 0)
97 {
98 const auto a = exp(log(0.5) / (rate * (inputs.a.value / 1000.0)));
99 const auto b = exp(log(0.5) / (rate * (inputs.b.value / 1000.0)));
100
101 const auto coeff = (abs_x > y) ? a : b;
102 y = coeff * y + (1. - coeff) * abs_x;
103 }
104 else
105 {
106 y = 0.;
107 }
108 return y;
109 }
110};
111}
STL namespace.
Definition score-plugin-analysis/Analysis/Envelope.hpp:68
Definition GistState.hpp:26
Definition score-plugin-analysis/Analysis/Envelope.hpp:40
Definition score-plugin-analysis/Analysis/Envelope.hpp:12
Definition Helpers.hpp:27
Definition Helpers.hpp:34
Definition Helpers.hpp:43
Definition Helpers.hpp:19