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

◆ create_sampler()

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

Construct a built SamplingPipeline from an audio file.

Loads the file into a DynamicSoundStream via SoundFileReader::load_bounded, constructs a SamplingPipeline with engine globals (BufferManager, TaskScheduler, buffer size), calls build(), and returns the result.

The returned sampler is ready for play() and play_continuous() calls. Voice slots are allocated on demand via load().

Parameters
filepathPath to the audio file (any FFmpeg-supported format).
num_samplesNumber of samples to load from the file (default: 48000 * 5).
truncateTruncate stream to num_samples if true (default: true).
channelOutput channel index (default: 0).
max_dur_msOptional maximum duration to build the pipeline for (in milliseconds). Defaults to 0 which is infinite (the pipeline will run until the sampler is destroyed).
Returns
Built SamplingPipeline, or nullptr if the file could not be loaded.
auto kick = MayaFlux::create_sampler("kick.wav");
kick->play(0, kick->slice_from_stream());
auto pad = MayaFlux::create_sampler("pad.wav");
pad->load(0, pad->slice_from_stream()).speed = 0.5;
pad->play_continuous(0);
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

Definition at line 15 of file Rigs.cpp.

18{
19 auto stream = get_io_manager()->load_audio_bounded(filepath, num_samples, truncate);
20
21 if (!stream) {
22 MF_ERROR(Journal::Component::API, Journal::Context::FileIO,
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}
#define MF_ERROR(comp, ctx,...)
uint32_t channel
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, channel, MayaFlux::Journal::FileIO, get_buffer_manager(), MayaFlux::Config::get_buffer_size(), get_io_manager(), get_scheduler(), and MF_ERROR.

Referenced by MayaFlux::Core::BackendResourceManager::~BackendResourceManager().

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