Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
gpu_convolution_reverb.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <memory>
6#include <vector>
7
13
14namespace pulp::gpu_audio {
15
16namespace detail {
17struct GpuConvolutionReverbTestAccess;
18} // namespace detail
19
24 std::uint32_t block_size = 0;
25 std::uint32_t sample_rate = 0;
26 // The asset's native rate. This is intentionally distinct from the
27 // session rate above: Forge may prepare one immutable IR at several host
28 // rates, and ZeroLatencyConvolver owns the canonical resampling policy.
30 std::vector<std::vector<float>> impulse_response;
35 std::uint32_t ring_blocks = 8;
36 bool gpu_enabled = false;
37 // Optional shared-I/O diagnostics. Tracing remains off for a normal
38 // Forge node until this is enabled or the host has an active runtime
39 // tracing session. The callback path only publishes fixed-size records.
41};
42
50 // The lane transport's status_snapshot(), including its convolver's
51 // health. Appended so positional initialization of the fields above holds.
53};
54
56 bool prepared = false;
57 bool gpu_enabled = false;
59 std::uint32_t block_size = 0;
60 std::uint32_t latency_samples = 0;
61 std::array<GpuConvolutionReverbLaneReport, 2> lanes{};
62};
63
76 public:
79
82
85 bool prepare() noexcept;
86 void release() noexcept;
87
88 bool prepared() const noexcept {
89 return prepared_;
90 }
91 bool gpu_enabled() const noexcept {
92 return config_.gpu_enabled;
93 }
94 std::uint32_t block_size() const noexcept {
95 return config_.block_size;
96 }
97 std::uint32_t latency_samples() const noexcept {
98 return prepared_ ? 3u * config_.block_size : 0u;
99 }
100
101 // These setters are RT-safe and allocation-free. As with the CPU
102 // ZeroLatencyConvolver controls, callers change them at block boundaries.
103 void set_ir_gain_db(double db) noexcept;
104 void set_predelay_ms(double ms) noexcept;
105 void set_wet_percent(double percent) noexcept;
106 void set_dry_percent(double percent) noexcept;
107 void set_width_percent(double percent) noexcept;
108 void set_lowcut_hz(double hz) noexcept;
109 void set_highcut_hz(double hz) noexcept;
110
114 std::uint32_t n) noexcept;
115
117
126 bool fenced() const noexcept;
127
128 private:
129 struct Lane;
130 struct ControlSample {
131 double wet = 0.0;
132 double dry = 0.0;
133 double width = 1.0;
134 double ir_gain = 1.0;
135 std::uint32_t predelay = 0;
136 };
137
138 bool valid_config() const noexcept;
139 // Prepares each lane's convolver: the authenticated shared provider by
140 // default, or `prepare_node` when a private test seam supplies one.
141 using LaneNodePreparer = bool (*)(GpuConvolver&, void*) noexcept;
142 bool prepare_with(LaneNodePreparer prepare_node, void* context) noexcept;
143 bool prepare_lanes(LaneNodePreparer prepare_node, void* context) noexcept;
145 void update_filter_coefficients() noexcept;
146 void clear_runtime_buffers() noexcept;
147 void process_quantum() noexcept;
148
150 // Initialize after Lane is complete, in the out-of-line constructor.
151 std::array<std::unique_ptr<Lane>, 2> lanes_;
152 // The transports are fixed-quantum APIs. `block_size` is the host's
153 // prepared capacity, not a promise that every callback has that size;
154 // lane input buffers accumulate short callbacks into one full quantum.
155 std::vector<float> dry_delay_;
156 std::vector<ControlSample> control_delay_;
157 std::vector<float> predelay_ring_[2];
158 std::vector<float> dry_due_[2];
159 std::vector<ControlSample> control_due_;
160 std::vector<float> output_fifo_[2];
161 std::uint32_t predelay_capacity_ = 0;
162 std::uint32_t predelay_samples_ = 0;
163 std::uint32_t predelay_write_ = 0;
164 std::uint32_t dry_write_ = 0;
165 std::uint32_t quantum_fill_ = 0;
166 std::uint32_t output_fifo_capacity_ = 0;
167 std::uint32_t output_fifo_read_ = 0;
168 std::uint32_t output_fifo_write_ = 0;
169 std::uint32_t output_fifo_available_ = 0;
170 double ir_gain_db_ = signal::ZeroLatencyConvolver::kIrGainDbDefault;
171 double ir_gain_linear_ = 1.0;
172 double predelay_ms_ = signal::ZeroLatencyConvolver::kPredelayMsDefault;
173 double wet_gain_ = signal::ZeroLatencyConvolver::kWetPercentDefault / 100.0;
174 double dry_gain_ = signal::ZeroLatencyConvolver::kDryPercentDefault / 100.0;
175 double width_ = signal::ZeroLatencyConvolver::kWidthPercentDefault / 100.0;
176 double lowcut_hz_ = signal::ZeroLatencyConvolver::kLowcutHzDefault;
177 double highcut_hz_ = signal::ZeroLatencyConvolver::kHighcutHzDefault;
178 double hp_coef_ = 1.0;
179 double lp_coef_ = 1.0;
180 std::array<double, 2> hp_prev_x_{};
181 std::array<double, 2> hp_z_{};
182 std::array<double, 2> lp_z_{};
183 bool hp_active_ = false;
184 bool lp_active_ = false;
185 bool prepared_ = false;
186};
187
190
191} // namespace pulp::gpu_audio
Non-owning view over multi-channel audio sample data.
Definition buffer.hpp:30
Optional, control-parity GPU route for the two-channel Forge convolution reverb.
Definition gpu_convolution_reverb.hpp:75
void set_predelay_ms(double ms) noexcept
GpuConvolutionReverb(const GpuConvolutionReverb &)=delete
bool prepare() noexcept
Prepare the opt-in route.
void set_width_percent(double percent) noexcept
void set_dry_percent(double percent) noexcept
void process(const audio::BufferView< const float > &input, audio::BufferView< float > &output, std::uint32_t n) noexcept
Audio-thread entry point.
std::uint32_t latency_samples() const noexcept
Definition gpu_convolution_reverb.hpp:97
bool gpu_enabled() const noexcept
Definition gpu_convolution_reverb.hpp:91
GpuConvolutionReverbReport report() const noexcept
GpuConvolutionReverb & operator=(const GpuConvolutionReverb &)=delete
std::uint32_t block_size() const noexcept
Definition gpu_convolution_reverb.hpp:94
bool prepared() const noexcept
Definition gpu_convolution_reverb.hpp:88
void set_lowcut_hz(double hz) noexcept
GpuAudioStatus status_snapshot() const noexcept
Allocation-free status of the least healthy lane (lane 0 on a tie), because one fenced or lost lane a...
void set_wet_percent(double percent) noexcept
GpuConvolutionReverb(GpuConvolutionReverbConfig config)
void set_highcut_hz(double hz) noexcept
void set_ir_gain_db(double db) noexcept
GpuAudioRecoveryReason recovery_reason() const noexcept
First latched recovery cause of that lane, or None.
bool fenced() const noexcept
True before preparation, or when any lane's GPU delivery is fenced.
friend struct detail::GpuConvolutionReverbTestAccess
Definition gpu_convolution_reverb.hpp:144
First real GPU audio node: FFT-based (overlap-add) convolution of the input with a fixed impulse resp...
Definition gpu_convolver.hpp:117
Definition gpu_audio_node.hpp:78
Definition flow_pans.hpp:19
GpuConvolutionReverb GpuConvolutionReverbNode
Name used by host/catalog integrations that treat the route as a node.
Definition gpu_convolution_reverb.hpp:189
GpuAudioRecoveryReason
First latched reason that a node entered recovery.
Definition gpu_audio_status.hpp:40
Definition additive_bank.hpp:218
IrNormalizeMode
IR amplitude policy applied at load, after resampling and tail trim.
Definition zero_latency_convolver_support.hpp:157
@ energy
sum h^2 = 1 per output ear (default; convolution reverb).
Definition zero_latency_convolver_support.hpp:160
STL namespace.
Backend-neutral, allocation-free capability snapshot for installed SDK consumers.
Definition gpu_audio_capability.hpp:46
Versioned, allocation-free status shared by native hosts and UI adapters.
Definition gpu_audio_status.hpp:80
Selected output for prepared process() calls, not worker completions or GPU admissions.
Definition gpu_audio_transport.hpp:123
Definition gpu_audio_transport.hpp:94
Configuration for the opt-in GPU realization of Forge's stereo convolution reverb.
Definition gpu_convolution_reverb.hpp:23
std::vector< std::vector< float > > impulse_response
Definition gpu_convolution_reverb.hpp:30
signal::IrNormalizeMode normalize
Definition gpu_convolution_reverb.hpp:31
double tail_trim_db
Definition gpu_convolution_reverb.hpp:32
double impulse_response_sample_rate
Definition gpu_convolution_reverb.hpp:29
GpuConvolverTraceConfig trace
Definition gpu_convolution_reverb.hpp:40
std::uint32_t block_size
Definition gpu_convolution_reverb.hpp:24
std::uint32_t ring_blocks
Definition gpu_convolution_reverb.hpp:35
bool gpu_enabled
Definition gpu_convolution_reverb.hpp:36
std::uint32_t sample_rate
Definition gpu_convolution_reverb.hpp:25
double tail_fade_ms
Definition gpu_convolution_reverb.hpp:33
int resample_taps_per_phase
Definition gpu_convolution_reverb.hpp:34
Per-lane evidence.
Definition gpu_convolution_reverb.hpp:46
GpuAudioCapabilityReport capability
Definition gpu_convolution_reverb.hpp:47
GpuAudioTransport::DeliverySnapshot delivery
Definition gpu_convolution_reverb.hpp:49
GpuAudioTransport::Stats stats
Definition gpu_convolution_reverb.hpp:48
GpuAudioStatus status
Definition gpu_convolution_reverb.hpp:52
Definition gpu_convolution_reverb.hpp:55
bool prepared
Definition gpu_convolution_reverb.hpp:56
std::uint32_t block_size
Definition gpu_convolution_reverb.hpp:59
bool gpu_enabled
Definition gpu_convolution_reverb.hpp:57
std::uint32_t latency_samples
Definition gpu_convolution_reverb.hpp:60
std::array< GpuConvolutionReverbLaneReport, 2 > lanes
Definition gpu_convolution_reverb.hpp:61
bool authenticated_shared_provider
Definition gpu_convolution_reverb.hpp:58
Opt-in diagnostics for the shared-I/O path.
Definition gpu_convolver.hpp:24
static constexpr double kTailFadeMsDefault
Definition zero_latency_convolver_support.hpp:475
static constexpr double kTailTrimDbDefault
Definition zero_latency_convolver_support.hpp:469
static constexpr int kResampTapsPerPhaseDefault
Definition zero_latency_convolver_support.hpp:483
Runtime zero-latency convolver; scheduling support and design constants are provided by zero_latency_...