Skip to content

Commit

Permalink
Merge pull request #26 from silvansky/feature/support-non-realtime-ef…
Browse files Browse the repository at this point in the history
…fects

Basic support for non-realtime effects
  • Loading branch information
aure authored Mar 21, 2024
2 parents 028c7b4 + c6e8487 commit 22f25ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Sources/AudioKitEX/Node+AudioKitAU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ public func instantiate(effect code: String) -> AVAudioNode {
public func instantiate(mixer code: String) -> AVAudioNode {
instantiate(componentDescription: AudioComponentDescription(mixer: code))
}

/// Create a non-realtime effect for the given unique identifier
/// - Parameter code: Unique four letter identifier
public func instantiate(nonRealTimeEffect code: String) -> AVAudioNode {
instantiate(componentDescription: AudioComponentDescription(nonRealTimeEffect: code))
}
11 changes: 8 additions & 3 deletions Sources/CAudioKitEX/Internals/DSPBase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ void deleteDSP(DSPRef pDSP)
{

assert( (outputBusNumber == 0) && "We don't yet support multiple output busses" );

AUAudioFrameCount inputFrameCount = framesToPull(frameCount);

assert( !(bCanProcessInPlace && (inputFrameCount != frameCount)) && "Can't process in place when inputFrameCount differs from frameCount" );

if (pullInputBlock) {
if (bCanProcessInPlace && inputBufferLists.size() == 1) {
if (bCanProcessInPlace && (inputBufferLists.size() == 1)) {
// pull input directly to output buffer
inputBufferLists[0] = outputData;
AudioUnitRenderActionFlags inputFlags = 0;
Expand All @@ -112,13 +117,13 @@ void deleteDSP(DSPRef pDSP)
for (size_t i = 0; i < inputBufferLists.size(); i++) {
inputBufferLists[i] = internalBufferLists[i];

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

AudioUnitRenderActionFlags inputFlags = 0;
pullInputBlock(&inputFlags, timestamp, frameCount, i, inputBufferLists[i]);
pullInputBlock(&inputFlags, timestamp, inputFrameCount, i, inputBufferLists[i]);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/CAudioKitEX/include/DSPBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ struct DSPBase {
void setBuffer(AudioBufferList* buffer, size_t busIndex);
size_t getInputBusCount() const { return inputBufferLists.size(); }

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

/// Render function.
virtual void process(FrameRange range) = 0;

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

if (midiEvent.length != 3) return;
uint8_t status = midiEvent.data[0] & 0xF0;
uint8_t channel = midiEvent.data[0] & 0x0F;
switch (status) {
case MIDI_NOTE_ON : {
uint8_t note = midiEvent.data[1];
Expand Down

0 comments on commit 22f25ea

Please sign in to comment.