MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Rigs.cpp
Go to the documentation of this file.
1#include "Rigs.hpp"
2
7
10
12
13namespace MayaFlux {
14
15std::shared_ptr<Kriya::SamplingPipeline> create_sampler(
16 const std::string& filepath, uint32_t num_samples, bool truncate,
17 uint32_t channel, uint64_t max_dur_ms)
18{
19 auto stream = get_io_manager()->load_audio_bounded(filepath, num_samples, truncate);
20
21 if (!stream) {
23 "create_sampler: failed to load '{}'", filepath);
24 return nullptr;
25 }
26
27 auto& mgr = *get_buffer_manager();
28 auto& sched = *get_scheduler();
29 const uint32_t buf_size = Config::get_buffer_size();
30
31 auto sampler = std::make_shared<Kriya::SamplingPipeline>(
32 std::move(stream), mgr, sched, channel, buf_size);
33
34 if (max_dur_ms > 0) {
35 sampler->build_for(max_dur_ms);
36 } else {
37 sampler->build();
38 }
39
40 return sampler;
41}
42
43std::shared_ptr<Kriya::SamplingPipeline> create_sampler_from_stream(
44 std::shared_ptr<Kakshya::DynamicSoundStream> stream,
45 uint32_t channel, uint64_t max_dur_ms)
46{
47 if (!stream)
48 return nullptr;
49
50 auto& mgr = *get_buffer_manager();
51 auto& sched = *get_scheduler();
52 const uint32_t buf_size = Config::get_buffer_size();
53
54 auto sampler = std::make_shared<Kriya::SamplingPipeline>(
55 std::move(stream), mgr, sched, channel, buf_size);
56
57 if (max_dur_ms > 0) {
58 sampler->build_for(max_dur_ms);
59 } else {
60 sampler->build();
61 }
62
63 return sampler;
64}
65
66std::vector<std::shared_ptr<Kriya::SamplingPipeline>> create_samplers(
67 const std::string& filepath, uint32_t num_samples, bool truncate,
68 uint64_t max_dur_ms, uint32_t max_channels)
69{
70 auto stream = get_io_manager()->load_audio_bounded(filepath, num_samples, truncate);
71
72 if (!stream) {
74 "create_samplers: failed to load '{}'", filepath);
75 return {};
76 }
77
78 const uint32_t ch_count = (max_channels == 0)
79 ? stream->get_num_channels()
80 : std::min(max_channels, stream->get_num_channels());
81
82 std::vector<std::shared_ptr<Kriya::SamplingPipeline>> result;
83 result.reserve(ch_count);
84
85 for (uint32_t i = 0; i < ch_count; ++i)
86 result.push_back(create_sampler_from_stream(stream, i, max_dur_ms));
87
88 return result;
89}
90
91} // namespace MayaFlux
#define MF_ERROR(comp, ctx,...)
Audio file loading and container management API.
Pre-assembled, purpose-built signal flow configurations.
uint32_t channel
uint32_t get_buffer_size()
Gets the buffer size from the default engine.
Definition Config.cpp:72
@ FileIO
Filesystem I/O operations.
@ API
MayaFlux/API Wrapper and convenience functions.
std::shared_ptr< Kriya::SamplingPipeline > create_sampler(const std::string &filepath, uint32_t num_samples, bool truncate, uint32_t channel, uint64_t max_dur_ms)
Construct a built SamplingPipeline from an audio file.
Definition Rigs.cpp:15
std::shared_ptr< Kriya::SamplingPipeline > create_sampler_from_stream(std::shared_ptr< Kakshya::DynamicSoundStream > stream, uint32_t channel, uint64_t max_dur_ms)
Construct a built SamplingPipeline from an existing DynamicSoundStream.
Definition Rigs.cpp:43
std::vector< std::shared_ptr< Kriya::SamplingPipeline > > create_samplers(const std::string &filepath, uint32_t num_samples, bool truncate, uint64_t max_dur_ms, uint32_t max_channels)
Construct one built SamplingPipeline per channel from an audio file.
Definition Rigs.cpp:66
std::shared_ptr< Buffers::BufferManager > get_buffer_manager()
Gets the buffer manager from the default engine.
Definition Graph.cpp:133
std::shared_ptr< IO::IOManager > get_io_manager()
Retrieves the global IOManager instance for file loading and buffer management.
Definition Depot.cpp:79
std::shared_ptr< Vruta::TaskScheduler > get_scheduler()
Gets the task scheduler from the default engine.
Definition Chronie.cpp:22
Main namespace for the Maya Flux audio engine.
Definition Runtime.cpp:12