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

◆ load_audio()

std::shared_ptr< Kakshya::SoundFileContainer > MayaFlux::IO::IOManager::load_audio ( const std::string &  filepath,
VideoLoadConfig  config = {} 
)

Load an audio file into a SoundFileContainer.

Performs can_read check, opens the file, creates and populates the container, and configures the default ContiguousAccessProcessor with auto_advance enabled.

Parameters
filepathPath to the audio file.
configLoadConfig struct containing audio read options.
Returns
Loaded SoundFileContainer, or nullptr on failure.

Definition at line 420 of file IOManager.cpp.

421{
422 auto reader = std::make_shared<IO::SoundFileReader>();
423
424 if (!reader->can_read(filepath)) {
425 MF_ERROR(Journal::Component::API, Journal::Context::FileIO, "Cannot read file: {}", filepath);
426 return nullptr;
427 }
428
429 reader->set_target_sample_rate(m_stream_info.sample_rate);
430 reader->set_audio_options(config.audio_options);
431
432 if (!reader->open(filepath, config.file_options)) {
433 MF_ERROR(Journal::Component::API, Journal::Context::FileIO, "Failed to open file: {}", reader->get_last_error());
434 return nullptr;
435 }
436
437 auto container = reader->create_container();
438 auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container);
439 if (!sound_container) {
440 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to create sound container");
441 return nullptr;
442 }
443
444 if (!reader->load_into_container(sound_container)) {
445 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to load audio data: {}", reader->get_last_error());
446 return nullptr;
447 }
448
449 configure_audio_processor(sound_container);
450
451 m_audio_readers.push_back(std::move(reader));
452
453 return sound_container;
454}
#define MF_ERROR(comp, ctx,...)
void configure_audio_processor(const std::shared_ptr< Kakshya::SoundFileContainer > &container) const
Core::GlobalStreamInfo & m_stream_info
std::vector< std::shared_ptr< SoundFileReader > > m_audio_readers
@ FileIO
Filesystem I/O operations.
@ Runtime
General runtime operations (default fallback)
@ API
MayaFlux/API Wrapper and convenience functions.
uint32_t sample_rate
Number of samples processed per second (Hz)

References MayaFlux::Journal::API, MayaFlux::IO::VideoLoadConfig::audio_options, configure_audio_processor(), MayaFlux::IO::VideoLoadConfig::file_options, MayaFlux::Journal::FileIO, m_audio_readers, m_stream_info, MF_ERROR, MayaFlux::Journal::Runtime, and MayaFlux::Core::GlobalStreamInfo::sample_rate.

+ Here is the call graph for this function: