2#include "ase/processor.hh"
10class Saturation :
public AudioProcessor {
15 Saturation (
const ProcessorSetup &psetup) :
16 AudioProcessor (psetup)
19 static_info (AudioProcessorInfo &info)
22 info.label =
"Saturation";
23 info.category =
"Distortion";
24 info.creator_name =
"Stefan Westerfeld";
25 info.website_url =
"https://anklang.testbit.eu";
27 enum Params { MODE = 1, MIX, DRIVE };
31 stereoin = add_input_bus (
"Stereo In", SpeakerArrangement::STEREO);
32 stereout = add_output_bus (
"Stereo Out", SpeakerArrangement::STEREO);
35 pmap.
group =
"Settings";
38 centries += {
"Soft/tanh",
"Soft Saturation using the tanh function" };
39 centries += {
"Hard",
"Hard clipping" };
40 pmap[MODE] =
Param {
"mode",
"Mode",
"Mode", 0,
"", std::move (centries),
"", {
String (
"blurb=") +
_(
"Saturation Function"), } };
41 pmap[MIX] =
Param {
"mix",
"Mix dry/wet",
"Mix", 100,
"%", { 0, 100 } };
42 pmap[DRIVE] =
Param {
"drive",
"Drive",
"Drive", 0,
"dB", { -6, 36 } };
44 install_params (pmap);
46 prepare_event_input();
52 return SaturationDSP::Mode::HARD_CLIP;
53 return SaturationDSP::Mode::TANH_CHEAP;
56 adjust_param (uint32_t tag)
override
60 case DRIVE: saturation.set_drive (get_param (DRIVE),
false);
62 case MIX: saturation.set_mix (get_param (MIX),
false);
64 case MODE: saturation.set_mode (map_mode (get_param (MODE)));
69 reset (
uint64 target_stamp)
override
71 saturation.reset (sample_rate());
75 render_audio (
float *left_in,
float *right_in,
float *left_out,
float *right_out,
uint n_frames)
80 saturation.process<
true> (left_in, right_in, left_out, right_out, n_frames);
83 render (
uint n_frames)
override
85 float *left_in =
const_cast<float*
> (ifloats (stereoin, 0));
86 float *right_in =
const_cast<float*
> (ifloats (stereoin, 1));
87 float *left_out = oblock (stereout, 0);
88 float *right_out = oblock (stereout, 1);
91 MidiEventInput evinput = midi_event_input();
92 for (
const auto &ev : evinput)
95 render_audio (left_in + offset, right_in + offset, left_out + offset, right_out + offset, ev.frame - offset);
100 case MidiMessage::PARAM_VALUE:
102 adjust_param (ev.param);
108 render_audio (left_in + offset, right_in + offset, left_out + offset, right_out + offset, n_frames - offset);
111static auto saturation = register_audio_processor<Saturation> (
"Ase::Devices::Saturation");
#define _(...)
Retrieve the translation of a C or C++ string.
The Anklang C++ API namespace.
uint64_t uint64
A 64-bit unsigned integer, use PRI*64 in format strings.
SpeakerArrangement
Flags to indicate channel arrangements of a bus.
std::string String
Convenience alias for std::string.
uint32_t uint
Provide 'uint' as convenience type.
Structured initializer for Parameter.
Parameter list construction helper.
String group
Group to be applied to all newly inserted Parameter objects.