MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
StreamSlice.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
8#include <optional>
9
10namespace MayaFlux::Kakshya {
11
12/**
13 * @struct StreamSlice
14 * @brief A bounded region of a DynamicSoundStream with associated playback parameters.
15 *
16 * Describes a slice of audio data within a DynamicSoundStream as a Region.
17 * region.start_coordinates[0] / end_coordinates[0] are the frame bounds;
18 * region.start_coordinates[1] / end_coordinates[1] are the channel bounds.
19 *
20 * The slice does not own a processor. The region is the contract; whatever
21 * drives this slice resolves the appropriate processor at activation time.
22 * Currently that is CursorAccessProcessor for sequential bounded reads, but
23 * the region descriptor is equally valid input to RegionOrganizationProcessor
24 * (non-linear navigation, selection patterns, transitions) or any future
25 * region-aware processor against a DynamicSoundStream.
26 *
27 * speed and scale are playback parameters applied by the driving processor.
28 * cursor_remainder accumulates sub-frame advancement for speed != 1.0.
29 * looping and index are playback state and identity carried with the slice.
30 *
31 * time_map, when set, replaces speed: it gives the read position in frames as
32 * a function of seconds since the voice was bound (see Kinesis::TimeMaps).
33 * Like the other fields it can be changed while the voice plays.
34 *
35 * source_channel picks which channel of the stream is played. Unset, the voice
36 * plays the stream channel with the same number as its output channel.
37 *
38 * repeat, with a time_map, restarts the map over and over. Its value is how
39 * many seconds each repeat lasts, read when the repeat begins, so a length that
40 * shrinks over time gives a stutter or bouncing repeat.
41 */
43 std::shared_ptr<DynamicSoundStream> stream;
45
46 double speed { 1.0 };
48 double scale { 1.0 };
49 bool looping {};
50 bool active {};
51 uint8_t index {};
52 size_t loop_count {};
53 std::shared_ptr<const Kinesis::TimeMap> time_map;
54 std::optional<uint32_t> source_channel;
55 std::shared_ptr<const Kinesis::TimeMap> repeat;
56
57 /**
58 * @brief Construct a slice spanning the full stream across all channels.
59 * @param stream Source stream.
60 * @param index Slot identity.
61 */
63 std::shared_ptr<DynamicSoundStream> stream,
64 uint8_t index = 0)
65 {
66 const uint64_t end_frame = stream->get_num_frames() > 0
67 ? stream->get_num_frames() - 1
68 : 0;
69 const uint64_t end_channel = stream->get_num_channels() > 0
70 ? stream->get_num_channels() - 1
71 : 0;
72 return StreamSlice {
73 .stream = std::move(stream),
75 .index = index,
76 };
77 }
78
79 /**
80 * @brief Construct a slice spanning a frame sub-region across all channels.
81 * @param stream Source stream.
82 * @param start_frame Inclusive start frame.
83 * @param end_frame Inclusive end frame.
84 * @param index Slot identity.
85 */
87 std::shared_ptr<DynamicSoundStream> stream,
88 uint64_t start_frame,
89 uint64_t end_frame,
90 uint8_t index = 0)
91 {
92 const uint64_t end_channel = stream->get_num_channels() > 0
93 ? stream->get_num_channels() - 1
94 : 0;
95 return StreamSlice {
96 .stream = std::move(stream),
98 .index = index,
99 };
100 }
101
102 /**
103 * @brief Construct a slice spanning a frame and channel sub-region.
104 * @param stream Source stream.
105 * @param start_frame Inclusive start frame.
106 * @param end_frame Inclusive end frame.
107 * @param start_channel Inclusive start channel.
108 * @param end_channel Inclusive end channel.
109 * @param index Slot identity.
110 */
112 std::shared_ptr<DynamicSoundStream> stream,
113 uint64_t start_frame,
114 uint64_t end_frame,
115 uint32_t start_channel,
116 uint32_t end_channel,
117 uint8_t index = 0)
118 {
119 return StreamSlice {
120 .stream = std::move(stream),
122 .index = index,
123 };
124 }
125
126 [[nodiscard]] uint64_t start_frame() const { return region.start_coordinates[0]; }
127 [[nodiscard]] uint64_t end_frame() const { return region.end_coordinates[0]; }
128 [[nodiscard]] uint32_t start_channel() const { return static_cast<uint32_t>(region.start_coordinates[1]); }
129 [[nodiscard]] uint32_t end_channel() const { return static_cast<uint32_t>(region.end_coordinates[1]); }
130
132 {
133 speed = s;
134 return *this;
135 }
136
138 {
139 looping = l;
140 return *this;
141 }
142
144 {
145 scale = s;
146 return *this;
147 }
148
150 {
151 loop_count = n;
152 return *this;
153 }
154
156 {
157 time_map = std::make_shared<const Kinesis::TimeMap>(std::move(map));
158 return *this;
159 }
160
162 {
163 source_channel = channel;
164 return *this;
165 }
166
168 {
169 repeat = std::make_shared<const Kinesis::TimeMap>(std::move(length));
170 return *this;
171 }
172};
173
174} // namespace MayaFlux::Kakshya
uint64_t length
Definition Composite.cpp:11
static Region audio_span(uint64_t start_frame, uint64_t end_frame, uint32_t start_channel, uint32_t end_channel, const std::string &label="")
Create a Region representing a span in audio (frames and channels).
Definition Region.hpp:182
std::vector< uint64_t > end_coordinates
Ending frame index (inclusive)
Definition Region.hpp:78
std::vector< uint64_t > start_coordinates
Starting frame index (inclusive)
Definition Region.hpp:75
Represents a point or span in N-dimensional space.
Definition Region.hpp:73
StreamSlice & with_source_channel(uint32_t channel)
std::shared_ptr< const Kinesis::TimeMap > time_map
static StreamSlice from_region(std::shared_ptr< DynamicSoundStream > stream, uint64_t start_frame, uint64_t end_frame, uint32_t start_channel, uint32_t end_channel, uint8_t index=0)
Construct a slice spanning a frame and channel sub-region.
std::shared_ptr< DynamicSoundStream > stream
static StreamSlice from_frame_range(std::shared_ptr< DynamicSoundStream > stream, uint64_t start_frame, uint64_t end_frame, uint8_t index=0)
Construct a slice spanning a frame sub-region across all channels.
StreamSlice & with_looping(bool l)
StreamSlice & with_scale(double s)
StreamSlice & with_speed(double s)
std::shared_ptr< const Kinesis::TimeMap > repeat
StreamSlice & with_repeat(Kinesis::TimeMap length)
StreamSlice & with_time_map(Kinesis::TimeMap map)
std::optional< uint32_t > source_channel
static StreamSlice from_stream(std::shared_ptr< DynamicSoundStream > stream, uint8_t index=0)
Construct a slice spanning the full stream across all channels.
StreamSlice & with_loop_count(size_t n)
A bounded region of a DynamicSoundStream with associated playback parameters.
Typed, composable, stateless callable from domain D to range R.
Definition Tendency.hpp:22