MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
StreamSlice.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Kakshya {
7
8/**
9 * @struct StreamSlice
10 * @brief A bounded region of a DynamicSoundStream with associated playback parameters.
11 *
12 * Describes a slice of audio data within a DynamicSoundStream as a Region.
13 * region.start_coordinates[0] / end_coordinates[0] are the frame bounds;
14 * region.start_coordinates[1] / end_coordinates[1] are the channel bounds.
15 *
16 * The slice does not own a processor. The region is the contract; whatever
17 * drives this slice resolves the appropriate processor at activation time.
18 * Currently that is CursorAccessProcessor for sequential bounded reads, but
19 * the region descriptor is equally valid input to RegionOrganizationProcessor
20 * (non-linear navigation, selection patterns, transitions) or any future
21 * region-aware processor against a DynamicSoundStream.
22 *
23 * speed and scale are playback parameters applied by the driving processor.
24 * cursor_remainder accumulates sub-frame advancement for speed != 1.0.
25 * looping and index are playback state and identity carried with the slice.
26 */
28 std::shared_ptr<DynamicSoundStream> stream;
30
31 double speed { 1.0 };
33 double scale { 1.0 };
34 bool looping {};
35 bool active {};
36 uint8_t index {};
37 size_t loop_count {};
38
39 /**
40 * @brief Construct a slice spanning the full stream across all channels.
41 * @param stream Source stream.
42 * @param index Slot identity.
43 */
45 std::shared_ptr<DynamicSoundStream> stream,
46 uint8_t index = 0)
47 {
48 const uint64_t end_frame = stream->get_num_frames() > 0
49 ? stream->get_num_frames() - 1
50 : 0;
51 const uint64_t end_channel = stream->get_num_channels() > 0
52 ? stream->get_num_channels() - 1
53 : 0;
54 return StreamSlice {
55 .stream = std::move(stream),
57 .index = index,
58 };
59 }
60
61 /**
62 * @brief Construct a slice spanning a frame sub-region across all channels.
63 * @param stream Source stream.
64 * @param start_frame Inclusive start frame.
65 * @param end_frame Inclusive end frame.
66 * @param index Slot identity.
67 */
69 std::shared_ptr<DynamicSoundStream> stream,
70 uint64_t start_frame,
71 uint64_t end_frame,
72 uint8_t index = 0)
73 {
74 const uint64_t end_channel = stream->get_num_channels() > 0
75 ? stream->get_num_channels() - 1
76 : 0;
77 return StreamSlice {
78 .stream = std::move(stream),
80 .index = index,
81 };
82 }
83
84 /**
85 * @brief Construct a slice spanning a frame and channel sub-region.
86 * @param stream Source stream.
87 * @param start_frame Inclusive start frame.
88 * @param end_frame Inclusive end frame.
89 * @param start_channel Inclusive start channel.
90 * @param end_channel Inclusive end channel.
91 * @param index Slot identity.
92 */
94 std::shared_ptr<DynamicSoundStream> stream,
95 uint64_t start_frame,
96 uint64_t end_frame,
97 uint32_t start_channel,
98 uint32_t end_channel,
99 uint8_t index = 0)
100 {
101 return StreamSlice {
102 .stream = std::move(stream),
104 .index = index,
105 };
106 }
107
108 [[nodiscard]] uint64_t start_frame() const { return region.start_coordinates[0]; }
109 [[nodiscard]] uint64_t end_frame() const { return region.end_coordinates[0]; }
110 [[nodiscard]] uint32_t start_channel() const { return static_cast<uint32_t>(region.start_coordinates[1]); }
111 [[nodiscard]] uint32_t end_channel() const { return static_cast<uint32_t>(region.end_coordinates[1]); }
112
114 {
115 speed = s;
116 return *this;
117 }
118
120 {
121 looping = l;
122 return *this;
123 }
124
126 {
127 scale = s;
128 return *this;
129 }
130
132 {
133 loop_count = n;
134 return *this;
135 }
136};
137
138} // namespace MayaFlux::Kakshya
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:176
std::vector< uint64_t > end_coordinates
Ending frame index (inclusive)
Definition Region.hpp:72
std::vector< uint64_t > start_coordinates
Starting frame index (inclusive)
Definition Region.hpp:69
Represents a point or span in N-dimensional space.
Definition Region.hpp:67
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)
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.