10 : m_container(container)
13 auto structure = container->get_structure();
16 container->register_state_change_callback(
17 [
this](
auto c,
auto s) {
30 buffer->mark_for_removal();
39 buffer->mark_for_removal();
52 auto audio_buffer = std::dynamic_pointer_cast<AudioBuffer>(buffer);
53 auto& buffer_data = audio_buffer->get_data();
54 uint32_t buffer_size = audio_buffer->get_num_samples();
56 auto read_positions =
m_container->get_read_position();
61 if (buffer_data.size() != buffer_size) {
62 buffer_data.resize(buffer_size);
72 buffer->mark_for_processing(
true);
79 std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(
m_container)->clear_all_consumption();
83 }
catch (
const std::exception& e) {
85 "SoundStreamReader: Error during processing: {}", e.what());
91 auto sc = std::dynamic_pointer_cast<Kakshya::SoundStreamContainer>(
m_container);
93 std::ranges::fill(output, 0.0);
97 const auto& pd = sc->get_processed_data();
98 const auto structure = sc->get_structure();
101 pd, structure.organization, structure.get_channel_count(),
115 std::source_location::current(),
116 "SoundStreamReader: Container not ready for processing");
120 auto& buffer_data = std::dynamic_pointer_cast<AudioBuffer>(buffer)->get_data();
121 uint32_t num_samples = std::dynamic_pointer_cast<AudioBuffer>(buffer)->get_num_samples();
126 buffer->mark_for_processing(
true);
129 }
catch (
const std::exception& e) {
131 "SoundStreamReader: Error pre-filling buffer: {}", e.what());
147 std::source_location::current(),
148 "SoundStreamReader: Channel index {} exceeds container channel count {}",
163 auto structure = container->get_structure();
166 container->register_state_change_callback(
174 const std::shared_ptr<Kakshya::SignalSourceContainer>& ,
183 "SoundStreamReader: Container entered ERROR state");
192 const std::shared_ptr<Kakshya::StreamContainer>& container,
193 uint32_t source_channel)
195 , m_container(container)
196 , m_source_channel(source_channel)
200 std::source_location::current(),
201 "SoundContainerBuffer: container must not be null");
224 adapter->set_container(container);
257 auto adapter = std::make_shared<SoundStreamReader>(
m_container);
#define MF_ERROR(comp, ctx,...)
void enforce_default_processing(bool should_process) override
Controls whether the audio buffer should use default processing.
std::shared_ptr< BufferProcessor > m_default_processor
Default audio transformation processor for this buffer.
void set_default_processor(const std::shared_ptr< BufferProcessor > &processor) override
Sets the default audio transformation processor for this buffer.
Concrete audio implementation of the Buffer interface for double-precision audio data.
void initialize()
Initialize the buffer after construction.
void setup_zero_copy_if_possible()
Attempt to enable zero-copy operation if container layout allows.
std::shared_ptr< Kakshya::StreamContainer > m_container
void set_container(const std::shared_ptr< Kakshya::StreamContainer > &container)
Update the container reference.
SoundContainerBuffer(uint32_t channel_id, uint32_t num_samples, const std::shared_ptr< Kakshya::StreamContainer > &container, uint32_t source_channel=0)
Construct a SoundContainerBuffer for a specific channel and container.
uint32_t m_source_channel
std::shared_ptr< BufferProcessor > m_pending_adapter
std::shared_ptr< BufferProcessor > create_default_processor() override
Create the default processor (SoundStreamReader) for this buffer.
void set_container(const std::shared_ptr< Kakshya::StreamContainer > &container)
Set the container to adapt.
void on_detach(const std::shared_ptr< Buffer > &buffer) override
Detach the adapter from its AudioBuffer.
std::shared_ptr< Kakshya::StreamContainer > m_container
uint32_t m_source_channel
void extract_channel_data(std::span< double > output)
Extract channel data from the container into the output buffer.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Attach the adapter to an AudioBuffer.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
Extracts and processes data from the container into the target AudioBuffer.
void on_container_state_change(const std::shared_ptr< Kakshya::SignalSourceContainer > &container, Kakshya::ProcessingState state)
Respond to container state changes (e.g., READY, PROCESSED, NEEDS_REMOVAL).
void set_source_channel(uint32_t channel_index)
Set which channel dimension to extract from the container.
SoundStreamReader(const std::shared_ptr< Kakshya::StreamContainer > &container)
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Init
Engine/subsystem initialization.
@ Buffers
Buffers, Managers, processors and processing chains.
ProcessingState
Represents the current processing lifecycle state of a container.
@ READY
Container has data loaded and is ready for processing.
@ NEEDS_REMOVAL
Container is marked for removal from the system.
@ ERROR
Container is in an error state and cannot proceed.
@ PROCESSED
Container has completed processing and results are available.
void extract_processed_data(const std::vector< DataVariant > &pd, OrganizationStrategy organization, uint64_t num_channels, uint32_t ch, std::span< double > output)
Extract one channel's samples from a processed dynamic data block.