MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Kakshya::SoundStreamContainer Class Reference

Concrete base implementation for streaming audio containers. More...

#include <SoundStreamContainer.hpp>

+ Inheritance diagram for MayaFlux::Kakshya::SoundStreamContainer:
+ Collaboration diagram for MayaFlux::Kakshya::SoundStreamContainer:

Public Member Functions

 SoundStreamContainer (uint32_t sample_rate=48000, uint32_t num_channels=2, uint64_t initial_capacity=0, bool circular_mode=false)
 Construct a SoundStreamContainer with specified parameters.
 
 ~SoundStreamContainer () override=default
 
std::vector< DataDimensionget_dimensions () const override
 Get the dimensions describing the structure of the data.
 
uint64_t get_total_elements () const override
 Get the total number of elements in the container.
 
MemoryLayout get_memory_layout () const override
 Get the memory layout used by this container.
 
void set_memory_layout (MemoryLayout layout) override
 Set the memory layout for this container.
 
uint64_t get_frame_size () const override
 Get the number of elements that constitute one "frame".
 
uint64_t get_num_frames () const override
 Get the number of frames in the primary (temporal) dimension.
 
std::vector< DataVariantget_region_data (const Region &region) const override
 Get data for a specific region.
 
void set_region_data (const Region &region, const std::vector< DataVariant > &data) override
 Set data for a specific region.
 
std::vector< DataVariantget_region_group_data (const RegionGroup &group) const override
 Get data for multiple regions efficiently.
 
std::vector< DataVariantget_segments_data (const std::vector< RegionSegment > &segment) const override
 Get data for multiple region segments efficiently.
 
std::span< const double > get_frame (uint64_t frame_index) const override
 Get a single frame of data efficiently.
 
void get_frames (std::span< double > output, uint64_t start_frame, uint64_t num_frames) const override
 Get multiple frames efficiently.
 
double get_value_at (const std::vector< uint64_t > &coordinates) const override
 Get a single value at the specified coordinates.
 
void set_value_at (const std::vector< uint64_t > &coordinates, double value) override
 Set a single value at the specified coordinates.
 
uint64_t coordinates_to_linear_index (const std::vector< uint64_t > &coordinates) const override
 Convert coordinates to linear index based on current memory layout.
 
std::vector< uint64_t > linear_index_to_coordinates (uint64_t linear_index) const override
 Convert linear index to coordinates based on current memory layout.
 
void clear () override
 Clear all data in the container.
 
void lock () override
 Acquire a lock for thread-safe access.
 
void unlock () override
 Release a previously acquired lock.
 
bool try_lock () override
 Attempt to acquire a lock without blocking.
 
const void * get_raw_data () const override
 Get a raw pointer to the underlying data storage.
 
bool has_data () const override
 Check if the container currently holds any data.
 
ContainerDataStructureget_structure () override
 Get the data structure defining this container's layout.
 
const ContainerDataStructureget_structure () const override
 
void set_structure (ContainerDataStructure structure) override
 Set the data structure for this container.
 
void add_region_group (const RegionGroup &group) override
 Add a named group of regions to the container.
 
const RegionGroupget_region_group (const std::string &name) const override
 Get a region group by name.
 
std::unordered_map< std::string, RegionGroupget_all_region_groups () const override
 Get all region groups in the container.
 
void remove_region_group (const std::string &name) override
 Remove a region group by name.
 
bool is_region_loaded (const Region &region) const override
 Check if a region is loaded in memory.
 
void load_region (const Region &region) override
 Load a region into memory.
 
void unload_region (const Region &region) override
 Unload a region from memory.
 
void set_read_position (const std::vector< uint64_t > &position) override
 Set the current read position in the primary temporal dimension per channel.
 
void update_read_position_for_channel (size_t channel, uint64_t frame) override
 Update the read position for a specific channel.
 
const std::vector< uint64_t > & get_read_position () const override
 Get the current read position.
 
void advance_read_position (const std::vector< uint64_t > &frames) override
 Advance the read position by a specified amount.
 
bool is_at_end () const override
 Check if read position has reached the end of the stream.
 
void reset_read_position () override
 Reset read position to the beginning of the stream.
 
uint64_t get_temporal_rate () const override
 Get the temporal rate (e.g., sample rate, frame rate) of the stream.
 
uint64_t time_to_position (double time) const override
 Convert from time (seconds) to position units (e.g., frame/sample index).
 
double position_to_time (uint64_t position) const override
 Convert from position units (e.g., frame/sample index) to time (seconds).
 
void set_looping (bool enable) override
 Enable or disable looping behavior for the stream.
 
bool is_looping () const override
 Check if looping is enabled for the stream.
 
void set_loop_region (const Region &region) override
 Set the loop region using a Region.
 
Region get_loop_region () const override
 Get the current loop region.
 
bool is_ready () const override
 Check if the stream is ready for reading.
 
std::vector< uint64_t > get_remaining_frames () const override
 Get the number of remaining frames from the current position, per channel.
 
uint64_t read_sequential (std::span< double > output, uint64_t count) override
 Read data sequentially from the current position.
 
uint64_t peek_sequential (std::span< double > output, uint64_t count, uint64_t offset=0) const override
 Peek at data without advancing the read position.
 
ProcessingState get_processing_state () const override
 Get the current processing state of the container.
 
void update_processing_state (ProcessingState new_state) override
 Update the processing state of the container.
 
void register_state_change_callback (std::function< void(std::shared_ptr< SignalSourceContainer >, ProcessingState)> callback) override
 Register a callback to be invoked on processing state changes.
 
