3 #include <Fx/MathMapping_generic.hpp>
4 #include <Fx/Types.hpp>
6 #include <ossia/dataflow/audio_port.hpp>
7 #include <ossia/dataflow/value_port.hpp>
9 #include <halp/layout.hpp>
13 namespace MathAudioGenerator
17 halp_meta(name,
"Expression Audio Generator")
18 halp_meta(c_name,
"MathAudioGenerator")
19 halp_meta(category,
"Audio/Utilities")
20 halp_meta(manual_url,
"https://ossia.io/score-docs/processes/exprtk.html#exprtk-support")
21 halp_meta(author,
"ossia score, ExprTK (Arash Partow)")
24 "Generate an audio signal from a math expression.\n"
25 "Available variables: a,b,c, t (samples), fs (sampling frequency)\n"
26 "See the documentation at http://www.partow.net/programming/exprtk")
27 halp_meta(uuid,
"eae294b3-afeb-4fba-bbe4-337998d3748a")
33 "var phi := 2 * pi * (20 + a * 500) / fs;\n"
36 "out[0] := b * cos(m1[0]);\n"
37 "out[1] := b * cos(m1[0]);\n">
40 halp::hslider_f32<
"Param (a)", halp::range{0., 1., 0.5}> a;
41 halp::hslider_f32<
"Param (b)", halp::range{0., 1., 0.5}> b;
42 halp::hslider_f32<
"Param (c)", halp::range{0., 1., 0.5}> c;
47 halp::variable_audio_bus<
"out",
double> audio;
63 expr.add_vector(
"out", cur_out);
64 expr.add_variable(
"t", cur_time);
65 expr.add_variable(
"a", a);
66 expr.add_variable(
"b", b);
67 expr.add_variable(
"c", c);
68 expr.add_variable(
"pa", pa);
69 expr.add_variable(
"pb", pb);
70 expr.add_variable(
"pc", pc);
71 expr.add_vector(
"m1", m1);
72 expr.add_vector(
"m2", m2);
73 expr.add_vector(
"m3", m3);
74 expr.add_variable(
"fs", fs);
77 expr.register_symbol_table();
80 void reset_symbols(std::size_t N)
83 if(N == cur_out.size())
86 expr.remove_vector(
"out");
87 expr.remove_vector(
"m1");
88 expr.remove_vector(
"m2");
89 expr.remove_vector(
"m3");
96 expr.add_vector(
"out", cur_out);
97 expr.add_vector(
"m1", m1);
98 expr.add_vector(
"m2", m2);
99 expr.add_vector(
"m3", m3);
101 expr.update_symbol_table();
103 std::vector<double> cur_out{};
105 double a{}, b{}, c{};
106 double pa{}, pb{}, pc{};
107 std::vector<double> m1, m2, m3;
109 ossia::math_expression expr;
114 static constexpr
int chans = 2;
115 void prepare(halp::setup s)
118 outputs.audio.request_channels(chans);
119 state.reset_symbols(chans);
122 using tick = halp::tick_flicks;
123 void operator()(
const tick& tk)
125 SCORE_ASSERT(outputs.audio.channels == 2);
129 self.fs = setup.rate;
130 if(!
self.expr.set_expression(inputs.expr))
133 self.reset_symbols(chans);
134 self.a = this->inputs.a;
135 self.b = this->inputs.b;
136 self.c = this->inputs.c;
137 for(int64_t i = 0; i < tk.frames; i++)
145 auto& channels = this->outputs.audio.samples;
146 for(
int j = 0; j < chans; j++)
148 channels[j][i] =
self.cur_out[j];
159 halp_meta(layout, halp::layouts::vbox)
162 halp_meta(layout, halp::layouts::hbox)
163 halp::control<&ins::a> a;
164 halp::control<&ins::b> b;
165 halp::control<&ins::c> c;
168 struct : halp::control<&ins::expr>
170 halp_flag(dynamic_size);
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33
Definition: MathAudioGenerator.hpp:158
Definition: MathAudioGenerator.hpp:16