Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
gpu_multi_convolver.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <cstdint>
5#include <memory>
6#include <string>
7#include <vector>
8
12
14
15namespace pulp::gpu_audio {
16
18
19namespace detail {
20// Test seam: prepare against a supplied compute device instead of a standalone
21// one. Not part of the SDK surface.
23 std::unique_ptr<render::GpuCompute>) noexcept;
24} // namespace detail
25
64public:
68 GpuMultiConvolver(uint32_t block_size, uint32_t sample_rate,
69 std::vector<std::vector<float>> irs);
71
73 bool prepare() override;
75 audio::BufferView<float>& output, uint32_t n) override;
78 uint32_t n) noexcept override;
79
81 bool gpu_available() const { return gpu_ != nullptr; }
85 bool device_lost() const noexcept;
87 std::string backend() const;
88
95 GpuAudioStatus status_snapshot() const noexcept override;
99 bool fenced() const noexcept;
100 uint32_t num_ir() const { return num_ir_; }
101 uint32_t fft_size() const { return fft_size_; }
102
107 const std::vector<float>& pan_l() const { return pan_l_; }
108 const std::vector<float>& pan_r() const { return pan_r_; }
109
115 void set_flow(float depth, float spread = 1.0f) noexcept {
116 flow_depth_.store(depth < 0.f ? 0.f : depth > 1.f ? 1.f : depth,
117 std::memory_order_relaxed);
118 flow_spread_.store(spread < 0.f ? 0.f : spread > 1.f ? 1.f : spread,
119 std::memory_order_relaxed);
120 }
121
126 bool convolve_stereo(const float* mono_in, float* out_l, float* out_r, uint32_t n);
127
128 private:
129 friend bool
131 std::unique_ptr<render::GpuCompute>) noexcept;
132 bool prepare_on(std::unique_ptr<render::GpuCompute> gpu);
133
134 uint32_t block_;
135 uint32_t sample_rate_;
136 std::vector<std::vector<float>> irs_;
137 uint32_t num_ir_ = 0;
138 uint32_t fft_size_ = 0;
139
140 std::unique_ptr<render::GpuCompute> gpu_;
141
142 // Per-room constant-power pan gains (linear), built at prepare().
143 std::vector<float> pan_l_;
144 std::vector<float> pan_r_;
145
146 // Per-block host scratch (allocated in prepare()).
147 std::vector<float> in_pad_; // 2*fft_size interleaved complex input
148 std::vector<float> out_lr_; // 2*fft_size: L block then R block (readback)
149 std::vector<float> carry_l_; // overlap-add accumulator, fft_size
150 std::vector<float> carry_r_;
151
152 // Flow (time-varying pans). flow_depth_/flow_spread_ are set from any thread
153 // (atomic); base_theta_ + pan_norm_ are the prepared static layout the drift
154 // orbits; block_counter_ advances on the transport worker (owns the phase).
155 std::atomic<float> flow_depth_{0.0f};
156 std::atomic<float> flow_spread_{1.0f};
157 std::vector<float> base_theta_; // per-room base azimuth, from prepare()
158 std::vector<float> pan_l_live_; // per-block drifting pans (Flow>0 only)
159 std::vector<float> pan_r_live_;
160 float pan_norm_ = 1.0f; // 1/sqrt(num_ir)
161 std::uint64_t block_counter_ = 0;
162
163 bool prepared_ = false;
164
165 // Blocks convolve_stereo() has been asked for since prepare(), and the one
166 // at which it first found the device lost (UINT64_MAX until then). Atomic
167 // because status readers report them from other threads.
168 std::atomic<std::uint64_t> blocks_seen_{0};
169 std::atomic<std::uint64_t> loss_block_{UINT64_MAX};
170};
171
172} // namespace pulp::gpu_audio
Non-owning view over multi-channel audio sample data.
Definition buffer.hpp:30
A unit of audio work the transport schedules onto a non-real-time worker.
Definition gpu_audio_node.hpp:92
Massive multi-IR ("multi-room") convolution: convolves one mono input against MANY distinct impulse r...
Definition gpu_multi_convolver.hpp:63
uint32_t fft_size() const
Definition gpu_multi_convolver.hpp:101
bool fenced() const noexcept
True before preparation or once the device was lost.
std::string backend() const
The live compute backend ("Metal"/"D3D12"/"Vulkan"), or "" if CPU-only.
GpuMultiConvolver(uint32_t block_size, uint32_t sample_rate, std::vector< std::vector< float > > irs)
irs is the bank of impulse responses (each a mono IR).
const std::vector< float > & pan_r() const
Definition gpu_multi_convolver.hpp:108
bool convolve_stereo(const float *mono_in, float *out_l, float *out_r, uint32_t n)
Convolve one mono input block against all rooms and write the panned stereo result (out_l / out_r,...
bool device_lost() const noexcept
True once the prepared device reports loss.
void set_flow(float depth, float spread=1.0f) noexcept
Flow: 0 = static field (bit-for-bit the pan_l()/pan_r() layout); >0 makes each room's pan drift per b...
Definition gpu_multi_convolver.hpp:115
bool gpu_available() const
True if the GPU compute device initialized and the multi-IR plan built.
Definition gpu_multi_convolver.hpp:81
void process_block(const audio::BufferView< const float > &input, audio::BufferView< float > &output, uint32_t n) override
Non-RT worker context. Process exactly one block (n == block_size).
GpuAudioNodeDescriptor descriptor() const override
GpuAudioStatus status_snapshot() const noexcept override
Allocation-free lifecycle projection, safe from a host or UI thread while a transport runs this node ...
uint32_t num_ir() const
Definition gpu_multi_convolver.hpp:100
const std::vector< float > & pan_l() const
Per-room constant-power pan gains (linear), available after prepare().
Definition gpu_multi_convolver.hpp:107
bool prepare() override
Non-RT. Allocate/compile/upload static data here.
void process_cpu_fallback(const audio::BufferView< const float > &input, audio::BufferView< float > &output, uint32_t n) noexcept override
RT-safe fallback.
GpuAudioRecoveryReason recovery_reason() const noexcept
First latched recovery cause, or None. Same snapshot as status_snapshot().
Definition gpu_audio_node.hpp:78
bool prepare_gpu_multi_convolver_with(GpuMultiConvolver &, std::unique_ptr< render::GpuCompute >) noexcept
Definition flow_pans.hpp:19
GpuAudioRecoveryReason
First latched reason that a node entered recovery.
Definition gpu_audio_status.hpp:40
STL namespace.
Declared, fixed scheduling properties of a GPU audio node.
Definition gpu_audio_node.hpp:44
Versioned, allocation-free status shared by native hosts and UI adapters.
Definition gpu_audio_status.hpp:80