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