Skip to content

Commit 22f25ea

Browse files
authored
Merge pull request #26 from silvansky/feature/support-non-realtime-effects
Basic support for non-realtime effects
2 parents 028c7b4 + c6e8487 commit 22f25ea

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Sources/AudioKitEX/Node+AudioKitAU.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,9 @@ public func instantiate(effect code: String) -> AVAudioNode {
6363
public func instantiate(mixer code: String) -> AVAudioNode {
6464
instantiate(componentDescription: AudioComponentDescription(mixer: code))
6565
}
66+
67+
/// Create a non-realtime effect for the given unique identifier
68+
/// - Parameter code: Unique four letter identifier
69+
public func instantiate(nonRealTimeEffect code: String) -> AVAudioNode {
70+
instantiate(componentDescription: AudioComponentDescription(nonRealTimeEffect: code))
71+
}

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 & 1 deletion
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

@@ -168,7 +170,6 @@ struct DSPBase {
168170

169171
if (midiEvent.length != 3) return;
170172
uint8_t status = midiEvent.data[0] & 0xF0;
171-
uint8_t channel = midiEvent.data[0] & 0x0F;
172173
switch (status) {
173174
case MIDI_NOTE_ON : {
174175
uint8_t note = midiEvent.data[1];

0 commit comments

Comments
 (0)