void unregister_state_change_callback () override
 Unregister the state change callback, if any.
 
bool is_ready_for_processing () const override
 Check if the container is ready for processing.
 
void mark_ready_for_processing (bool ready) override
 Mark the container as ready or not ready for processing.
 
void create_default_processor () override
 Create and configure a default processor for this container.
 
void process_default () override
 Process the container's data using the default processor.
 
void set_default_processor (std::shared_ptr< DataProcessor > processor) override
 Set the default data processor for this container.
 
std::shared_ptr< DataProcessorget_default_processor () const override
 Get the current default data processor.
 
std::shared_ptr< DataProcessingChainget_processing_chain () override
 Get the current processing chain for this container.
 
void set_processing_chain (std::shared_ptr< DataProcessingChain > chain) override
 Set the processing chain for this container.
 
uint32_t register_dimension_reader (uint32_t dimension_index) override
 Register a reader for a specific dimension.
 
void unregister_dimension_reader (uint32_t dimension_index) override
 Unregister a reader for a specific dimension.
 
bool has_active_readers () const override
 Check if any dimensions currently have active readers.
 
void mark_dimension_consumed (uint32_t dimension_index, uint32_t reader_id) override
 Mark a dimension as consumed for the current processing cycle.
 
bool all_dimensions_consumed () const override
 Check if all active dimensions have been consumed in this cycle.
 
virtual void clear_all_consumption ()
 
std::vector< DataVariant > & get_processed_data () override
 Get a mutable reference to the processed data buffer.
 
const std::vector< DataVariant > & get_processed_data () const override
 Get a const reference to the processed data buffer.
 
void mark_buffers_for_processing (bool) override
 Mark associated buffers for processing in the next cycle.
 
void mark_buffers_for_removal () override
 Mark associated buffers for removal from the system.
 
virtual uint32_t get_sample_rate () const
 
virtual uint32_t get_num_channels () const
 
void reset_processing_token () override
 
bool try_acquire_processing_token (int channel) override
 
bool has_processing_token (int channel) const override
 
std::span< const double > get_data_as_double () const
 Get the audio data as a specific type.
 
const std::vector< DataVariant > & get_data () override
 Get a reference to the raw data stored in the container.
 
DataAccess channel_data (size_t channel) override
 Get channel data with semantic interpretation.
 
std::vector< DataAccessall_channel_data () override
 Get all channel data as accessors.
 
- Public Member Functions inherited from MayaFlux::Kakshya::StreamContainer
virtual ~StreamContainer ()=default
 
- Public Member Functions inherited from MayaFlux::Kakshya::SignalSourceContainer
 ~SignalSourceContainer () override=default
 
- Public Member Functions inherited from MayaFlux::Kakshya::NDDataContainer
virtual ~NDDataContainer ()=default
 

Protected Member Functions

void setup_dimensions ()
 
void notify_state_change (ProcessingState new_state)
 
void reorganize_data_layout (MemoryLayout new_layout)
 
const std::vector< std::span< double > > & get_span_cache () const
 Get the cached spans for each channel, recomputing if dirty.
 
void invalidate_span_cache ()
 Invalidate the span cache when data or layout changes.
 

Protected Attributes

std::vector< DataVariantm_data
 
std::vector< DataVariantm_processed_data
 
std::atomic< int > m_processing_token_channel { -1 }
 
uint32_t m_sample_rate = 48000
 
uint32_t m_num_channels {}
 
uint64_t m_num_frames {}
 
std::vector< std::atomic< uint64_t > > m_read_position
 
bool m_looping_enabled = false
 
Region m_loop_region
 
bool m_circular_mode {}
 
uint64_t m_circular_write_position {}
 
std::atomic< ProcessingStatem_processing_state { ProcessingState::IDLE }
 
std::shared_ptr< DataProcessorm_default_processor
 
std::shared_ptr< DataProcessingChainm_processing_chain
 
std::unordered_map< std::string, RegionGroupm_region_groups
 
std::unordered_map< uint32_t, int > m_active_readers
 
std::unordered_set< uint32_t > m_consumed_dimensions
 
std::unordered_map< uint32_t, std::unordered_set< uint32_t > > m_reader_consumed_dimensions
 
std::unordered_map< uint32_t, uint32_t > m_dimension_to_next_reader_id
 
std::function< void(std::shared_ptr< SignalSourceContainer >, ProcessingState)> m_state_callback
 
std::shared_mutex m_data_mutex
 
std::mutex m_state_mutex
 
std::mutex m_reader_mutex
 
std::vector< double > m_cached_ext_buffer
 
std::atomic< bool > m_double_extraction_dirty { true }
 
std::mutex m_extraction_mutex
 
ContainerDataStructure m_structure
 

Private Attributes

std::optional< std::vector< std::span< double > > > m_span_cache
 
std::atomic< bool > m_span_cache_dirty { true }
 

Detailed Description

Concrete base implementation for streaming audio containers.

SoundStreamContainer provides a complete, concrete implementation of all StreamContainer functionality for audio data. It serves as:

  1. A standalone streaming container for real-time audio processing
  2. A base class for specialized containers like SoundFileContainer

The container implements all common audio streaming operations including:

  • Region management and processing state tracking
  • Sequential reading with looping support
  • Multi-dimensional data access and coordinate mapping
  • Processing chain integration and reader tracking
  • Memory layout optimization and data reorganization

Uses virtual inheritance to support diamond inheritance when used as a base for FileContainer-derived classes.

Definition at line 27 of file SoundStreamContainer.hpp.


The documentation for this class was generated from the following files: