| 37 | } |
| 38 | |
| 39 | class ADSRNode::ADSRNodeImpl : public lab::AudioProcessor |
| 40 | { |
| 41 | public: |
| 42 | float cached_sample_rate = 48000.f; // typical default |
| 43 | struct LerpTarget { float t, dvdt; }; |
| 44 | std:: deque<LerpTarget> _lerp; |
| 45 | |
| 46 | ADSRNodeImpl() : AudioProcessor() |
| 47 | { |
| 48 | envelope.reserve(AudioNode::ProcessingSizeInFrames * 4); |
| 49 | } |
| 50 | |
| 51 | virtual ~ADSRNodeImpl() {} |
| 52 | |
| 53 | virtual void initialize() override { } |
| 54 | virtual void uninitialize() override { } |
| 55 | |
| 56 | // Processes the source to destination bus. The number of channels must match in source and destination. |
| 57 | virtual void process(ContextRenderLock & r, const lab::AudioBus * sourceBus, lab::AudioBus* destinationBus, int framesToProcess) override |
| 58 | { |
| 59 | using std::deque; |
| 60 | |
| 61 | if (!destinationBus->numberOfChannels()) |
| 62 | return; |
| 63 | |
| 64 | if (!sourceBus->numberOfChannels()) |
| 65 | { |
| 66 | destinationBus->zero(); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | if (framesToProcess != _gateArray.size()) |
| 71 | _gateArray.resize(framesToProcess); |
| 72 | if (envelope.size() != framesToProcess) |
| 73 | envelope.resize(framesToProcess); |
| 74 | |
| 75 | // scan the gate signal |
| 76 | const bool gate_is_connected = m_gate->hasSampleAccurateValues(); |
| 77 | if (gate_is_connected) |
| 78 | { |
| 79 | m_gate->calculateSampleAccurateValues(r, _gateArray.data(), framesToProcess); |
| 80 | |
| 81 | // threshold the gate to on or off |
| 82 | for (int i = 0; i < framesToProcess; ++i) |
| 83 | _gateArray[i] = _gateArray[i] > 0 ? 1.f : 0.f; |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | float g = m_gate->value(); |
| 88 | // threshold the gate to on or off |
| 89 | for (int i = 0; i < framesToProcess; ++i) |
| 90 | _gateArray[i] = g > 0 ? 1.f : 0.f; |
| 91 | } |
| 92 | |
| 93 | // oneshot == false means gate controls Attack/Sustain |
| 94 | // oneshot == true means sustain param controls sustain |
| 95 | bool oneshot = m_oneShot->valueBool(); |
| 96 |
nothing calls this directly
no outgoing calls
no test coverage detected