4

Note that this is NOT a duplicate of this SO Post because in that post only WHAT method to use is given but there's no example on HOW should I use it.

So, I have dug into AKOfflineRenderNode as much as I can and have viewed all examples I could find. However, my code never seemed to work correctly on iOS 10.3.1 devices(and other iOS 10 versions), for the result is always silent. I try to follow examples provided in other SO posts but no success. I try to follow that in SongProcessor but it uses an older version of Swift and I can't even compile it. Trying SongProcessor's way to use AKOfflineRenderNode didn't help either. It always turned out silent.

I created a demo project just to test this. Because I don't own the audio file I used to test with, I couldn't upload it to my GitHub. Please add an audio file named "Test" into the project before compiling onto an iOS 10.3.1 simulator. (And if your file isn't in m4a, remember to change the file type in code where I initialize AKPlayer)

If you don't want to download and run the sample, the essential part is here:

@IBAction func export() {
    // url, player, offlineRenderer and others are predefined and connected as player >> aPitchShifter >> offlineRenderer
    // AudioKit.output is already offlineRenderer

    offlineRenderer.internalRenderEnabled = false
    try! AudioKit.start()

    // I also tried using AKAudioPlayer instead of AKPlayer
    // Also tried getting time in these ways:
    // AVAudioTime.secondsToAudioTime(hostTime: 0, time: 0)
    // player.audioTime(at: 0)
    // And for hostTime I've tried 0 as well as mach_absolute_time()
    // None worked

    let time = AVAudioTime(sampleTime: 0, atRate: offlineRenderer.avAudioNode.inputFormat(forBus: 0).sampleRate)
    player.play(at: time)
    try! offlineRenderer.renderToURL(url, duration: player.duration)

    player.stop()
    player.disconnectOutput()
    offlineRenderer.internalRenderEnabled = true

    try? AudioKit.stop()
}
Nicholas
  • 747
  • 7
  • 23
  • How about posting the demo project onto github so that other people can test this? Its a lot to ask of the SO community to read the code and divine an answer for you. – Aurelius Prochazka Aug 26 '19 at 00:34
  • 1
    I have edited the question and added a sample project on GitHub. Thanks for the advice. @AureliusProchazka – Nicholas Aug 26 '19 at 04:11

0 Answers0