Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
sample_heritage_live_cyclic.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstddef>
7#include <cstdint>
8#include <span>
9#include <vector>
10
11namespace pulp::audio {
12
13inline constexpr double kSampleHeritageCyclicStretchMinimumFactor = 0.25;
14inline constexpr double kSampleHeritageCyclicStretchMaximumFactor = 20.0;
15
20
31
45
57
68
70 std::uint64_t seed = 0;
71 std::uint64_t next_cycle_index = 0;
72};
73
81 public:
82 static constexpr std::size_t kInterpolatorGuardFrames = 2;
83
89
92
94 void release() noexcept;
95 void reset() noexcept;
97
98 bool prepared() const noexcept {
99 return prepared_;
100 }
101 bool exact_bypass() const noexcept {
102 return exact_bypass_;
103 }
104 double source_frames_per_output_frame() const noexcept {
105 return source_ratio_;
106 }
107 std::size_t startup_prebuffer_frames() const noexcept {
108 return startup_prebuffer_;
109 }
111 return resources_;
112 }
113
114 SampleHeritageLiveCyclicPlan plan(std::size_t output_frames) const noexcept;
116 BufferView<float> output) noexcept;
118 BufferView<float> output,
119 std::size_t valid_input_frames,
120 bool end_of_source) noexcept;
121 std::size_t last_valid_output_frames() const noexcept {
122 return last_valid_output_frames_;
123 }
124 std::uint64_t remaining_output_frames() const noexcept {
125 return source_ended_ && target_output_frames_ > rendered_output_frames_
126 ? target_output_frames_ - rendered_output_frames_
127 : 0;
128 }
129
130 bool division_permutation(std::uint64_t cycle_index, std::size_t channel,
131 std::span<std::uint32_t> destination) const noexcept;
133
134 private:
135 static constexpr std::size_t kMaximumCycleSamples = 1u << 20u;
136 static constexpr std::size_t kMaximumDivisions = 1024;
137 static constexpr std::size_t kMaximumChannels = 64;
138
139 bool fill_permutation(std::uint64_t cycle_index, std::size_t channel,
140 std::uint32_t* destination) const noexcept;
141 std::size_t mapped_cycle_offset(std::size_t phase, std::uint64_t cycle_index,
142 std::size_t channel, bool& join_crossfade,
143 std::size_t& alternate_offset, float& join_weight) noexcept;
144 float read_linear(std::size_t channel, double position, bool& ok) const noexcept;
145 void write_input(BufferView<const float> input) noexcept;
146 std::uint64_t source_anchor(std::uint64_t cycle_index, bool& overflow) const noexcept;
147 std::uint64_t required_source_through(std::uint64_t first_output, std::uint64_t output_frames,
148 bool& overflow) const noexcept;
149 std::uint32_t* permutation_slot(std::size_t channel) noexcept;
150
153 std::vector<float> ring_;
154 std::vector<std::uint32_t> permutation_;
155 double source_ratio_ = 1.0;
156 std::size_t startup_prebuffer_ = 0;
157 std::uint64_t accepted_source_frames_ = 0;
158 std::uint64_t rendered_output_frames_ = 0;
159 std::uint64_t real_source_frames_ = 0;
160 std::uint64_t target_output_frames_ = 0;
161 std::uint64_t cycle_index_offset_ = 0;
162 std::uint64_t permutation_cycle_ = static_cast<std::uint64_t>(-1);
163 bool prepared_ = false;
164 bool exact_bypass_ = false;
165 bool source_ended_ = false;
166 std::size_t last_valid_output_frames_ = 0;
167};
168
169} // namespace pulp::audio
Non-owning view over multi-channel audio sample data.
Definition buffer.hpp:30
SampleHeritageLiveCyclicPlan plan(std::size_t output_frames) const noexcept
const SampleHeritageLiveCyclicResources & resources() const noexcept
Definition sample_heritage_live_cyclic.hpp:110
std::size_t last_valid_output_frames() const noexcept
Definition sample_heritage_live_cyclic.hpp:121
SampleHeritageLiveCyclicStatus prepare(const SampleHeritageLiveCyclicConfig &config) noexcept
std::uint64_t remaining_output_frames() const noexcept
Definition sample_heritage_live_cyclic.hpp:124
static SampleHeritageLiveCyclicResources resources_for(const SampleHeritageLiveCyclicConfig &config) noexcept
SampleHeritageLiveCyclicStretch & operator=(SampleHeritageLiveCyclicStretch &&)=delete
SampleHeritageLiveCyclicStatus process(BufferView< const float > input, BufferView< float > output) noexcept
static constexpr std::size_t kInterpolatorGuardFrames
Definition sample_heritage_live_cyclic.hpp:82
SampleHeritageLiveCyclicRngContinuation capture_next_cycle_rng_continuation() const noexcept
SampleHeritageLiveCyclicStretch & operator=(const SampleHeritageLiveCyclicStretch &)=delete
void reset_with_rng_continuation(SampleHeritageLiveCyclicRngContinuation continuation) noexcept
SampleHeritageLiveCyclicStatus process(BufferView< const float > input, BufferView< float > output, std::size_t valid_input_frames, bool end_of_source) noexcept
SampleHeritageLiveCyclicStretch(const SampleHeritageLiveCyclicStretch &)=delete
SampleHeritageLiveCyclicStretch(SampleHeritageLiveCyclicStretch &&)=delete
bool prepared() const noexcept
Definition sample_heritage_live_cyclic.hpp:98
double source_frames_per_output_frame() const noexcept
Definition sample_heritage_live_cyclic.hpp:104
std::size_t startup_prebuffer_frames() const noexcept
Definition sample_heritage_live_cyclic.hpp:107
bool exact_bypass() const noexcept
Definition sample_heritage_live_cyclic.hpp:101
bool division_permutation(std::uint64_t cycle_index, std::size_t channel, std::span< std::uint32_t > destination) const noexcept
Definition analyzer_provider.hpp:12
SampleHeritageLiveCyclicShuffle
Definition sample_heritage_live_cyclic.hpp:16
@ FisherYates
Definition sample_heritage_live_cyclic.hpp:18
@ Identity
Definition sample_heritage_live_cyclic.hpp:17
SampleHeritageLivePitchMode
Definition sample_heritage_schema.hpp:62
@ Preserve
Definition sample_heritage_schema.hpp:62
@ AllocationFailed
Definition finite_time_stretch.hpp:27
constexpr double kSampleHeritageCyclicStretchMinimumFactor
Definition sample_heritage_live_cyclic.hpp:13
@ SizeOverflow
Definition sample_heritage_engine.hpp:44
@ InvalidDimensions
Definition sample_heritage_bus_dsp.hpp:23
@ NotPrepared
Definition sample_heritage_bus_dsp.hpp:21
@ Ok
Definition loop_types.hpp:34
@ ok
Definition analyzer_provider.hpp:58
@ InputFrameMismatch
Definition sample_heritage_engine.hpp:86
constexpr double kSampleHeritageCyclicStretchMaximumFactor
Definition sample_heritage_live_cyclic.hpp:14
SampleHeritageLiveCyclicStatus
Definition sample_heritage_live_cyclic.hpp:21
@ NotPrepared
Definition sample_heritage_live_cyclic.hpp:23
@ SourceUnavailable
Definition sample_heritage_live_cyclic.hpp:29
@ Ok
Definition sample_heritage_live_cyclic.hpp:22
@ InvalidConfiguration
Definition sample_heritage_live_cyclic.hpp:24
STL namespace.
Definition sample_heritage_live_cyclic.hpp:32
bool tempo_lock
Definition sample_heritage_live_cyclic.hpp:43
double factor
Definition sample_heritage_live_cyclic.hpp:33
std::uint64_t seed
Definition sample_heritage_live_cyclic.hpp:38
std::size_t cycle_samples
Definition sample_heritage_live_cyclic.hpp:34
SampleHeritageLivePitchMode pitch_mode
Definition sample_heritage_live_cyclic.hpp:42
std::size_t channel_count
Definition sample_heritage_live_cyclic.hpp:41
std::size_t crossfade_samples
Definition sample_heritage_live_cyclic.hpp:35
std::size_t shuffle_divisions
Definition sample_heritage_live_cyclic.hpp:36
std::size_t max_block_samples
Definition sample_heritage_live_cyclic.hpp:40
SampleHeritageLiveCyclicShuffle shuffle
Definition sample_heritage_live_cyclic.hpp:39
bool linked_channels
Definition sample_heritage_live_cyclic.hpp:37
Definition sample_heritage_live_cyclic.hpp:58
SampleHeritageLiveCyclicStatus status
Definition sample_heritage_live_cyclic.hpp:59
std::size_t input_frames
Definition sample_heritage_live_cyclic.hpp:61
std::size_t startup_prebuffer_frames
Definition sample_heritage_live_cyclic.hpp:62
bool valid() const noexcept
Definition sample_heritage_live_cyclic.hpp:64
std::size_t output_frames
Definition sample_heritage_live_cyclic.hpp:60
Definition sample_heritage_live_cyclic.hpp:46
SampleHeritageLiveCyclicStatus status
Definition sample_heritage_live_cyclic.hpp:47
std::size_t ring_capacity_frames
Definition sample_heritage_live_cyclic.hpp:49
std::size_t scratch_bytes
Definition sample_heritage_live_cyclic.hpp:51
std::size_t persistent_bytes
Definition sample_heritage_live_cyclic.hpp:50
std::size_t maximum_input_frames
Definition sample_heritage_live_cyclic.hpp:48
bool valid() const noexcept
Definition sample_heritage_live_cyclic.hpp:53
Definition sample_heritage_live_cyclic.hpp:69
std::uint64_t next_cycle_index
Definition sample_heritage_live_cyclic.hpp:71
std::uint64_t seed
Definition sample_heritage_live_cyclic.hpp:70