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

◆ load_into_container()

bool MayaFlux::IO::SoundFileReader::load_into_container ( std::shared_ptr< Kakshya::SignalSourceContainer container)
overridevirtual

Load file data into an existing SignalSourceContainer.

Parameters
containerTarget container.
Returns
True if loading succeeded.

Implements MayaFlux::IO::FileReader.

Definition at line 815 of file SoundFileReader.cpp.

816{
817 if (!container) {
818 set_error("Invalid container");
819 return false;
820 }
821
822 auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container);
823 if (!sound_container) {
824 set_error("Container is not a SoundFileContainer");
825 return false;
826 }
827
828 auto metadata = get_metadata();
829 if (!metadata) {
830 set_error("Failed to get metadata");
831 return false;
832 }
833
834 auto total_frames = metadata->get_attribute<uint64_t>("total_frames").value_or(0);
835 auto sample_rate = metadata->get_attribute<uint32_t>("sample_rate").value_or(48000);
836 auto channels = metadata->get_attribute<uint32_t>("channels").value_or(2);
837
838 sound_container->setup(total_frames, sample_rate, channels);
839
841 sound_container->get_structure().organization = Kakshya::OrganizationStrategy::PLANAR;
842 } else {
843 sound_container->get_structure().organization = Kakshya::OrganizationStrategy::INTERLEAVED;
844 }
845
846 std::vector<Kakshya::DataVariant> audio_data = read_all();
847
848 if (audio_data.empty()) {
849 set_error("Failed to read audio data");
850 return false;
851 }
852
853 sound_container->set_raw_data(audio_data);
854
855 auto regions = get_regions();
856 auto region_groups = regions_to_groups(regions);
857 for (const auto& [name, group] : region_groups) {
858 sound_container->add_region_group(group);
859 }
860
861 sound_container->create_default_processor();
862 sound_container->mark_ready_for_processing(true);
863
864 return true;
865}
static std::unordered_map< std::string, Kakshya::RegionGroup > regions_to_groups(const std::vector< FileRegion > &regions)
Convert file regions to region groups.
std::vector< Kakshya::DataVariant > read_all() override
Read the entire audio file into memory.
void set_error(const std::string &error) const
Set the last error message.
AudioReadOptions m_audio_options
Audio-specific read options.
std::optional< FileMetadata > get_metadata() const override
Get metadata for the currently open file.
std::vector< FileRegion > get_regions() const override
Get all regions (markers, loops, etc.) from the file.
@ PLANAR
Separate DataVariant per logical unit (LLL...RRR for stereo)
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)

References MayaFlux::IO::DEINTERLEAVE, get_metadata(), get_regions(), MayaFlux::Kakshya::INTERLEAVED, m_audio_options, MayaFlux::IO::NONE, MayaFlux::Kakshya::PLANAR, read_all(), MayaFlux::IO::FileReader::regions_to_groups(), and set_error().

Referenced by create_container().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: