C-backed AudioKit DSP

Related tags

Audio AudioKitEX
Overview

AudioKitEX

Build Status License Platform Reviewed by Hound Twitter Follow

This extension to AudioKit contains all of the AudioKit features that rely on C/C++ DSP.

Documentation

The documentation appears in the Wiki

Examples

See the AudioKit Cookbook for examples.

Installation in Xcode 13

You can AudioKit and any of the other AudioKit libraries using Collections

  1. Select File -> Add Packages...
  2. Click the + icon on the bottom left of the Collections sidebar on the left.
  3. Choose Add Swift Package Collection from the pop-up menu.
  4. In the Add Package Collection dialog box, enter https://swiftpackageindex.com/AudioKit/collection.json as the URL and click the "Load" button.
  5. It will warn you that the collection is not signed, but it is fine, click "Add Unsigned Collection".
  6. Now you can add any of the AudioKit Swift Packages you need and read about what they do, right from within Xcode.
Comments
  • AudioKitEx Sequencer not playing first note, issues adding notes while playing

    AudioKitEx Sequencer not playing first note, issues adding notes while playing

    From @kenwheeler Original Ticket: AudioKit/AudioKit#2727

    Describe the bug I'm witnessing two issues with the Sequencer.

    1. When I have two tracks, and add a note at 0.0 for each:
    
    conductor.sequencer.tracks[selected].sequence.add(noteNumber: 60, position: Double((index)) * 0.25, duration: 1.0)
    

    I'm seeing that the first note of the second track isn't played. All subsequent notes play alright.

    2. When adding notes programmatically using the same API above, _while the sequencer is playing_, I'm hearing offset note timings. If I stop the sequencer and restart it, the timing is correct.
    

    To Reproduce Steps to reproduce the behavior:

    1. Add two notes programmatically using the above API at the 0.0 position and play with looping enabled
    
    2. For the other issue, use the same API as above to add notes programmatically while the sequencer is playing
    

    Expected behavior I would expect a) two tracks, each with a note at 0.0 position to be able to play simultaneously. and b) I would expect notes added when the sequencer is playing to be time accurate in the current play context.

    Screenshots If applicable, add screenshots to help explain your problem.

    Details (please complete the following information):

    * Type: [e.g. iPhone6, iPad, Mac] iPhone 13 pro
    
    * OS: [e.g. iOS13.1] iOS 15.4.1
    
    * AudioKit Version [e.g. 5.0] 5.3.3,
      **Other Context**
      I'm using samplers.
    

    p.s. Thanks so much, this project rules

    opened by emurray2 5
  • Callback instrument high CPU usage even without using it

    Callback instrument high CPU usage even without using it

    I've recently switched from the AppleSequencer to the Sequencer in order to build a metronome app (I was having the long-standing first measure bug with it).

    Strangely, I was seeing the CPU usage going up a lot after the switch. After isolating various part of the code, it seems that using the CallbackInstrument was the cause of all this.

    Is there something going on there? Here's a capture of Time Profiler, it seems that multiple threads are spawned.

    Capture d’écran 2022-01-17 à 13 31 51

    Here's the sample code I'm using if you want to test on your side.

    Using AudioKit 5.3.0.

    import AudioKit
    import AudioKitEX
    import UIKit
    
    class ViewController: UIViewController {
    
        let engine = AudioEngine()
        let sequencer = Sequencer()
        var callbackTrack: SequencerTrack?
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            let callbacksInstrument = CallbackInstrument(midiCallback: { status, note, _ in
                print(status, note)
            })
            callbackTrack = sequencer.addTrack(for: callbacksInstrument)
            
            engine.output = callbacksInstrument
            try? engine.start()
        }
    
    }
    
    opened by jdanthinne 5
  • AppleSampler crash on DSPBase.mm

    AppleSampler crash on DSPBase.mm

    macOS Version(s) Used to Build

    macOS 12 Monterey

    Xcode Version(s)

    Xcode 13.4.1

    Description

    If noteOn events are called while loading AudioKit's AppleSampler() it can occasionally crash on line 121 of DSPBase.mm. Here is a test project to illustrate the crash: https://github.com/NickCulbertson/TestRenderBlock

    This is the current AUInternalRenderBlock:

    AUInternalRenderBlock DSPBase::internalRenderBlock()
    {
        return ^AUAudioUnitStatus(
            AudioUnitRenderActionFlags *actionFlags,
            const AudioTimeStamp       *timestamp,
            AUAudioFrameCount           frameCount,
            NSInteger                   outputBusNumber,
            AudioBufferList            *outputData,
            const AURenderEvent        *realtimeEventListHead,
            AURenderPullInputBlock __unsafe_unretained pullInputBlock)
        {
    
            assert( (outputBusNumber == 0) && "We don't yet support multiple output busses" );
            if (pullInputBlock) {
                if (bCanProcessInPlace && inputBufferLists.size() == 1) {
                    // pull input directly to output buffer
                    inputBufferLists[0] = outputData;
                    AudioUnitRenderActionFlags inputFlags = 0;
                    pullInputBlock(&inputFlags, timestamp, frameCount, 0, inputBufferLists[0]);
                }
                else {
                    // pull input to internal buffer
                    for (size_t i = 0; i < inputBufferLists.size(); i++) {
                        inputBufferLists[i] = internalBufferLists[i];
                        
                        UInt32 byteSize = frameCount * 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]);  //CRASH HERE
                    }
                }
            }
            
            outputBufferList = outputData;
            
            processWithEvents(timestamp, frameCount, realtimeEventListHead);
            
            return noErr;
        };
    }
    

    Just a thought, but this is Apple's generated render block in DSPKernel when making an AUv3. It might be useful for comparison:

    // MARK: -  AUAudioUnit (AUAudioUnitImplementation)
    
    // Subclassers must provide a AUInternalRenderBlock (via a getter) to implement rendering.
    - (AUInternalRenderBlock)internalRenderBlock {
        /*
         Capture in locals to avoid ObjC member lookups. If "self" is captured in
         render, we're doing it wrong.
         */
        // Specify captured objects are mutable.
        __block OverdriveSynthDSPKernel *state = &_kernel;
        __block BufferedInputBus *input = &_inputBus;
    
        return ^AUAudioUnitStatus(AudioUnitRenderActionFlags 				*actionFlags,
                                  const AudioTimeStamp       				*timestamp,
                                  AVAudioFrameCount           				frameCount,
                                  NSInteger                   				outputBusNumber,
                                  AudioBufferList            				*outputData,
                                  const AURenderEvent        				*realtimeEventListHead,
                                  AURenderPullInputBlock __unsafe_unretained pullInputBlock) {
    
            AudioUnitRenderActionFlags pullFlags = 0;
    
            if (frameCount > state->maximumFramesToRender()) {
                return kAudioUnitErr_TooManyFramesToProcess;
            }
    
            AUAudioUnitStatus err = input->pullInput(&pullFlags, timestamp, frameCount, 0, pullInputBlock);
    
            if (err != noErr) { return err; }
    
            AudioBufferList *inAudioBufferList = input->mutableAudioBufferList;
    
            /*
             Important:
             If the caller passed non-null output pointers (outputData->mBuffers[x].mData), use those.
    
             If the caller passed null output buffer pointers, process in memory owned by the Audio Unit
             and modify the (outputData->mBuffers[x].mData) pointers to point to this owned memory.
             The Audio Unit is responsible for preserving the validity of this memory until the next call to render,
             or deallocateRenderResources is called.
    
             If your algorithm cannot process in-place, you will need to preallocate an output buffer
             and use it here.
    
             See the description of the canProcessInPlace property.
             */
    
            // If passed null output buffer pointers, process in-place in the input buffer.
            AudioBufferList *outAudioBufferList = outputData;
            if (outAudioBufferList->mBuffers[0].mData == nullptr) {
                for (UInt32 i = 0; i < outAudioBufferList->mNumberBuffers; ++i) {
                    outAudioBufferList->mBuffers[i].mData = inAudioBufferList->mBuffers[i].mData;
                }
            }
    
            state->setBuffers(inAudioBufferList, outAudioBufferList);
            state->processWithEvents(timestamp, frameCount, realtimeEventListHead, nil /* MIDIOutEventBlock */);
    
            return noErr;
        };
    }
    
    bug 
    opened by NickCulbertson 3
  • Sequencer not triggering note off at the end of the loop

    Sequencer not triggering note off at the end of the loop

    Issue opened by @Truba Opening here because this is an AudioKitEX issue - may be related to #10 Original Ticket: AudioKit/AudioKit#2536

    Full description

    Hi guys, Sry for not opening in the stack overflow first, but I'm pretty sure something is wrong here.

    Describe the bug / Expected behavior

    Sequencer doesn't seem to be triggering note off events if the note off event is placed at the end of the track loop. Here we have an example with just that:

    let sequencer = Sequencer()
    let track = sequencer.addTrack(for: sampler)
    track.loopEnabled = true
    track.length = 4
    track.sequence.add(noteNumber: someNote, position: 3, duration: 1)
    

    I'm creating a sequencer that outputs to sampler, and I'm also adding just one note. I'm expecting this one note to trigger 2 events. Note On at position 3 and note Off at position 4. But only the note On at position 3 is triggered, note Off at position 4 is missing.

    To Reproduce is Cookbook

    I can also replicate is by slightly modifying the Shaker example in Cookbook: https://gist.github.com/Truba/d36ee294817446aac082d929cf3adb7d

    I've updated both tracks to use longer duration, and I've updated CallbackInstrument to print the on/off state as well. In the print you can see that Off event is missing for beat at position 3.

    Where the issue might lie

    I'm pretty sure the issue lies somewhere around here:

    https://github.com/AudioKit/AudioKit/blob/4c3f5ef1b7d758609c7cfbc2d1f631fc45da04d1/Sources/CAudioKitEX/Sequencing/SequencerEngine.mm#L178

    I've tried tinkering with it a bit, but without success. This was my idea, it seems to work for the first loop, but it doesn't work for any consecutive loops.

    int time = (triggerTime >= lengthInSamples()) ? triggerTime - lengthInSamples() : triggerTime;
    if (time < samplesOfBufferForNewLoop) {
          int offset = (int)time + loopRestartInBuffer;
    

    Details (please complete the following information):

    * Type: iPhone 12 Pro, iPad Pro 9.7
    
    * OS: iOS 14.5
    
    * AudioKit Version 5.2
    
    opened by emurray2 1
  • Sequencer Cleanup

    Sequencer Cleanup

    Moves some funcs to sequencerTrack directly, marks the old ones as deprecated, and makes some other sequence track editing from within the sequencer more consistent.

    opened by eljeff 1
  • Develop

    Develop

    opened by mzF414 0
  • Sequencer check trackbounds notes

    Sequencer check trackbounds notes

    Changes:

    1. Add totalDuration getter in Sequence.swift
    2. Update totalDuration every time a new note event is added in Sequence.swift
    3. Add property observer to sequence in SequencerTrack.swift
    4. Add warnings and change the track length if the totalDuration exceeds the bounds of the track
    5. Add testNoteBounds() with passing MD5
    6. Update Package.resolved to current AK
    7. Add totalDuration to NoteEventSequence initializer
    8. Change testAdd() to use new initializer

    This should help with #10 and #12

    opened by emurray2 0
  • Revert CallbackInstrument timer to NSTimer

    Revert CallbackInstrument timer to NSTimer

    This reverts the changes made here: https://github.com/AudioKit/AudioKit/pull/2632.

    The CallbackInstrument is now using NSTimer back again, but with a run loop depending on the thread the instrument was instantiated.

    This could fix https://github.com/AudioKit/AudioKitEX/issues/5.

    opened by jdanthinne 0
  • pass maxFramesToRender to DSPBase::init

    pass maxFramesToRender to DSPBase::init

    Is your feature request related to a problem? Please describe.

    An AudioUnit will often need to know the maximum buffer size that will be requested for rendering. AudioKit doesn't provide this.

    Describe the solution you'd like

    maxFramesToRender should be passed to DSPBase::init.

    Describe alternatives you've considered

    This information could possibly be grabbed from the size of the output buffers but that is inelegant.

    Are there examples for this somewhere in the code?

    opened by wtholliday 0
  • Potential issue with upcoming Swift 5.7/Nightly toolchain

    Potential issue with upcoming Swift 5.7/Nightly toolchain

    Describe the bug Note that this is more of a "heads up" issue; I don't know if they will actually apply once Swift 5.7 and Xcode 14 exit beta. It may necessitate a maintainer of AudioKitEX filing a Radar issue.


    When building any application that has a dependency on AudioKitEX with the upcoming Swift 5.7 or nightly Swift toolchains in Xcode 14.0 beta, the build will fail when attempting to build the CAudioKitEX component with the following error in DSPBase.h:133:

    Screen Shot 2022-06-07 at 12 07 20

    This issue is present in both the release and main branch versions of AudioKitEX.

    To Reproduce Steps to reproduce the behavior:

    1. Install Xcode 14 beta.
    2. Install either the trunk snapshot or the Swift 5.7 development snapshot.
    3. Open any project that uses AudioKitEX, such as the AudioKit Cookbook.
    4. Select either one of the prerelease toolchains from the Xcode > Toolchains menu.
    5. Attempt to build the project using any scheme and target combination.
    6. The build will fail with the error from the screenshot.

    Author's note: My project doesn't use STKAudioKit, but another error was raised when I was recreating the issue with the Cookbook app. It was in Skini.cpp:142, and the error was Missing '#include <stdlib.h>'; 'atof' must be declared before it is used.

    Expected behavior The build should have completed and my application/Cookbook should have launched.

    Screenshots Error screenshot is in description of bug.

    Details (please complete the following information):

    • Type: 2021 MacBook Pro w/ M1 Pro CPU
    • OS: macOS Monterey 12.4
    • Xcode: 14.0 beta
    • Swift: Nightly and 5.7 development toolchains
    • AudioKit Version: Latest release and main branch

    Additional context I'm happy to provide any additional context, if necessary.

    opened by nhubbard 4
Releases(5.4.0)
Owner
AudioKit
AudioKit
AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS, and tvOS.

AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit 9.5k Dec 31, 2022
Microtonal Tuning Tables for AudioKit

Microtonal Tuning Tables for AudioKit These tuning tables were developed by Marcus Hobbs and used in the AudioKit Synth One iOS app. Installation via

AudioKit 11 Nov 23, 2022
AudioKit Sample Player (ROM Player) - EXS24, Sound Font, Wave Player

AudioKit ROM / Sample Player Welcome to the official AudioKit example of a sample-based music instrument written in Swift. It can be modified to play

AudioKit 500 Dec 27, 2022
AudioKit Synth One: Open-Source iOS Synthesizer App

AudioKit Synth One We've open-sourced the code for this synthesizer so that everyone is able to make changes to the code, introduce new features, fix

AudioKit 1.5k Dec 25, 2022
Swift Xcode Project that demonstrates how to set up a microphone input via AudioKit verions 5.

AudioKit Mic Input Swift Xcode Project that demonstrates how to set up a microphone input via AudioKit verions 5. Be sure to plug in headphones in ord

Mark Jeschke 0 Oct 23, 2021
🅿️ PandoraPlayer is a lightweight music player for iOS, based on AudioKit and completely written in Swift.

Made by Applikey Solutions Find this project on Dribbble Table of Contents Purpose Features Supported OS & SDK Versions Installation Usage Demo Releas

Applikey Solutions 1.1k Dec 26, 2022
AudioKit 67 Dec 21, 2022
A minimal AUv3 instrument example using AudioKit 5

AUv3 Instrument (AudioKit 5) A minimal AUv3 instrument example using AudioKit 5. Download the project, customize it however you like, and share your w

Nick Culbertson 24 Jan 4, 2023
Website for AudioKit documentation.

AudioKit.io audiokit.io hosts DocC documentation for all AudioKit packages. Running the Website The first and only thing we need to do is add a workin

AudioKit 3 Sep 5, 2022
Functional DSP / Audio Framework for Swift

Lullaby Lullaby is an audio synthesis framework for Swift that supports both macOS and Linux! It was inspired by other audio environments like FAUST,

Jae 16 Nov 5, 2022
Awesome Cache Delightful on-disk cache (written in Swift). Backed by NSCache for maximum performance

Awesome Cache Delightful on-disk cache (written in Swift). Backed by NSCache for maximum performance and support for expiry of single objects. Usage d

Alexander Schuch 1.3k Dec 29, 2022
SwiftStore - Key/Value store for Swift backed by LevelDB.

SwiftStore Key/Value store for Swift backed by LevelDB. Usage Create instances of store import SwiftStore

Hemant Sapkota 119 Dec 21, 2022
Key-Value store for Swift backed by LevelDB

SwiftStore Key/Value store for Swift backed by LevelDB. Usage Create instances of store import SwiftStore // Create a store. let store = SwiftStore(s

Hemanta Sapkota 119 Dec 21, 2022
A UICollectionView backed drop-in component for introduction views

#GHWalkThrough - iOS App Walk through control This is simple and customizable drop-in solution for showing app walkthroughs or intros. Configurable to

Gnosis Hub 717 Dec 15, 2022
A Flutter tourism app that is backed-by Redux, shows animations, internationalization (i18n, English <=> Arabic), ClipPath, and fonts

A Flutter tourism app that is backed-by Redux, shows animations, internationalization (i18n, English <=> Arabic), ClipPath, and fonts. YouTube demo I

Abdulmomen Kadum عبدالمؤمن كاظم 277 Dec 28, 2022
Detailed explanations and implementations of various maths concepts for writing high performance code/algorithms backed with Unit tests.

Detailed explanations and implementations of various maths concepts which can help software Engineers write high performance code/algorithms backed with Unit tests.

Mussa Charles 2 Sep 25, 2022
AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS, and tvOS.

AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit 9.5k Dec 31, 2022
Microtonal Tuning Tables for AudioKit

Microtonal Tuning Tables for AudioKit These tuning tables were developed by Marcus Hobbs and used in the AudioKit Synth One iOS app. Installation via

AudioKit 11 Nov 23, 2022
AudioKit Sample Player (ROM Player) - EXS24, Sound Font, Wave Player

AudioKit ROM / Sample Player Welcome to the official AudioKit example of a sample-based music instrument written in Swift. It can be modified to play

AudioKit 500 Dec 27, 2022
AudioKit Synth One: Open-Source iOS Synthesizer App

AudioKit Synth One We've open-sourced the code for this synthesizer so that everyone is able to make changes to the code, introduce new features, fix

AudioKit 1.5k Dec 25, 2022