13 rmix_ (seed1 | 1), next_ (seed2 ? seed2 : 0x14057b7ef767814fU)
22 constexpr uint64_t M = 0xd3833e804f4c574bU;
25 rmix_ =
rotr (rmix_ - last, 37);
33 constexpr float i2f = 4.65661287416159475086293992373695129617e-10;
41template<
size_t N,
class D,
class F>
extern inline F
42iir_eval_tdf2 (
const D *b,
const D *a, D *w, F x)
44 static_assert (N >= 1);
45 const D y = x * b[0] + w[0];
46 D v = x * b[N] - y * a[N];
52 v = x * b[n] + t - y * a[n];
62 static constexpr size_t N = 3;
63 static constexpr Float B[N + 1] = { 0.049922035, -0.095993537, 0.050612699, -0.004408786 };
64 static constexpr Float A[N + 1] = { 1, -2.494956002, 2.017265875, -0.522189400 };
65 float delays_[N] = { 0, };
66 void reset () {
floatfill (delays_, 0.0, N); }
67 Float eval (Float x) {
return iir_eval_tdf2<N> (B, A, delays_, x); }
70template<
class F>
static inline F
73 constexpr F db2log2 = 0.166096404744368117393515971474469508793;
79 using Pink = PinkFilter<float>;
81 WhiteRand white_rand_;
83 float gain_factor_ = 1.0;
86 enum Params { GAIN = 1,
MONO, PINK };
88 ColoredNoise (
const ProcessorSetup &psetup) :
95 info.
label =
"Pink & White Noise";
104 stereout_ =
add_output_bus (
"Stereo Out", SpeakerArrangement::STEREO);
108 pmap.
group =
_(
"Noise Settings");
109 pmap[GAIN] =
Param {
"gain",
_(
"Gain"),
_(
"Gain"), 0,
"dB", { -96, 24, }, };
110 pmap[
MONO] =
Param {
"mono",
_(
"Monophonic"),
_(
"Mono"),
false };
111 pmap[PINK] =
Param {
"pink",
_(
"Pink Noise"),
_(
"Pink"),
true };
116 adjust_param (uint32_t tag)
override
118 switch (Params (tag))
120 case GAIN: gain_factor_ = db2amp (get_param (tag));
break;
122 case PINK: pink_ =
get_param (tag);
break;
126 reset (
uint64 target_stamp)
override
132 void render (
uint n_frames)
override;
134 enum Cases { INSTEREO = 1, WITHPINK = 2, WITHGAIN = 4, MASK = 0x7 };
135 template<Cases>
void render_cases (
float *out0,
float *out1,
uint n_frames,
const float gain);
139static auto noise_module = register_audio_processor<ColoredNoise> (
"Ase::Devices::ColoredNoise");
141template<ColoredNoise::Cases CASES>
void
142ColoredNoise::render_cases (
float *out0,
float *out1,
uint n_frames,
const float gain)
144 static_assert (CASES <= MASK);
145 for (
size_t i = 0; i < n_frames; i++)
147 auto [f0, f1] = white_rand_.randf2();
148 if_constexpr (
bool (CASES & WITHPINK) &&
bool (CASES & INSTEREO))
150 f0 = pink0.eval (f0);
151 f1 = pink1.eval (f1);
153 if_constexpr (
bool (CASES & WITHPINK) && !
bool (CASES & INSTEREO))
155 f0 = pink0.eval (f0);
156 f1 = pink0.eval (f1);
180static const auto render_table = make_case_table<ColoredNoise::MASK> ([] (
auto CASE)
182 return &ColoredNoise::render_cases<ColoredNoise::Cases (CASE.value)>;
186ColoredNoise::render (
uint n_frames)
188 apply_input_events();
189 float *out0 = oblock (stereout_, 0);
190 float *out1 = oblock (stereout_, 1);
191 const float gain = gain_factor_;
192 const uint index = INSTEREO * !mono_ + WITHPINK * pink_ + WITHGAIN * (gain != 1.0);
193 (this->*render_table[index]) (out0, out1, n_frames, gain);
Audio signal AudioProcessor base class, implemented by all effects and instruments.
void remove_all_buses()
Remove existing bus configurations, useful at the start of configure().
double get_param(Id32 paramid)
Fetch value of parameter id.
OBusId add_output_bus(CString uilabel, SpeakerArrangement speakerarrangement, const String &hints="", const String &blurb="")
Add an output bus with uilabel and channels configured via speakerarrangement.
virtual void initialize(SpeakerArrangement busses)=0
void install_params(const AudioParams::Map ¶ms)
Reset list of parameters, enqueues parameter value initializaiton events.
#define _(...)
Retrieve the translation of a C or C++ string.
#define if_constexpr
Indentation helper for editors that cannot (yet) decipher if constexpr
The Anklang C++ API namespace.
CString website_url
Website of/about this AudioProcessor.
uint64_t uint64
A 64-bit unsigned integer, use PRI*64 in format strings.
void floatfill(float *dst, float f, size_t n)
Fill n values of dst with f.
OBusId
ID type for AudioProcessor output buses, buses are numbered with increasing index.
CString version
Version identifier.
CString creator_name
Name of the creator.
CString label
Preferred user interface name.
uint32_t uint
Provide 'uint' as convenience type.
CString category
Category to allow grouping for processors of similar function.
Detailed information and common properties of AudioProcessor subclasses.
Structured initializer for Parameter.
Parameter list construction helper.
String group
Group to be applied to all newly inserted Parameter objects.