Skip to content

Commit 096ed56

Browse files
committed
Support pulling more or less frames than requested in internalRenderBlock
1 parent 9ac80b2 commit 096ed56

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Sources/CAudioKitEX/Internals/DSPBase.mm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ void deleteDSP(DSPRef pDSP)
100100
{
101101

102102
assert( (outputBusNumber == 0) && "We don't yet support multiple output busses" );
103+
104+
AUAudioFrameCount inputFrameCount = framesToPull(frameCount);
105+
106+
assert( !(bCanProcessInPlace && (inputFrameCount != frameCount)) && "Can't process in place when inputFrameCount differs from frameCount" );
107+
103108
if (pullInputBlock) {
104-
if (bCanProcessInPlace && inputBufferLists.size() == 1) {
109+
if (bCanProcessInPlace && (inputBufferLists.size() == 1)) {
105110
// pull input directly to output buffer
106111
inputBufferLists[0] = outputData;
107112
AudioUnitRenderActionFlags inputFlags = 0;
@@ -112,13 +117,13 @@ void deleteDSP(DSPRef pDSP)
112117
for (size_t i = 0; i < inputBufferLists.size(); i++) {
113118
inputBufferLists[i] = internalBufferLists[i];
114119

115-
UInt32 byteSize = frameCount * sizeof(float);
120+
UInt32 byteSize = inputFrameCount * sizeof(float);
116121
for (UInt32 ch = 0; ch < inputBufferLists[i]->mNumberBuffers; ch++) {
117122
inputBufferLists[i]->mBuffers[ch].mDataByteSize = byteSize;
118123
}
119124

120125
AudioUnitRenderActionFlags inputFlags = 0;
121-
pullInputBlock(&inputFlags, timestamp, frameCount, i, inputBufferLists[i]);
126+
pullInputBlock(&inputFlags, timestamp, inputFrameCount, i, inputBufferLists[i]);
122127
}
123128
}
124129
}

Sources/CAudioKitEX/include/DSPBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ struct DSPBase {
136136
void setBuffer(AudioBufferList* buffer, size_t busIndex);
137137
size_t getInputBusCount() const { return inputBufferLists.size(); }
138138

139+
virtual AUAudioFrameCount framesToPull(AUAudioFrameCount requestedOutputFrameCount) { return requestedOutputFrameCount; };
140+
139141
/// Render function.
140142
virtual void process(FrameRange range) = 0;
141143

0 commit comments

Comments
 (0)