14namespace fs = std::filesystem;
18std::shared_ptr<MayaFlux::Kakshya::SoundFileContainer>
load_audio_file(
const std::string& filepath)
20 auto reader = std::make_unique<IO::SoundFileReader>();
23 if (!reader->can_read(filepath)) {
24 std::cerr <<
"Cannot read file: " << filepath <<
'\n';
29 reader->set_target_bit_depth(64);
33 if (!reader->open(filepath, options)) {
38 auto container = reader->create_container();
39 auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container);
40 if (!sound_container) {
47 if (!reader->load_into_container(sound_container)) {
52 auto existing_processor = std::dynamic_pointer_cast<Kakshya::ContiguousAccessProcessor>(
53 sound_container->get_default_processor());
55 if (existing_processor) {
57 existing_processor->set_output_size(output_shape);
58 existing_processor->set_auto_advance(
true);
64 auto processor = std::make_shared<Kakshya::ContiguousAccessProcessor>();
66 processor->set_output_size(output_shape);
67 processor->set_auto_advance(
true);
69 sound_container->set_default_processor(processor);
75 "Loaded audio file: {} | Channels: {} | Frames: {} | Sample Rate: {} Hz",
77 sound_container->get_num_channels(),
78 sound_container->get_num_frames(),
79 sound_container->get_sample_rate());
81 return sound_container;
87 uint32_t num_channels = container->get_num_channels();
88 std::vector<std::shared_ptr<Buffers::ContainerBuffer>> created_buffers;
93 "Setting up audio playback for {} channels...",
96 for (uint32_t channel = 0; channel < num_channels; ++channel) {
105 created_buffers.push_back(std::move(container_buffer));
110 "✓ Created buffer for channel {}",
114 return created_buffers;
121 if (!reader.
open(filepath)) {
123 "Failed to open image: {}", filepath);
129 if (!texture_buffer) {
131 "Failed to create texture buffer from: {}", filepath);
136 "Loaded image: {} ({}x{})",
137 fs::path(filepath).filename().
string(),
138 texture_buffer->get_width(),
139 texture_buffer->get_height());
141 return texture_buffer;
146 if (!fs::exists(filepath) || !fs::is_regular_file(filepath)) {
150 auto ext = filepath.extension().string();
151 std::ranges::transform(ext, ext.begin(),
152 [](
unsigned char c) { return std::tolower(c); });
154 static const std::unordered_set<std::string> image_extensions = {
155 ".png",
".jpg",
".jpeg",
".bmp",
".tga",
156 ".psd",
".gif",
".hdr",
".pic",
".pnm"
159 return image_extensions.contains(ext);
164 if (!fs::exists(filepath) || !fs::is_regular_file(filepath)) {
168 auto ext = filepath.extension().string();
169 std::ranges::transform(ext, ext.begin(),
170 [](
unsigned char c) { return std::tolower(c); });
172 static const std::unordered_set<std::string> audio_extensions = {
173 ".wav",
".aiff",
".aif",
".flac",
".ogg",
174 ".mp3",
".m4a",
".wma"
177 return audio_extensions.contains(ext);
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_TRACE(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
Audio file loading and container management API.
void initialize()
Initialize the buffer after construction.
AudioBuffer implementation backed by a StreamContainer.
std::shared_ptr< Buffers::TextureBuffer > create_texture_buffer()
Create a VKBuffer containing the loaded image pixel data.
bool open(const std::string &filepath, FileReadOptions options=FileReadOptions::ALL) override
Open a file for reading.
File reader for image formats (PNG, JPG, BMP, TGA, etc.)
static void initialize_ffmpeg()
Initialize FFmpeg libraries (thread-safe, called automatically).
@ AUDIO_BACKEND
Standard audio processing backend configuration.
uint32_t get_buffer_size()
Gets the buffer size from the default engine.
uint32_t get_sample_rate()
Gets the sample rate from the default engine.
FileReadOptions
Generic options for file reading behavior.
@ EXTRACT_METADATA
Extract file metadata.
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ BufferManagement
Buffer Management (Buffers::BufferManager, creating buffers)
@ FileIO
Filesystem I/O operations.
@ Runtime
General runtime operations (default fallback)
@ API
MayaFlux/API Wrapper and convenience functions.
@ ROW_MAJOR
C/C++ style (last dimension varies fastest)
std::shared_ptr< MayaFlux::Kakshya::SoundFileContainer > load_audio_file(const std::string &filepath)
Loads an audio file into a SoundFileContainer with automatic format detection.
bool is_image(const fs::path &filepath)
bool is_audio(const fs::path &filepath)
std::shared_ptr< Buffers::TextureBuffer > load_image_file(const std::string &filepath)
Loads an image file into a TextureBuffer.
std::shared_ptr< Buffers::BufferManager > get_buffer_manager()
Gets the buffer manager from the default engine.
std::vector< std::shared_ptr< Buffers::ContainerBuffer > > hook_sound_container_to_buffers(const std::shared_ptr< MayaFlux::Kakshya::SoundFileContainer > &container)
Connects a SoundFileContainer to the buffer system for immediate playback.
Main namespace for the Maya Flux audio engine.