MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
StreamWriteProcessor.cpp
Go to the documentation of this file.
3
5
6namespace MayaFlux::Buffers {
7
8void StreamWriteProcessor::processing_function(std::shared_ptr<Buffer> buffer)
9{
10 auto audio_buffer = std::dynamic_pointer_cast<AudioBuffer>(buffer);
11 if (!audio_buffer || !m_container)
12 return;
13
14 std::span<const double> data_span = audio_buffer->get_data();
15
16 if (data_span.empty())
17 return;
18
19 uint32_t channel_id = audio_buffer->get_channel_id();
20
21 if (channel_id >= m_container->get_num_channels()) {
22 std::cerr << "Warning: AudioBuffer channel " << channel_id
23 << " exceeds container channels (" << m_container->get_num_channels()
24 << "). Skipping write." << '\n';
25 return;
26 }
27
28 uint64_t frames_written = m_container->write_frames(data_span, m_write_position, channel_id);
29
30 if (frames_written > 0) {
31 m_write_position += frames_written;
32
33 if (m_container->is_circular() && m_write_position >= m_container->get_circular_capacity()) {
35 }
36 }
37}
38
40{
41 if (m_container) {
42 m_write_position = m_container->time_to_position(time_seconds);
43 }
44}
45
47{
48 if (m_container) {
49 return m_container->position_to_time(m_write_position);
50 }
51 return 0.0;
52}
53}
std::shared_ptr< Kakshya::DynamicSoundStream > m_container
uint64_t m_write_position
Current write position in frames.
void set_write_position_time(double time_seconds)
Set write position to a specific time offset.
void processing_function(std::shared_ptr< Buffer > buffer) override
Write buffer audio data to the appropriate container channel.
double get_write_position_time() const
Get current write position as time offset.