Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
published_sample_store.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <mutex>
6#include <vector>
7
10
11namespace pulp::audio {
12
14 // The store-level replacement path needs one currently published slot and
15 // one free slot for the next sample. Use SampleSlotBank directly for
16 // specialized one-slot/offline materialization workflows.
17 std::uint32_t slot_count = 0;
18 std::uint32_t max_channels = 0;
19 std::uint64_t max_frames_per_slot = 0;
20};
21
22// Reusable controller-side sample publication helper over SampleSlotBank.
23//
24// prepare() allocates fixed storage before audio starts. load_*() and publish()
25// may allocate/copy and take a mutex, so call them only from a controller,
26// importer, or background owner thread. Audio callbacks should only read
27// PublishedSampleView snapshots and generation-aware channel pointers.
29public:
31
33 void release() noexcept;
34
35 bool prepared() const noexcept { return storage_ready_; }
36 std::uint32_t slot_count() const noexcept { return slots_.slot_count(); }
37 std::uint32_t max_channels() const noexcept { return slots_.max_channels(); }
38 std::uint64_t max_frames_per_slot() const noexcept {
39 return slots_.max_frames_per_slot();
40 }
41
42 bool load_mono(const float* data,
43 int num_samples,
44 double sample_rate,
45 std::uint64_t audio_safe_generation = 0);
46 bool load_interleaved_stereo(const float* interleaved,
47 int num_frames,
48 double sample_rate,
49 std::uint64_t audio_safe_generation = 0);
51 std::uint64_t frames,
52 double sample_rate,
53 std::uint64_t audio_safe_generation = 0);
54
55 bool has_sample() const noexcept { return slots_.read_published_view().valid; }
56 int sample_length() const noexcept;
57
59 return slots_.read_published_view();
60 }
61 bool slot_view_valid(const PublishedSampleView& view) const noexcept {
62 return slots_.slot_view_valid(view);
63 }
65 std::uint32_t channel) const noexcept {
66 return slots_.channel_data(view, channel);
67 }
69 const float** channel_ptrs,
70 std::size_t channel_capacity) const noexcept;
71
72private:
73 bool config_valid(const PublishedSampleStoreConfig& config) const noexcept;
74 bool ensure_capacity(const PublishedSampleStoreConfig& config);
75 bool publish_locked(BufferView<const float> source,
76 std::uint64_t frames,
77 double sample_rate,
78 std::uint64_t audio_safe_generation);
79
80 SampleSlotBank slots_;
81 std::mutex load_mutex_;
82 std::vector<float> load_scratch_;
84 bool storage_ready_ = false;
85};
86
87} // namespace pulp::audio
Non-owning view over multi-channel audio sample data.
Definition buffer.hpp:30
bool prepared() const noexcept
Definition published_sample_store.hpp:35
int sample_length() const noexcept
bool load_mono(const float *data, int num_samples, double sample_rate, std::uint64_t audio_safe_generation=0)
const float * channel_data(const PublishedSampleView &view, std::uint32_t channel) const noexcept
Definition published_sample_store.hpp:64
bool slot_view_valid(const PublishedSampleView &view) const noexcept
Definition published_sample_store.hpp:61
bool prepare(const PublishedSampleStoreConfig &config)
std::uint32_t slot_count() const noexcept
Definition published_sample_store.hpp:36
bool load_interleaved_stereo(const float *interleaved, int num_frames, double sample_rate, std::uint64_t audio_safe_generation=0)
std::uint64_t max_frames_per_slot() const noexcept
Definition published_sample_store.hpp:38
std::uint32_t max_channels() const noexcept
Definition published_sample_store.hpp:37
bool has_sample() const noexcept
Definition published_sample_store.hpp:55
bool populate_channel_ptrs(const PublishedSampleView &view, const float **channel_ptrs, std::size_t channel_capacity) const noexcept
bool publish(BufferView< const float > source, std::uint64_t frames, double sample_rate, std::uint64_t audio_safe_generation=0)
PublishedSampleView read_published_view() const noexcept
Definition published_sample_store.hpp:58
Definition sample_slot_bank.hpp:37
Definition analyzer_provider.hpp:12
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
Definition published_sample_store.hpp:13
std::uint64_t max_frames_per_slot
Definition published_sample_store.hpp:19
std::uint32_t slot_count
Definition published_sample_store.hpp:17
std::uint32_t max_channels
Definition published_sample_store.hpp:18
Definition sample_slot_bank.hpp:22