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

◆ load_audio_file()

MAYAFLUX_API std::shared_ptr< MayaFlux::Kakshya::SoundFileContainer > MayaFlux::load_audio_file ( const std::string &  filepath)

Loads an audio file into a SoundFileContainer with automatic format detection.

Parameters
filepathPath to the audio file to load
Returns
Shared pointer to loaded SoundFileContainer, or nullptr on failure

Provides comprehensive audio file loading with format detection, sample rate conversion, and bit depth optimization. Supports all FFmpeg formats including WAV, MP3, FLAC, OGG, etc. The container is immediately ready for use with buffer system integration. Returns nullptr on failure with error details logged to stderr.

Definition at line 18 of file Depot.cpp.

19{
20 auto reader = std::make_unique<IO::SoundFileReader>();
22
23 if (!reader->can_read(filepath)) {
24 std::cerr << "Cannot read file: " << filepath << '\n';
25 return nullptr;
26 }
27
28 reader->set_target_sample_rate(MayaFlux::Config::get_sample_rate());
29 reader->set_target_bit_depth(64);
30 reader->set_audio_options(IO::AudioReadOptions::DEINTERLEAVE);
31
32 IO::FileReadOptions options = IO::FileReadOptions::EXTRACT_METADATA;
33 if (!reader->open(filepath, options)) {
34 MF_ERROR(Journal::Component::API, Journal::Context::FileIO, "Failed to open file: {}", reader->get_last_error());
35 return nullptr;
36 }
37
38 auto container = reader->create_container();
39 auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container);
40 if (!sound_container) {
41 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to create sound container");
42 return nullptr;
43 }
44
45 sound_container->set_memory_layout(Kakshya::MemoryLayout::ROW_MAJOR);
46
47 if (!reader->load_into_container(sound_container)) {
48 MF_ERROR(Journal::Component::API, Journal::Context::Runtime, "Failed to load audio data: {}", reader->get_last_error());
49 return nullptr;
50 }
51
52 auto existing_processor = std::dynamic_pointer_cast<Kakshya::ContiguousAccessProcessor>(
53 sound_container->get_default_processor());
54
55 if (existing_processor) {
56 std::vector<uint64_t> output_shape = { MayaFlux::Config::get_buffer_size(), sound_container->get_num_channels() };
57 existing_processor->set_output_size(output_shape);
58 existing_processor->set_auto_advance(true);
59
60 MF_DEBUG(Journal::Component::API, Journal::Context::ContainerProcessing, "Configured existing ContiguousAccessProcessor");
61 } else {
62 MF_TRACE(Journal::Component::API, Journal::Context::ContainerProcessing, "No default processor found, creating a new ContiguousAccessProcessor");
63
64 auto processor = std::make_shared<Kakshya::ContiguousAccessProcessor>();
65 std::vector<uint64_t> output_shape = { MayaFlux::Config::get_buffer_size(), sound_container->get_num_channels() };
66 processor->set_output_size(output_shape);
67 processor->set_auto_advance(true);
68
69 sound_container->set_default_processor(processor);
70 }
71
72 MF_INFO(
73 Journal::Component::API,
74 Journal::Context::FileIO,
75 "Loaded audio file: {} | Channels: {} | Frames: {} | Sample Rate: {} Hz",
76 filepath,
77 sound_container->get_num_channels(),
78 sound_container->get_num_frames(),
79 sound_container->get_sample_rate());
80
81 return sound_container;
82}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_TRACE(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
static void initialize_ffmpeg()
Initialize FFmpeg libraries (thread-safe, called automatically).
uint32_t get_buffer_size()
Gets the buffer size from the default engine.
Definition Config.cpp:51
uint32_t get_sample_rate()
Gets the sample rate from the default engine.
Definition Config.cpp:46

References MayaFlux::Journal::API, MayaFlux::Journal::ContainerProcessing, MayaFlux::IO::DEINTERLEAVE, MayaFlux::IO::EXTRACT_METADATA, MayaFlux::Journal::FileIO, MayaFlux::Config::get_buffer_size(), MayaFlux::Config::get_sample_rate(), MayaFlux::IO::SoundFileReader::initialize_ffmpeg(), MF_DEBUG, MF_ERROR, MF_INFO, MF_TRACE, MayaFlux::Kakshya::ROW_MAJOR, and MayaFlux::Journal::Runtime.

Referenced by MayaFlux::Kriya::BufferOperation::capture_file(), MayaFlux::Kriya::BufferOperation::capture_file_from(), MayaFlux::Kriya::BufferOperation::file_to_stream(), and MayaFlux::Creator::load_container().

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