Skip to content

Commit 750410f

Browse files
authored
Merge pull request #38 from AudioKit/pass-max-frames-to-render
Pass maxFramesToRender to DSP at allocation time
2 parents 6f31de5 + 99d2002 commit 750410f

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

Sources/AudioKitEX/AudioKitAU.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ open class AudioKitAU: AUAudioUnit {
3939
}
4040

4141
if let outputFormat = outputBusArray.first?.format {
42-
allocateRenderResourcesDSP(dsp, outputFormat.channelCount, outputFormat.sampleRate)
42+
allocateRenderResourcesDSP(dsp, outputFormat.channelCount, outputFormat.sampleRate, maximumFramesToRender)
4343
}
4444
}
4545

Sources/CAudioKitEX/Internals/DSPBase.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ void setBufferDSP(DSPRef pDSP, AudioBufferList* buffer, size_t busIndex)
2525
pDSP->setBuffer(buffer, busIndex);
2626
}
2727

28-
void allocateRenderResourcesDSP(DSPRef pDSP, uint32_t channelCount, double sampleRate)
28+
void allocateRenderResourcesDSP(DSPRef pDSP, uint32_t channelCount, double sampleRate, AUAudioFrameCount maxFramesToRender)
2929
{
30+
pDSP->setMaximumFramesToRender(maxFramesToRender);
3031
pDSP->init(channelCount, sampleRate);
3132
}
3233

Sources/CAudioKitEX/include/DSPBase.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ size_t inputBusCountDSP(DSPRef pDSP);
1818
bool canProcessInPlaceDSP(DSPRef pDSP);
1919

2020
void setBufferDSP(DSPRef pDSP, AudioBufferList* buffer, size_t busIndex);
21-
void allocateRenderResourcesDSP(DSPRef pDSP, uint32_t channelCount, double sampleRate);
21+
void allocateRenderResourcesDSP(DSPRef pDSP, uint32_t channelCount, double sampleRate, AUAudioFrameCount maxFramesToRender);
2222
void deallocateRenderResourcesDSP(DSPRef pDSP);
2323
void resetDSP(DSPRef pDSP);
2424

@@ -89,6 +89,7 @@ struct DSPBase {
8989

9090
int channelCount;
9191
double sampleRate;
92+
AUAudioFrameCount maximumFramesToRender = 0;
9293

9394
bool isInitialized = false;
9495

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

136137
void setBuffer(AudioBufferList* buffer, size_t busIndex);
138+
139+
/// Set by AudioKitAU from AUAudioUnit.maximumFramesToRender before init().
140+
/// Subclasses may read `maximumFramesToRender` in their init() override to
141+
/// pre-size scratch buffers to the worst-case render size.
142+
void setMaximumFramesToRender(AUAudioFrameCount frames) { maximumFramesToRender = frames; }
143+
AUAudioFrameCount getMaximumFramesToRender() const { return maximumFramesToRender; }
137144
size_t getInputBusCount() const { return inputBufferLists.size(); }
138145

139146
virtual AUAudioFrameCount framesToPull(AUAudioFrameCount requestedOutputFrameCount) { return requestedOutputFrameCount; };

0 commit comments

Comments
 (0)