MayaFlux 0.4.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,
LoadConfig  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 263 of file IOManager.cpp.

264{
265 auto reader = std::make_shared<IO::SoundFileReader>();
266
267 if (!reader->can_read(filepath)) {
268 MF_ERROR(Journal::Component::API, Journal::Context::FileIO, "Cannot read file: {}", filepath);
269 return nullptr;
270 }
271
272 reader->set_target_sample_rate(m_stream_info.sample_rate);
273 reader->set_audio_options(config.audio_options);
274
275 if (!reader->open(filepath, config.file_options)) {
276 MF_ERROR(Journal::Component::API, Journal::Context::FileIO, "Failed to open file: {}", reader->get_last_error());
277 return nullptr;
278 }
279
280 auto container = reader->create_container();
281 auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container);
282 if (!sound_container) {
283 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to create sound container");
284 return nullptr;
285 }
286
287 if (!reader->load_into_container(sound_container)) {
288 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to load audio data: {}", reader->get_last_error());
289 return nullptr;
290 }
291
292 configure_audio_processor(sound_container);
293
294 m_audio_readers.push_back(std::move(reader));
295
296 return sound_container;
297}
#define MF_ERROR(comp, ctx,...)
Core::GlobalStreamInfo & m_stream_info
std::vector< std::shared_ptr< SoundFileReader > > m_audio_readers
void configure_audio_processor(const std::shared_ptr< Kakshya::SoundFileContainer > &container)
@ 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::LoadConfig::audio_options, configure_audio_processor(), MayaFlux::IO::LoadConfig::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: