Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
loop_renderer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
9
10namespace pulp::audio {
11
13 std::uint64_t rendered_frames = 0;
14 std::uint64_t source_backed_frames = 0;
15 std::uint64_t silent_frames = 0;
16 bool active = false;
17 bool wrapped = false;
18 float max_sample_delta = 0.0f;
19};
20
22public:
23 bool set_region(const LoopRegion& region,
24 std::uint64_t source_frames) noexcept;
25 void reset() noexcept;
26 void start() noexcept;
27 void stop() noexcept;
28
29 void set_playback_rate(double rate) noexcept;
33 return interpolation_.policy;
34 }
36 return interpolation_;
37 }
38 // Change the loop playback mode in place, preserving the current position — so a
39 // sustaining voice can switch Forward<->OneShot without restarting (e.g. a LOOP
40 // toggle acting on already-held notes). Does not re-arm fades or reset position.
41 void set_playback_mode(LoopPlaybackMode mode) noexcept { cursor_.set_playback_mode(mode); }
42 LoopPlaybackMode playback_mode() const noexcept { return cursor_.region().playback_mode; }
43 void set_start_fade_frames(std::uint64_t frames) noexcept { start_fade_frames_ = frames; }
44 void set_stop_fade_frames(std::uint64_t frames) noexcept { stop_fade_frames_ = frames; }
45
46 bool active() const noexcept { return cursor_.active(); }
47 double position() const noexcept { return cursor_.position(); }
48
49 // Overwrite renderer for RT voice scratch buffers. Writes every frame up
50 // to min(frames, destination.num_samples()) for every destination channel;
51 // inactive, invalid-source, and fade-to-zero frames are written as silence.
52 // The destination does not need to be pre-cleared, and this call never
53 // accumulates into existing samples.
55 BufferView<float> destination,
56 std::uint64_t frames) noexcept;
57
58private:
59 float apply_crossfade_plan(BufferView<const float> source,
60 std::uint32_t output_channel,
61 const LoopFrameReadPlan& plan) const noexcept;
62 float fade_gain() noexcept;
63
64 LoopPlaybackCursor cursor_;
65 PreparedSampleInterpolation interpolation_{
67 std::uint64_t start_fade_frames_ = 0;
68 std::uint64_t stop_fade_frames_ = 0;
69 std::uint64_t start_fade_position_ = 0;
70 std::uint64_t stop_fade_position_ = 0;
71 bool stopping_ = false;
72};
73
74} // namespace pulp::audio
Non-owning view over multi-channel audio sample data.
Definition buffer.hpp:30
Allocation-free loop traversal state independent of sample storage.
Definition loop_playback_cursor.hpp:27
Definition loop_renderer.hpp:21
bool active() const noexcept
Definition loop_renderer.hpp:46
bool set_interpolation(const PreparedSampleInterpolation &interpolation) noexcept
LoopRenderResult render(BufferView< const float > source, BufferView< float > destination, std::uint64_t frames) noexcept
double position() const noexcept
Definition loop_renderer.hpp:47
SampleInterpolationPolicy interpolation_policy() const noexcept
Definition loop_renderer.hpp:32
void set_stop_fade_frames(std::uint64_t frames) noexcept
Definition loop_renderer.hpp:44
const PreparedSampleInterpolation & interpolation() const noexcept
Definition loop_renderer.hpp:35
void set_start_fade_frames(std::uint64_t frames) noexcept
Definition loop_renderer.hpp:43
bool set_region(const LoopRegion &region, std::uint64_t source_frames) noexcept
LoopPlaybackMode playback_mode() const noexcept
Definition loop_renderer.hpp:42
bool set_interpolation_policy(SampleInterpolationPolicy policy) noexcept
void set_playback_rate(double rate) noexcept
void set_playback_mode(LoopPlaybackMode mode) noexcept
Definition loop_renderer.hpp:41
Definition analyzer_provider.hpp:12
LoopPlaybackMode
Definition loop_types.hpp:7
SampleInterpolationPolicy
Definition sample_interpolation.hpp:21
@ Linear
Definition sample_interpolation.hpp:24
Definition loop_playback_cursor.hpp:9
Definition loop_types.hpp:42
Definition loop_renderer.hpp:12
bool wrapped
Definition loop_renderer.hpp:17
std::uint64_t source_backed_frames
Definition loop_renderer.hpp:14
std::uint64_t rendered_frames
Definition loop_renderer.hpp:13
bool active
Definition loop_renderer.hpp:16
std::uint64_t silent_frames
Definition loop_renderer.hpp:15
float max_sample_delta
Definition loop_renderer.hpp:18
Definition sample_interpolation.hpp:148
SampleInterpolationPolicy policy
Definition sample_interpolation.hpp:149