Skip to content

Commit 8630d61

Browse files
Complete minimal saturator skeleton.
1 parent c225ba3 commit 8630d61

3 files changed

Lines changed: 117 additions & 36 deletions

File tree

include/private/plugins/saturator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ namespace lsp
3939
class saturator: public plug::Module
4040
{
4141
protected:
42-
4342
// Same as Graph Equalizer
4443
typedef struct eq_band_t
4544
{

src/main/meta/saturator.cpp

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,34 +140,36 @@ namespace lsp
140140
{ NULL, NULL }
141141
};
142142

143+
#define SATURATOR_CONTROLS(id, label, alias) \
144+
COMBO("ov" id, "Oversampler Mode" label, "Oversampler Mode" alias, saturator::SAT_OVS_DFL, sat_oversampler_mode), \
145+
AMP_GAIN_RANGE("ge" id, "Pre gain" label, "Pre gain" alias, saturator::PRE_GAIN_DFL, saturator::PRE_GAIN_MIN, saturator::PRE_GAIN_MAX), \
146+
AMP_GAIN_RANGE("gt" id, "Post gain" label, "Post gain" alias, saturator::POST_GAIN_DFL, saturator::POST_GAIN_MIN, saturator::POST_GAIN_MAX), \
147+
CONTROL("sl" id, "Slope" label, "Slope" alias, U_NONE, saturator::SLOPE), \
148+
CONTROL("sh" id, "Shape" label, "Shape" alias, U_NONE, saturator::SHAPE), \
149+
CONTROL("hl" id, "High Level" label, "High Level" alias, U_NONE, saturator::HIGH_LEVEL), \
150+
CONTROL("ll" id, "Low Level" label, "Low Level" alias, U_NONE, saturator::LOW_LEVEL), \
151+
CONTROL("rd" id, "Radius" label, "Radius" alias, U_NONE, saturator::RADIUS), \
152+
CONTROL("lv" id, "Levels" label, "Levels" alias, U_NONE, saturator::LEVELS), \
153+
CONTROL("cp" id, "Continuous Companding" label, "Continuous Companding" alias, U_NONE, saturator::C_COMPANDING), \
154+
CONTROL("qp" id, "Quantized Companding" label, "Quantized Companding" alias, U_NONE, saturator::Q_COMPANDING), \
155+
CONTROL("bs" id, "Bias" label, "Bias" alias, U_NONE, saturator::BIAS), \
156+
CONTROL("bl" id, "Blend" label, "Blend" alias, U_NONE, saturator::BLEND), \
157+
COMBO("sp" id, "Shaping Function" label, "Shaping Function" alias, saturator::SAT_SH_FCN_DEFAULT, sat_shaping_fcn)
158+
159+
#define SATURATOR_CONTROLS_MONO SATURATOR_CONTROLS("", "", "")
160+
#define SATURATOR_CONTROLS_STEREO SATURATOR_CONTROLS("", "", "")
161+
#define SATURATOR_CONTROLS_LR SATURATOR_CONTROLS("l", " Left", " L"), SATURATOR_CONTROLS("r", " Right", " R")
162+
143163
#define EQ_BAND(id, label, alias, x, f) \
144164
SWITCH("xs" id "_" #x, "Band solo" label " " f, "Solo " f alias, 0.0f), \
145165
SWITCH("xm" id "_" #x, "Band mute" label " " f, "Mute " f alias, 0.0f), \
146166
SWITCH("xe" id "_" #x, "Band on" label " " f, "On " f alias, 1.0f), \
147-
BLINK("fv" id "_" #x, "Filter visibility " label " " f), \
148167
LOG_CONTROL("g" id "_" #x, "Band gain" label " " f, "Gain " f alias, U_GAIN_AMP, saturator::BAND_GAIN)
149168

150169
#define EQ_BAND_MONO(x, f) EQ_BAND("", "", "", x, f)
151170
#define EQ_BAND_STEREO(x, f) EQ_BAND("", "", "", x, f)
152171
#define EQ_BAND_LR(x, f) EQ_BAND("l", " Left", " L", x, f), EQ_BAND("r", " Right", " R", x, f)
153172

154-
#define SATURATOR_COMMON \
155-
BYPASS, \
156-
COMBO("scom", "Oversampler Mode", "Oversample", saturator::SAT_OVS_DFL, sat_oversampler_mode), \
157-
AMP_GAIN_RANGE("g_pre", "Pre gain", "Pre gain", saturator::PRE_GAIN_DFL, saturator::PRE_GAIN_MIN, saturator::PRE_GAIN_MAX), \
158-
AMP_GAIN_RANGE("g_pst", "Post gain", "Ppost gain", saturator::POST_GAIN_DFL, saturator::POST_GAIN_MIN, saturator::POST_GAIN_MAX), \
159-
CONTROL("slp", "Slope", "Slope", U_NONE, saturator::SLOPE), \
160-
CONTROL("shp", "Shape", "Shape", U_NONE, saturator::SHAPE), \
161-
CONTROL("hlv", "High Level", "High Level", U_NONE, saturator::HIGH_LEVEL), \
162-
CONTROL("llv", "Low Level", "Low Level", U_NONE, saturator::LOW_LEVEL), \
163-
CONTROL("rdr", "Radius", "Radius", U_NONE, saturator::RADIUS), \
164-
CONTROL("lvl", "Levels", "Levels", U_NONE, saturator::LEVELS), \
165-
CONTROL("cmp", "Continuous Companding", "Continuous Companding", U_NONE, saturator::C_COMPANDING), \
166-
CONTROL("qmp", "Quantized Companding", "Quantized Companding", U_NONE, saturator::Q_COMPANDING), \
167-
CONTROL("bs", "Bias", "Bias", U_NONE, saturator::BIAS), \
168-
CONTROL("bld", "Blend", "Blend", U_NONE, saturator::BLEND), \
169-
COMBO("shp", "Shaping Function", "Shaping Function", saturator::SAT_SH_FCN_DEFAULT, sat_shaping_fcn)
170-
171173
#define EQ_BANDS_3X(band) \
172174
band(0, "125"), \
173175
band(1, "1K"), \
@@ -245,7 +247,8 @@ namespace lsp
245247

246248
// Input controls
247249
BYPASS,
248-
SATURATOR_COMMON,
250+
SATURATOR_CONTROLS_MONO,
251+
EQ_BANDS_3X(EQ_BAND_MONO),
249252
EQ_BANDS_3X(EQ_BAND_MONO),
250253
OPT_STRING("comment", "Comment", 128),
251254

@@ -262,7 +265,8 @@ namespace lsp
262265

263266
// Input controls
264267
BYPASS,
265-
SATURATOR_COMMON,
268+
SATURATOR_CONTROLS_STEREO,
269+
EQ_BANDS_3X(EQ_BAND_STEREO),
266270
EQ_BANDS_3X(EQ_BAND_STEREO),
267271
OPT_STRING("comment", "Comment", 128),
268272

@@ -279,7 +283,8 @@ namespace lsp
279283

280284
// Input controls
281285
BYPASS,
282-
SATURATOR_COMMON,
286+
SATURATOR_CONTROLS_MONO,
287+
EQ_BANDS_8X(EQ_BAND_MONO),
283288
EQ_BANDS_8X(EQ_BAND_MONO),
284289
OPT_STRING("comment", "Comment", 128),
285290

@@ -296,7 +301,8 @@ namespace lsp
296301

297302
// Input controls
298303
BYPASS,
299-
SATURATOR_COMMON,
304+
SATURATOR_CONTROLS_STEREO,
305+
EQ_BANDS_8X(EQ_BAND_STEREO),
300306
EQ_BANDS_8X(EQ_BAND_STEREO),
301307
OPT_STRING("comment", "Comment", 128),
302308

@@ -313,7 +319,8 @@ namespace lsp
313319

314320
// Input controls
315321
BYPASS,
316-
SATURATOR_COMMON,
322+
SATURATOR_CONTROLS_MONO,
323+
EQ_BANDS_16X(EQ_BAND_MONO),
317324
EQ_BANDS_16X(EQ_BAND_MONO),
318325
OPT_STRING("comment", "Comment", 128),
319326

@@ -330,7 +337,8 @@ namespace lsp
330337

331338
// Input controls
332339
BYPASS,
333-
SATURATOR_COMMON,
340+
SATURATOR_CONTROLS_STEREO,
341+
EQ_BANDS_16X(EQ_BAND_STEREO),
334342
EQ_BANDS_16X(EQ_BAND_STEREO),
335343
OPT_STRING("comment", "Comment", 128),
336344

@@ -347,7 +355,8 @@ namespace lsp
347355

348356
// Input controls
349357
BYPASS,
350-
SATURATOR_COMMON,
358+
SATURATOR_CONTROLS_MONO,
359+
EQ_BANDS_32X(EQ_BAND_MONO),
351360
EQ_BANDS_32X(EQ_BAND_MONO),
352361
OPT_STRING("comment", "Comment", 128),
353362

@@ -364,7 +373,8 @@ namespace lsp
364373

365374
// Input controls
366375
BYPASS,
367-
SATURATOR_COMMON,
376+
SATURATOR_CONTROLS_STEREO,
377+
EQ_BANDS_32X(EQ_BAND_STEREO),
368378
EQ_BANDS_32X(EQ_BAND_STEREO),
369379
OPT_STRING("comment", "Comment", 128),
370380

src/main/plug/saturator.cpp

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,33 @@ namespace lsp
5151
&meta::saturator_x32_stereo,
5252
};
5353

54+
typedef struct plugin_settings_t
55+
{
56+
const meta::plugin_t *metadata;
57+
uint8_t bands;
58+
} plugin_settings_t;
59+
60+
static const plugin_settings_t plugin_settings[] =
61+
{
62+
{&meta::saturator_x3_mono, 3 },
63+
{&meta::saturator_x3_stereo, 3 },
64+
{&meta::saturator_x8_mono, 8 },
65+
{&meta::saturator_x8_stereo, 8 },
66+
{&meta::saturator_x16_mono, 16 },
67+
{&meta::saturator_x16_stereo, 16 },
68+
{&meta::saturator_x32_mono, 32 },
69+
{&meta::saturator_x32_stereo, 32 },
70+
71+
{ NULL, 0 }
72+
};
73+
5474
static plug::Module *plugin_factory(const meta::plugin_t *meta)
5575
{
56-
return new saturator(meta);
76+
for (const plugin_settings_t *s = plugin_settings; s->metadata != NULL; ++s)
77+
if (s->metadata == meta)
78+
return new saturator(s->metadata, s->bands);
79+
80+
return NULL;
5781
}
5882

5983
static plug::Factory factory(plugin_factory, plugins, 2);
@@ -71,7 +95,7 @@ namespace lsp
7195

7296
// Initialize other parameters
7397
nSampleRate = 0;
74-
nBands = bands;
98+
nBands = bands;
7599
vChannels = NULL;
76100
vBuffer = NULL;
77101

@@ -134,26 +158,44 @@ namespace lsp
134158
size_t port_id = 0;
135159

136160
// Bind input audio ports
161+
lsp_trace("Binding input audio ports");
137162
for (size_t i=0; i<nChannels; ++i)
138163
BIND_PORT(vChannels[i].pIn);
139164

140165
// Bind output audio ports
166+
lsp_trace("Binding output audio ports");
141167
for (size_t i=0; i<nChannels; ++i)
142168
BIND_PORT(vChannels[i].pOut);
143169

144-
// Bind bypass
170+
// Bind common ports
171+
lsp_trace("Binding common ports");
145172
BIND_PORT(pBypass);
146173

147-
// Bind ports for audio processing channels
174+
// Bind saturator control ports
175+
lsp_trace("Binding saturator control ports");
148176
for (size_t i=0; i<nChannels; ++i)
149177
{
150178
channel_t *c = &vChannels[i];
151179

152-
BIND_PORT();
180+
BIND_PORT(c->sOversamplerParams.pMode);
181+
BIND_PORT(c->sShaperParams.pPreGain);
182+
BIND_PORT(c->sShaperParams.pPostGain);
183+
BIND_PORT(c->sShaperParams.pSlope);
184+
BIND_PORT(c->sShaperParams.pShape);
185+
BIND_PORT(c->sShaperParams.pHighLevel);
186+
BIND_PORT(c->sShaperParams.pLowLevel);
187+
BIND_PORT(c->sShaperParams.pRadius);
188+
BIND_PORT(c->sShaperParams.pLevels);
189+
BIND_PORT(c->sShaperParams.pCCompanding);
190+
BIND_PORT(c->sShaperParams.pQCompanding);
191+
BIND_PORT(c->sShaperParams.pBias);
192+
BIND_PORT(c->sShaperParams.pDrive);
193+
BIND_PORT(c->sShaperParams.pBlend);
194+
BIND_PORT(c->sShaperParams.pShapingFcn);
153195

154196
if (i > 0)
155197
{
156-
channel_t *pc = &vChannels[0];
198+
//channel_t *pc = &vChannels[0];
157199

158200
// TODO: Ports shared between channels go here
159201
}
@@ -163,17 +205,47 @@ namespace lsp
163205
}
164206
}
165207

208+
// Bind Pre-EQ ports
209+
lsp_trace("Binding pre-eq filter ports");
210+
for (size_t i=0; i<nBands; ++i)
211+
{
212+
for (size_t j=0; j<nChannels; ++j)
213+
{
214+
eq_band_t *b = &vChannels[j].vPreEQBands[i];
215+
216+
BIND_PORT(b->pSolo);
217+
BIND_PORT(b->pMute);
218+
BIND_PORT(b->pEnable);
219+
BIND_PORT(b->pGain);
220+
}
221+
}
222+
223+
// Bind Pre-EQ ports
224+
lsp_trace("Binding post-eq filter ports");
225+
for (size_t i=0; i<nBands; ++i)
226+
{
227+
for (size_t j=0; j<nChannels; ++j)
228+
{
229+
eq_band_t *b = &vChannels[j].vPostEQBands[i];
230+
231+
BIND_PORT(b->pSolo);
232+
BIND_PORT(b->pMute);
233+
BIND_PORT(b->pEnable);
234+
BIND_PORT(b->pGain);
235+
}
236+
}
237+
166238
// TODO: Bind output ports.
167239
BIND_PORT(pComment);
168240

169-
// Bind output meters
241+
// TODO: Bind output ports
170242
for (size_t i=0; i<nChannels; ++i)
171243
{
172-
channel_t *c = &vChannels[i];
244+
//channel_t *c = &vChannels[i];
173245

174246
if (i > 0)
175247
{
176-
channel_t *pc = &vChannels[0];
248+
//channel_t *pc = &vChannels[0];
177249
// TODO: Output ports shared between channels go here
178250
}
179251
else

0 commit comments

Comments
 (0)