MCPcopy Create free account
hub / github.com/LabSound/LabSound / _precalc

Method _precalc

src/extended/DiodeNode.cpp:58–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58void DiodeNode::_precalc()
59{
60 // The non-linear waveshaper curve describes the transformation between an input signal and an output signal.
61 // Calculate a 1024-point curve following equation (2) from Parker's paper.
62
63 float h = _distortion->valueFloat();
64
65 const int samples = 1024;
66
67 std::vector<float> wsCurve;
68 wsCurve.resize(samples);
69
70 float vb_ = _vb->valueFloat();
71 float vl_ = _vl->valueFloat();
72
73 float s = float(samples);
74 for (int i = 0; i < samples; ++i)
75 {
76 // convert the index to a voltage of range -1 to 1
77 float v = fabsf((float(i) - s / 2.0f) / (s / 2.0f));
78 if (v <= vb_)
79 v = 0;
80 else if ((vb_ < v) && (v <= vl_))
81 v = h * powf(v - vb_, 2.0f) / (2 * vl_ - 2.0f * vb_);
82 else
83 v = h * v - h * vl_ + (h * ((powf(vl_ - vb_, 2.0f)) / (2.0f * vl_ - 2.0f * vb_)));
84 wsCurve[i] = v;
85 }
86
87 setCurve(wsCurve);
88}
89
90} // lab

Callers 1

DiodeNodeMethod · 0.95

Calls 2

valueFloatMethod · 0.80
resizeMethod · 0.80

Tested by

no test coverage detected