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

◆ create_samplers()

MAYAFLUX_API std::vector< std::shared_ptr< Kriya::SamplingPipeline > > MayaFlux::create_samplers ( const std::string &  filepath,
uint32_t  num_samples = 48000 *5,
bool  truncate = true,
uint64_t  max_dur_ms = 0,
uint32_t  max_channels = 0 
)

Construct one built SamplingPipeline per channel from an audio file.

Loads the file once into a shared DynamicSoundStream, then constructs one SamplingPipeline per channel. All pipelines share the same stream with no redundant IO. max_channels = 0 uses all channels available in the file.

auto ch = MayaFlux::create_samplers("res/stereo.wav", 48000 * 5);
ch[0]->play(0, ch[0]->slice_from_stream());
ch[1]->play(0, ch[1]->slice_from_stream());
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
Parameters
filepathPath to the audio file (any FFmpeg-supported format).
num_samplesNumber of samples to load (default: 48000 * 5).
truncateTruncate stream to num_samples if true (default: true).
max_dur_msOptional maximum duration in milliseconds. 0 for infinite.
max_channelsMaximum channels to create pipelines for. 0 = all available.
Returns
Vector of built SamplingPipelines, one per channel. Empty on load failure.

Definition at line 66 of file Rigs.cpp.

69{
70 auto stream = get_io_manager()->load_audio_bounded(filepath, num_samples, truncate);
71
72 if (!stream) {
73 MF_ERROR(Journal::Component::API, Journal::Context::FileIO,
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}
#define MF_ERROR(comp, ctx,...)
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::shared_ptr< IO::IOManager > get_io_manager()
Retrieves the global IOManager instance for file loading and buffer management.
Definition Depot.cpp:79

References MayaFlux::Journal::API, create_sampler_from_stream(), MayaFlux::Journal::FileIO, get_io_manager(), and MF_ERROR.

+ Here is the call graph for this function: