-
Notifications
You must be signed in to change notification settings - Fork 0
/
RNNoise.cpp
66 lines (55 loc) · 1.77 KB
/
RNNoise.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "RNNoise.h"
#include "IPlug_include_in_plug_src.h"
RNNoise::RNNoise(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo)
{
GetParam(kNoiseFloor)->InitDouble("Noise Floor", 0.2, 0., 1., 0.01, ""); // TODO: default
sts = rnnoise_create(nullptr);
MakeDefaultPreset();
}
RNNoise::~RNNoise()
{
if(sts)
rnnoise_destroy(sts);
}
#if IPLUG_DSP
void RNNoise::OnReset()
{
if(mPreviousSR != GetSampleRate())
{
mPreviousSR = GetSampleRate();
if(sts)
rnnoise_destroy(sts);
sts = rnnoise_create(nullptr);
rnnoise_set_param(sts, RNNOISE_PARAM_MAX_ATTENUATION, GetParam(kNoiseFloor)->Value()); // TODO: DB mapping correct?
rnnoise_set_param(sts, RNNOISE_PARAM_SAMPLE_RATE, GetSampleRate());
}
}
void RNNoise::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
{
for (int s = 0; s < nFrames; s++) {
// Input is in floatingpoint -1.0 to 1.0 range. Rnnoise uses float, but expects
// int16_t's range [-32768, 32767] so convert.
ibuffer[frameCount++] = ((inputs[0][s] + inputs[1][s]) / 2.f) * 32768;
if(frameCount == kNumFrames) {
rnnoise_process_frame(sts, &obuffer[outFrameCount], ibuffer);
outFrameCount += frameCount;
frameCount = 0;
}
}
int framesToOutput = std::min(nFrames, outFrameCount);
for (int s = 0; s < framesToOutput; s++) {
outputs[0][s] = outputs[1][s] = obuffer[s] / 32768;
}
int left = outFrameCount - framesToOutput;
if (left > 0) {
memmove(obuffer, obuffer + framesToOutput, left * sizeof(obuffer[0]));
}
outFrameCount -= framesToOutput;
}
void RNNoise::OnParamChange(int paramIdx)
{
if(sts)
rnnoise_set_param(sts, RNNOISE_PARAM_MAX_ATTENUATION, GetParam(kNoiseFloor)->Value()); // TODO: DB mapping correct?
}
#endif