Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
param_processing.hpp
Go to the documentation of this file.
1#pragma once
2
3// Processor-facing helpers for sample-accurate parameter work.
4//
5// Realtime contract: after callers provide the output/input views,
6// StateStore, and any ParameterEventQueue storage, for_each_subblock() and
7// ControlRateParamSmoother hot operations do not allocate. prepare() belongs
8// off the audio thread when sample-rate/configuration changes happen.
9
10#include <pulp/audio/buffer.hpp>
14#include <pulp/state/store.hpp>
15#include <cstddef>
16#include <span>
17#include <utility>
18
19namespace pulp::format {
20
23
24template <typename Fn>
28 state::ParamCursor& params,
29 Fn&& fn)
30{
31 const auto total = output.num_samples();
32 params.advance_to(0);
33 if (total == 0) return;
34
35 std::size_t start = 0;
36 const auto event_span = events ? events->events() : std::span<const state::ParameterEvent>{};
37
38 auto emit = [&](std::size_t block_start, std::size_t block_end) {
39 if (block_end <= block_start) return;
40 auto out_slice = output.slice(block_start, block_end - block_start);
41 auto in_slice = input.slice(block_start, block_end - block_start);
42 fn(out_slice, in_slice, params);
43 };
44
45 for (const auto& event : event_span) {
46 if (event.sample_offset <= 0) continue;
47 if (static_cast<std::size_t>(event.sample_offset) >= total) break;
48
49 const auto split = static_cast<std::size_t>(event.sample_offset);
50 if (split > start) {
51 emit(start, split);
52 }
53 params.advance_to(event.sample_offset);
54 start = split;
55 }
56
57 if (start < total) {
58 emit(start, total);
59 }
60}
61
62template <typename Fn>
65 const state::StateStore& store,
67 std::span<const state::ParamSnapshotEntry> initial_values,
68 Fn&& fn)
69{
70 state::ParamCursor params(store, events, initial_values);
71 for_each_subblock(output, input, events, params, std::forward<Fn>(fn));
72}
73
74template <typename Fn>
77 const state::StateStore& store,
79 Fn&& fn)
80{
81 for_each_subblock(output, input, store, events,
82 std::span<const state::ParamSnapshotEntry>{},
83 std::forward<Fn>(fn));
84}
85
87public:
88 void prepare(const state::ParamInfo& info,
89 double sample_rate,
90 float initial_value) {
91 ramp_seconds_ = info.smoothing_ramp_seconds > 0.0f
92 ? info.smoothing_ramp_seconds
93 : 0.0f;
94 smoothing_enabled_ = ramp_seconds_ > 0.0f && sample_rate > 0.0;
95 value_.set_immediate(initial_value);
96 if (smoothing_enabled_) {
97 value_.set_ramp_time(ramp_seconds_, static_cast<float>(sample_rate));
98 }
99 }
100
101 void reset(float value) { value_.set_immediate(value); }
102
103 void set_target(float value) {
104 if (smoothing_enabled_) {
105 value_.set_target(value);
106 } else {
107 value_.set_immediate(value);
108 }
109 }
110
111 float next() { return value_.next(); }
112 void skip(int samples) { value_.skip(samples); }
113 float current() const { return value_.current(); }
114 float target() const { return value_.target(); }
115 bool is_smoothing() const { return value_.is_smoothing(); }
116 bool smoothing_enabled() const { return smoothing_enabled_; }
117 float ramp_seconds() const { return ramp_seconds_; }
118
119private:
121 float ramp_seconds_ = 0.0f;
122 bool smoothing_enabled_ = false;
123};
124
125} // namespace pulp::format
Non-owning view over multi-channel audio sample data.
Definition buffer.hpp:30
std::size_t num_samples() const
Definition buffer.hpp:84
BufferView slice(std::size_t start, std::size_t length) const
Create a non-owning slice over this view.
Definition buffer.hpp:49
Definition param_processing.hpp:86
bool is_smoothing() const
Definition param_processing.hpp:115
void skip(int samples)
Definition param_processing.hpp:112
void set_target(float value)
Definition param_processing.hpp:103
bool smoothing_enabled() const
Definition param_processing.hpp:116
float next()
Definition param_processing.hpp:111
float current() const
Definition param_processing.hpp:113
void reset(float value)
Definition param_processing.hpp:101
float ramp_seconds() const
Definition param_processing.hpp:117
float target() const
Definition param_processing.hpp:114
void prepare(const state::ParamInfo &info, double sample_rate, float initial_value)
Definition param_processing.hpp:88
Linear smoothing for control-rate parameters.
Definition smoothed_value.hpp:24
Definition param_cursor.hpp:26
void advance_to(int32_t sample_offset)
Definition param_cursor.hpp:43
Definition parameter_event_queue.hpp:82
Centralized parameter storage with lock-free value access.
Definition store.hpp:164
Definition child_process_manager.hpp:18
What the product grants a device: the quota table indexed by capability tier and live thermal state.
Definition aax_editor.hpp:31
void for_each_subblock(audio::BufferView< float > &output, const audio::BufferView< const float > &input, const state::ParameterEventQueue *events, state::ParamCursor &params, Fn &&fn)
Definition param_processing.hpp:25
state::ParamCursor ParamCursor
Definition param_processing.hpp:21
state::ParamSnapshotEntry ParamSnapshotEntry
Definition param_processing.hpp:22
Immutable parameter metadata, registered once at plugin initialization.
Definition parameter.hpp:316
Definition param_cursor.hpp:21