Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
value_source.hpp
Go to the documentation of this file.
1#pragma once
2#include <atomic>
3#include <cstdint>
4
13
14#include <array>
15#include <cstddef>
16#include <type_traits>
17
19
20namespace pulp::dataplane {
21
22class ValueChannelSet;
23
24namespace detail {
25class ScalarTelemetryState;
26class MeterTelemetryState;
27class VectorTelemetryState;
28class EventTelemetryState;
29
30template <typename T> struct PublishedValue {
31 T value{};
32 std::uint64_t publication = 0;
33};
34} // namespace detail
35
39struct MeterFrame {
40 static constexpr int kMaxChannels = 8;
41 std::array<float, kMaxChannels> rms{};
42 std::array<float, kMaxChannels> peak{};
47 int channels = 0;
48};
49
50static_assert(std::is_trivially_copyable_v<MeterFrame>);
51
61 public:
64 void note_publish() noexcept {
65 publish_seq_.fetch_add(1, std::memory_order_relaxed);
66 }
67
69 std::uint32_t publish_seq() const noexcept {
70 return publish_seq_.load(std::memory_order_relaxed);
71 }
72
73 private:
74 std::atomic<std::uint32_t> publish_seq_{0};
75};
76
81 public:
83
86 void publish(const MeterFrame& frame);
87
91
92 private:
93 friend class ValueChannelSet;
95 detail::MeterTelemetryState* telemetry_ = nullptr;
96 std::uint64_t writer_publication_ = 0;
97};
98
109 static constexpr int kMaxSamples = 4096;
110 std::array<float, kMaxSamples> samples{};
114 int count = 0;
115};
116
117static_assert(std::is_trivially_copyable_v<VectorFrame>);
118
124 std::uint32_t frame_index = 0;
125 float value = 0.0f;
126};
127
128static_assert(std::is_trivially_copyable_v<ValueEvent>);
129
136 static constexpr int kMaxEvents = 1024;
137 std::array<ValueEvent, kMaxEvents> events{};
138 int count = 0;
142 std::uint32_t publication = 0;
143};
144
145static_assert(std::is_trivially_copyable_v<EventFrame>);
146
155 public:
157
162 void publish(const float* samples, int count);
163
166
167 private:
168 friend class ValueChannelSet;
170 detail::VectorTelemetryState* telemetry_ = nullptr;
171 std::uint64_t writer_publication_ = 0;
172};
173
180 public:
182
185 void publish(const ValueEvent* events, int count);
186
189
190 private:
191 friend class ValueChannelSet;
193 detail::EventTelemetryState* telemetry_ = nullptr;
194 // Single-writer state: only publish() touches this counter.
195 std::uint64_t writer_publication_ = 0;
196};
197
202 public:
204
206 void publish(float value);
207
209 float read();
210
211 private:
212 friend class ValueChannelSet;
214 detail::ScalarTelemetryState* telemetry_ = nullptr;
215 std::uint64_t writer_publication_ = 0;
216};
217
218} // namespace pulp::dataplane
Lock-free event channel: the writer publishes the occurrences from one audio block and the view reads...
Definition value_source.hpp:179
friend class ValueChannelSet
Definition value_source.hpp:191
EventFrame read()
Read the latest completed block from the reader thread.
void publish(const ValueEvent *events, int count)
Publish a block's occurrences from the writer thread.
Lock-free meter channel: the host publishes a MeterFrame from the audio/host thread; the view reads t...
Definition value_source.hpp:80
void publish(const MeterFrame &frame)
Publish the latest reading.
friend class ValueChannelSet
Definition value_source.hpp:93
MeterFrame read()
Read the latest published reading.
Monotonic publish counter, shared by every value source.
Definition value_source.hpp:60
std::uint32_t publish_seq() const noexcept
Reader (UI) thread. Changes iff the writer published since the last read.
Definition value_source.hpp:69
void note_publish() noexcept
Writer (audio/host) thread, from publish().
Definition value_source.hpp:64
Lock-free scalar channel: a single paint-safe cached number (a readout value, a modulation ring's bas...
Definition value_source.hpp:201
friend class ValueChannelSet
Definition value_source.hpp:212
void publish(float value)
Publish the latest value from the writer (audio/host) thread.
float read()
Read the latest value from the reader (UI) thread.
A processor's declared channels.
Definition value_channel_set.hpp:61
Lock-free vector channel: the writer publishes a block of samples, the view reads the latest block pa...
Definition value_source.hpp:154
void publish(const float *samples, int count)
Publish a block from the writer (audio/host) thread.
friend class ValueChannelSet
Definition value_source.hpp:168
VectorFrame read()
Read the latest published block from the reader (UI) thread.
Lock-free triple buffer for publishing the latest value from a writer thread to a reader thread witho...
Definition triple_buffer.hpp:45
Definition value_channel_telemetry.hpp:74
Definition audio_bridge.hpp:9
Definition child_process_manager.hpp:18
A bounded list of occurrences from one audio block.
Definition value_source.hpp:135
std::uint32_t publication
Source-owned generation used by a reader to identify this exact block.
Definition value_source.hpp:142
std::array< ValueEvent, kMaxEvents > events
Definition value_source.hpp:137
static constexpr int kMaxEvents
Definition value_source.hpp:136
int count
Definition value_source.hpp:138
A single multi-channel meter reading.
Definition value_source.hpp:39
std::array< float, kMaxChannels > rms
Definition value_source.hpp:41
std::array< float, kMaxChannels > peak
Definition value_source.hpp:42
int channels
Number of valid channels in rms/peak.
Definition value_source.hpp:47
static constexpr int kMaxChannels
Definition value_source.hpp:40
One occurrence inside an audio block.
Definition value_source.hpp:123
std::uint32_t frame_index
Definition value_source.hpp:124
float value
Definition value_source.hpp:125
A block of samples for a scope-style display — an envelope curve, a detector's output,...
Definition value_source.hpp:108
int count
Valid samples in samples.
Definition value_source.hpp:114
std::array< float, kMaxSamples > samples
Definition value_source.hpp:110
static constexpr int kMaxSamples
Definition value_source.hpp:109
Definition value_source.hpp:30
std::uint64_t publication
Definition value_source.hpp:32
T value
Definition value_source.hpp:31
Lock-free latest-value publication between two threads.