Using AudioKit with Objective-C

211 views
Skip to first unread message

Denis Delbecq

unread,
Sep 22, 2017, 3:15:40 PM9/22/17
to AudioKit Users Group
Hello.

I would like to add waveform plot features to my sound recorder/player, using Objective-C (I started using it on a NeXT in late 1990… so my brain is quite designed for it and not for swift, I'm afraid). I discovered the AudioKit 4 which seems a great framework, and I imported the AudioKit & AudioKitUI frameworks from audiokit.io website. I am using Xcode 9 with iOS10.0 target. Unfortunately I cannot initialize some classes from the AudioKit in my objective-C code... For example, to create an AKAudioPlayer instance, I use:

    AKAudioFile *audioFile = [[AKAudioFile alloc] initForReading: myURL error:&error];  
    AKAudioPlayer* playerAK = [[AKAudioPlayer alloc] initWithFile:audioFile looping:NO deferBuffering:false completionHandler:nil];


From what I understand from Apple documentation on using swift framework in Objective-C, I thought that the  initWithFile: looping: deferBuffering: completionHandler: was the good translation in objective-C from the swift init call defined in AKAudioPlayer.swift in AudioKit framework:

public init(file: AKAudioFile,
                looping: Bool = false,
                deferBuffering: Bool = false,
                completionHandler: AKCallback? = nil) throws...


The AKAudioFile object instantiation causes neither warning nor error. But on instantiation of AKAudioPlayer, the compiler returns an error, saying no interface declares the selector initWithFile: looping: deferBuffering: completionHandler:

What am I doing wrong? Thanks for help


Aurelius Prochazka Ph.D.

unread,
Sep 25, 2017, 6:06:36 AM9/25/17
to AudioKit Users Group
AudioKit v4.0.1 addresses quite a few of the not-available-in-objective-c issues that we introduced with Xcode9/AudioKit 4.  Maybe try that and see how far you get.  Fixing it usually just involves putting an @objc in front of the class or method name on the Swift side.

Aure

Denis Delbecq

unread,
Sep 25, 2017, 2:02:26 PM9/25/17
to AudioKit Users Group
Sorry for my precedent answer, which was erroneous. In fact with 4.0.1 I can call init method in objective C. For an unknown reason, when typing my code to create the AKAudioPlayer object, Xcode now proposes a definition slightly different from the swift definition (adding error parameter), as
initWithFile: looping: deferBuffering: error: completionHandler:

Thanks!

Denis Delbecq

unread,
Sep 25, 2017, 2:02:54 PM9/25/17
to AudioKit Users Group
It is corrected with 4.0.1. Thanks!


Le lundi 25 septembre 2017 12:06:36 UTC+2, Aurelius Prochazka Ph.D. a écrit :
Reply all
Reply to author
Forward
0 new messages