39 std::function<
void(
const clap_event_header* event)>&& eventCallback,
40 std::function<
void(marvin::containers::BufferView<SampleType>)>&& blockCallback) {
41 const auto numChannels = buffer.getNumChannels();
42 auto** channelArray =
static_cast<SampleType**
>(alloca(
sizeof(SampleType*) * numChannels));
43 size_t lastEventIndex{ 0 };
44 auto*
const* rawBuff = buffer.getArrayOfWritePointers();
45 for (
size_t i = 0; i < buffer.getNumSamples(); ++i) {
46 if (eventContext.
next() && eventContext.
next()->time ==
static_cast<std::uint32_t
>(i)) {
47 while (eventContext.
next() && eventContext.
next()->time ==
static_cast<std::uint32_t
>(i)) {
48 eventCallback(eventContext.
next());
51 for (
size_t channel = 0; channel < numChannels; ++channel) {
52 auto* offsetChannelPtr = rawBuff[channel] +
static_cast<std::ptrdiff_t
>(lastEventIndex);
53 channelArray[channel] = offsetChannelPtr;
55 const auto numSamples = i - lastEventIndex;
56 marvin::containers::BufferView<SampleType> slice{ channelArray, buffer.getNumChannels(), numSamples };
61 const auto remaining =
static_cast<std::int64_t
>(buffer.getNumSamples()) -
static_cast<std::int64_t
>(lastEventIndex);
62 if (remaining <= 0)
return;
63 for (
size_t channel = 0; channel < numChannels; ++channel) {
64 auto* offsetChannelPtr = rawBuff[channel] +
static_cast<std::ptrdiff_t
>(lastEventIndex);
65 channelArray[channel] = offsetChannelPtr;
67 marvin::containers::BufferView<SampleType> slice{ channelArray, buffer.getNumChannels(),
static_cast<size_t>(remaining) };
void runBlockDispatch(marvin::containers::BufferView< SampleType > buffer, mostly_harmless::events::InputEventContext eventContext, std::function< void(const clap_event_header *event)> &&eventCallback, std::function< void(marvin::containers::BufferView< SampleType >)> &&blockCallback)
Splits an input buffer into chunks and dispatches them, allowing for block based processing.
Definition mostlyharmless_AudioHelpers.h:37