MayaFlux 0.2.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 216 of file IOManager.cpp.

217{
218 auto reader = std::make_shared<IO::SoundFileReader>();
219
220 if (!reader->can_read(filepath)) {
221 MF_ERROR(Journal::Component::API, Journal::Context::FileIO, "Cannot read file: {}", filepath);
222 return nullptr;
223 }
224
225 reader->set_target_sample_rate(m_sample_rate);
226 reader->set_audio_options(config.audio_options);
227
228 if (!reader->open(filepath, config.file_options)) {
229 MF_ERROR(Journal::Component::API, Journal::Context::FileIO, "Failed to open file: {}", reader->get_last_error());
230 return nullptr;
231 }
232
233 auto container = reader->create_container();
234 auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container);
235 if (!sound_container) {
236 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to create sound container");
237 return nullptr;
238 }
239
240 if (!reader->load_into_container(sound_container)) {
241 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to load audio data: {}", reader->get_last_error());
242 return nullptr;
243 }
244
245 configure_audio_processor(sound_container);
246
247 m_audio_readers.push_back(std::move(reader));
248
249 return sound_container;
250}
#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: