MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ write_frames() [2/2]

uint64_t MayaFlux::Kakshya::DynamicSoundStream::write_frames ( std::vector< std::span< const double > >  data,
uint64_t  start_frame = 0 
)

Definition at line 102 of file DynamicSoundStream.cpp.

103{
104 auto num_frames = validate(data, start_frame);
105
106 if (!num_frames)
107 return 0;
108
109 if (m_is_circular && start_frame + num_frames > m_circular_capacity) {
110 uint64_t frames_to_end = m_circular_capacity - start_frame;
111 uint64_t frames_from_start = num_frames - frames_to_end;
112
113 if (frames_to_end > 0) {
114 std::vector<std::span<const double>> first_part;
115 first_part.reserve(data.size());
116 for (const auto& span : data) {
117 first_part.emplace_back(span.subspan(0, frames_to_end));
118 }
119 write_frames(first_part, start_frame);
120 }
121
122 if (frames_from_start > 0) {
123 std::vector<std::span<const double>> second_part;
124 second_part.reserve(data.size());
125 for (const auto& span : data) {
126 second_part.emplace_back(span.subspan(frames_to_end, frames_from_start));
127 }
128 write_frames(second_part, 0);
129 }
130
131 return num_frames;
132 }
133
134 Region write_region {
135 { start_frame, 0 },
136 { start_frame + num_frames - 1, get_num_channels() - 1 }
137 };
138
139 std::vector<DataVariant> data_variants;
140
142 uint64_t samples_to_write = num_frames * get_num_channels();
143 data_variants.emplace_back(
144 std::vector<double>(data[0].begin(), data[0].begin() + samples_to_write));
145 } else {
146 data_variants = data
147 | std::views::take(get_num_channels())
148 | std::views::transform([num_frames](const auto& span) -> DataVariant {
149 return DataVariant(std::vector<double>(span.begin(), span.begin() + num_frames));
150 })
151 | std::ranges::to<std::vector>();
152 }
153
154 set_region_data(write_region, data_variants);
155
156 if (m_is_circular) {
158 }
159
160 return num_frames;
161}
bool m_is_circular
True when operating in circular buffer mode.
uint64_t validate(std::vector< std::span< const double > > &data, uint64_t start_frame=0)
uint64_t write_frames(std::span< const double > data, uint64_t start_frame=0, uint32_t channel=0)
Write audio frame data to the container with automatic capacity management.
uint64_t m_circular_capacity
Fixed capacity for circular mode.
void set_region_data(const Region &region, const std::vector< DataVariant > &data) override
Set data for a specific region.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:73
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)

References MayaFlux::Kakshya::SoundStreamContainer::get_num_channels(), MayaFlux::Kakshya::INTERLEAVED, m_circular_capacity, m_is_circular, MayaFlux::Kakshya::SoundStreamContainer::m_num_frames, MayaFlux::Kakshya::SoundStreamContainer::m_structure, MayaFlux::Kakshya::ContainerDataStructure::organization, MayaFlux::Kakshya::SoundStreamContainer::set_region_data(), validate(), and write_frames().

+ Here is the call graph for this function: