Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for non-realtime effects #26

Merged
merged 3 commits into from
Mar 21, 2024
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
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