Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/AudioKitEX/AudioKitAU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ open class AudioKitAU: AUAudioUnit {
}

if let outputFormat = outputBusArray.first?.format {
allocateRenderResourcesDSP(dsp, outputFormat.channelCount, outputFormat.sampleRate)
allocateRenderResourcesDSP(dsp, outputFormat.channelCount, outputFormat.sampleRate, maximumFramesToRender)
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/CAudioKitEX/Internals/DSPBase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ void setBufferDSP(DSPRef pDSP, AudioBufferList* buffer, size_t busIndex)
pDSP->setBuffer(buffer, busIndex);
}

void allocateRenderResourcesDSP(DSPRef pDSP, uint32_t channelCount, double sampleRate)
void allocateRenderResourcesDSP(DSPRef pDSP, uint32_t channelCount, double sampleRate, AUAudioFrameCount maxFramesToRender)
{
pDSP->setMaximumFramesToRender(maxFramesToRender);
pDSP->init(channelCount, sampleRate);
}

Expand Down
9 changes: 8 additions & 1 deletion Sources/CAudioKitEX/include/DSPBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ size_t inputBusCountDSP(DSPRef pDSP);
bool canProcessInPlaceDSP(DSPRef pDSP);

void setBufferDSP(DSPRef pDSP, AudioBufferList* buffer, size_t busIndex);
void allocateRenderResourcesDSP(DSPRef pDSP, uint32_t channelCount, double sampleRate);
void allocateRenderResourcesDSP(DSPRef pDSP, uint32_t channelCount, double sampleRate, AUAudioFrameCount maxFramesToRender);
void deallocateRenderResourcesDSP(DSPRef pDSP);
void resetDSP(DSPRef pDSP);

Expand Down Expand Up @@ -89,6 +89,7 @@ struct DSPBase {

int channelCount;
double sampleRate;
AUAudioFrameCount maximumFramesToRender = 0;

bool isInitialized = false;

Expand Down Expand Up @@ -134,6 +135,12 @@ struct DSPBase {
std::atomic<bool> isStarted{true};

void setBuffer(AudioBufferList* buffer, size_t busIndex);

/// Set by AudioKitAU from AUAudioUnit.maximumFramesToRender before init().
/// Subclasses may read `maximumFramesToRender` in their init() override to
/// pre-size scratch buffers to the worst-case render size.
void setMaximumFramesToRender(AUAudioFrameCount frames) { maximumFramesToRender = frames; }
AUAudioFrameCount getMaximumFramesToRender() const { return maximumFramesToRender; }
size_t getInputBusCount() const { return inputBufferLists.size(); }

virtual AUAudioFrameCount framesToPull(AUAudioFrameCount requestedOutputFrameCount) { return requestedOutputFrameCount; };
Expand Down
Loading