Skip to content
This repository was archived by the owner on Nov 8, 2025. It is now read-only.
/ Re-Nooice Public archive

Commit 558f1cc

Browse files
committed
Code comments
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 7583dbd commit 558f1cc

File tree

1 file changed

+57
-10
lines changed

1 file changed

+57
-10
lines changed

src/PluginDSP.cpp

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,41 @@ START_NAMESPACE_DISTRHO
1616

1717
class ReNooicePlugin : public Plugin
1818
{
19+
// scaling used for denoise processing
1920
static constexpr const uint32_t kDenoiseScaling = std::numeric_limits<short>::max();
2021
static constexpr const float kDenoiseScalingInv = 1.f / kDenoiseScaling;
2122

23+
// denoise block size
2224
const uint32_t denoiseFrameSize = static_cast<uint32_t>(rnnoise_get_frame_size());
2325
const uint32_t denoiseFrameSizeF = denoiseFrameSize * sizeof(float);
2426

27+
// denoise handle, keep it const so we never modify it
2528
DenoiseState* const denoise = rnnoise_create(nullptr);
2629

30+
// buffers for latent processing
2731
float* bufferIn;
2832
float* bufferOut;
29-
3033
HeapRingBuffer ringBufferDry;
3134
HeapRingBuffer ringBufferOut;
35+
uint32_t bufferInPos;
36+
37+
// whether we received enough latent audio frames
38+
bool processing;
3239

40+
// translate Grace Period param (ms) into 48kHz frames
41+
// updated when param changes
3342
uint32_t gracePeriodInFrames = 0;
34-
uint32_t numFramesUntilGracePeriodOver = 0;
3543

36-
uint32_t bufferInPos;
37-
bool processing;
44+
// assigned to gracePeriodInFrames when going mute
45+
uint32_t numFramesUntilGracePeriodOver = 0;
3846

3947
// smooth bypass
4048
LinearValueSmoother dryValue;
4149

4250
// smooth mute/unmute
4351
LinearValueSmoother muteValue;
4452

53+
// our parameter list
4554
enum Parameters {
4655
kParamBypass,
4756
kParamThreshold,
@@ -55,6 +64,8 @@ class ReNooicePlugin : public Plugin
5564
};
5665
float parameters[kParamCount] = {};
5766

67+
// denoise statistics
68+
// mostly just for testing
5869
struct {
5970
float vads[128];
6071
float avg, min, max;
@@ -123,6 +134,9 @@ class ReNooicePlugin : public Plugin
123134
sampleRateChanged(getSampleRate());
124135
}
125136

137+
/**
138+
Destructor.
139+
*/
126140
~ReNooicePlugin()
127141
{
128142
rnnoise_destroy(denoise);
@@ -133,7 +147,7 @@ class ReNooicePlugin : public Plugin
133147
// Information
134148

135149
/**
136-
Get the plugin label.@n
150+
Get the plugin label.
137151
This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
138152
*/
139153
const char* getLabel() const noexcept override
@@ -150,7 +164,7 @@ class ReNooicePlugin : public Plugin
150164
}
151165

152166
/**
153-
Get the plugin license (a single line of text or a URL).@n
167+
Get the plugin license (a single line of text or a URL).
154168
For commercial plugins this should return some short copyright information.
155169
*/
156170
const char* getLicense() const noexcept override
@@ -160,7 +174,6 @@ class ReNooicePlugin : public Plugin
160174

161175
/**
162176
Get the plugin version, in hexadecimal.
163-
@see d_version()
164177
*/
165178
uint32_t getVersion() const noexcept override
166179
{
@@ -170,13 +183,21 @@ class ReNooicePlugin : public Plugin
170183
// ----------------------------------------------------------------------------------------------------------------
171184
// Init
172185

186+
/**
187+
Initialize the audio port @a index.
188+
This function will be called once, shortly after the plugin is created.
189+
*/
173190
void initAudioPort(bool input, uint32_t index, AudioPort& port) override
174191
{
175192
port.groupId = kPortGroupMono;
176193

177194
Plugin::initAudioPort(input, index, port);
178195
}
179196

197+
/**
198+
Initialize the parameter @a index.
199+
This function will be called once, shortly after the plugin is created.
200+
*/
180201
void initParameter(uint32_t index, Parameter& parameter) override
181202
{
182203
parameter.hints = kParameterIsAutomatable;
@@ -251,11 +272,21 @@ class ReNooicePlugin : public Plugin
251272
}
252273
}
253274

275+
/**
276+
Get the current value of a parameter.
277+
The host may call this function from any context, including realtime processing.
278+
*/
254279
float getParameterValue(uint32_t index) const override
255280
{
256281
return parameters[index];
257282
}
258283

284+
/**
285+
Change a parameter value.
286+
The host may call this function from any context, including realtime processing.
287+
When a parameter is marked as automatable, you must ensure no non-realtime operations are performed.
288+
@note This function will only be called for parameter inputs.
289+
*/
259290
void setParameterValue(uint32_t index, float value) override
260291
{
261292
parameters[index] = value;
@@ -266,7 +297,7 @@ class ReNooicePlugin : public Plugin
266297
dryValue.setTargetValue(value);
267298
break;
268299
case kParamGracePeriod:
269-
// 48 is 1ms (48000 kHz [1s] / 1000)
300+
// 48 frames = 1ms (48000 kHz [1s] / 1000)
270301
gracePeriodInFrames = d_roundToUnsignedInt(value * 48.f);
271302
break;
272303
}
@@ -275,6 +306,9 @@ class ReNooicePlugin : public Plugin
275306
// ----------------------------------------------------------------------------------------------------------------
276307
// Audio/MIDI Processing
277308

309+
/**
310+
Activate this plugin.
311+
*/
278312
void activate() override
279313
{
280314
const uint32_t ringBufferSize = denoiseFrameSizeF * 2;
@@ -283,6 +317,8 @@ class ReNooicePlugin : public Plugin
283317

284318
bufferIn = new float[denoiseFrameSize];
285319
bufferOut = new float[denoiseFrameSize];
320+
bufferInPos = 0;
321+
processing = false;
286322

287323
parameters[kParamCurrentVAD] = 0.f;
288324
parameters[kParamAverageVAD] = 0.f;
@@ -294,11 +330,12 @@ class ReNooicePlugin : public Plugin
294330
muteValue.setTargetValue(0.f);
295331
muteValue.clearToTargetValue();
296332

297-
processing = false;
298-
bufferInPos = 0;
299333
stats.reset();
300334
}
301335

336+
/**
337+
Deactivate this plugin.
338+
*/
302339
void deactivate() override
303340
{
304341
delete[] bufferIn;
@@ -446,6 +483,10 @@ class ReNooicePlugin : public Plugin
446483
}
447484
}
448485

486+
/**
487+
Optional callback to inform the plugin about a sample rate change.
488+
This function will only be called when the plugin is deactivated.
489+
*/
449490
void sampleRateChanged(const double sampleRate) override
450491
{
451492
dryValue.setSampleRate(sampleRate);
@@ -460,6 +501,12 @@ class ReNooicePlugin : public Plugin
460501

461502
// --------------------------------------------------------------------------------------------------------------------
462503

504+
/**
505+
Create an instance of the Plugin class.
506+
This is the entry point for DPF plugins.
507+
DPF will call this to either create an instance of your plugin for the host
508+
or to fetch some initial information for internal caching.
509+
*/
463510
Plugin* createPlugin()
464511
{
465512
return new ReNooicePlugin();

0 commit comments

Comments
 (0)