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 242 of file IOManager.cpp.

243{
244 auto reader = std::make_shared<IO::SoundFileReader>();
245
246 if (!reader->can_read(filepath)) {
247 MF_ERROR(Journal::Component::API, Journal::Context::FileIO, "Cannot read file: {}", filepath);
248 return nullptr;
249 }
250
251 reader->set_target_sample_rate(m_sample_rate);
252 reader->set_audio_options(config.audio_options);
253
254 if (!reader->open(filepath, config.file_options)) {
255 MF_ERROR(Journal::Component::API, Journal::Context::FileIO, "Failed to open file: {}", reader->get_last_error());
256 return nullptr;
257 }
258
259 auto container = reader->create_container();
260 auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container);
261 if (!sound_container) {
262 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to create sound container");
263 return nullptr;
264 }
265
266 if (!reader->load_into_container(sound_container)) {
267 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to load audio data: {}", reader->get_last_error());
268 return nullptr;
269 }
270
271 configure_audio_processor(sound_container);
272
273 m_audio_readers.push_back(std::move(reader));
274
275 return sound_container;
276}
#define MF_ERROR(comp, ctx,...)
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.

References MayaFlux::Journal::API, MayaFlux::IO::LoadConfig::audio_options, configure_audio_processor(), MayaFlux::IO::LoadConfig::file_options, MayaFlux::Journal::FileIO, m_audio_readers, m_sample_rate, MF_ERROR, and MayaFlux::Journal::Runtime.

+ Here is the call graph for this function: