1

I have an Audiokit prototype working that uses Audiobus on iOS. I am loading an effects delay, input, AudioKit output, mixer, etc. in a view controller and everything works as expected.

I am now trying to refactor to use the MVC pattern. I created a Conductor class, and a delay class. I moved the Audiokit start, Audiobus start, etc. into the conductor. I get no errors on build or run. I also get no audio passing through at this point.

The Delay is just the example MultiDelay and is setup deriving AKNode, and AKInput.

Am I overlooking something simple on this?

Example MVC Audiokit

ViewController ...

import AudioKit
import AudioKitUI
import UIKit

class ViewController: UIViewController {

// Create instance of Conductor
let conductor = Conductor.sharedInstance

/// Views
let stackView = UIStackView()
/// Views

override func viewDidLoad() {
    super.viewDidLoad()

    setupUI()
}

func setupUI() {

    stackView.axis = .vertical
    stackView.distribution = .fillEqually
    stackView.alignment = .fill
    stackView.translatesAutoresizingMaskIntoConstraints = false
    stackView.spacing = 10

    /// Delay
    // Simple Delay
    // Range and Type = Delay time in seconds (Default: 1)
    stackView.addArrangedSubview(AKRotaryKnob(
        property: "Simple Delay Time",
        value: conductor.delay.time,
        format: "%0.2f s") { sliderValue in
            self.conductor.delay.time = sliderValue
    })
    // Range and Type = Feedback (Normalized Value) ranges from 0 to 1 (Default: 0.5)
    stackView.addArrangedSubview(AKRotaryKnob(
        property: "Simple Delay Feedback",
        value: conductor.delay.feedback,
        range: 0.0 ... 0.99,
        format: "%0.2f s") { sliderValue in
            self.conductor.delay.feedback = sliderValue
    })
    // Range and Type = Dry/Wet Mix (Normalized Value) ranges from 0 to 1 (Default: 0.5)
    stackView.addArrangedSubview(AKSlider(
        property: "Simple Delay Dry/Wet Mix",
        value: self.conductor.delayDrMixer.balance,
        range: 0.0 ... 0.99,
        format: "%0.2f") { sliderValue in
            self.conductor.delayDrMixer.balance = sliderValue
    })

    stackView.addArrangedSubview(AKSlider(
       property: "Output Volume",
       value: conductor.booster.gain,
       range: 0 ... 2,
       format: "%0.2f") { sliderValue in
           self.conductor.booster.gain = sliderValue
   })
   /// Output Volume Section

   view.addSubview(stackView)

   stackView.widthAnchor.constraint(equalTo: self.view.widthAnchor, multiplier: 0.9).isActive = true
   stackView.heightAnchor.constraint(equalTo: self.view.heightAnchor, multiplier: 0.9).isActive = true
   stackView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
   stackView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
   }
}

Conductor...

import Foundation
import AudioKit

class Conductor: AKMIDIListener {

     // Globally accessible singleton
    static let sharedInstance = Conductor()
    let input = AKStereoInput()

    // Simple Delay
    // Example using AudioKit class but you could use your own 
    // custom class instead.
    var delay: AKDelay!  
    var delayDrMixer: AKDryWetMixer!

    var booster: AKBooster!
    var mixer = AKMixer()

    init() {
        AKSettings.audioInputEnabled = true

        // Simple Delay
        delay = AKDelay(input) // Route audio input into delay node
        delayDrMixer = AKDryWetMixer(input, delay) // route input and delay into dry wet mixer

        // Master Mixer
        mixer = AKMixer(delayDrMixer) // Route audio int final mix node

        // Set Output & Start AudioKit
        AudioKit.output = mixer // route mix to output
        do {
            try AudioKit.start()
        } catch {
            AKLog("Audiokit start failed")
        }
        Audiobus.start()
   }
}
  • Please include some codes if possible. – Mahib Apr 17 '18 at 20:04
  • After some cleanup and a reboot it resolved itself. Not sure how, no code was changed. – Glenn Seagraves Apr 18 '18 at 03:36
  • I would still recommend the codes and solution of the problem. Anyone else come across the issue can look into these solution. Thanks. – Mahib Apr 18 '18 at 03:42
  • I added a code example above. Let me know if anyone has any questions. This is pretty basic but as you can see in the ViewController there is no business logic. Just controls to change properties on objects in a Conductor class. – Glenn Seagraves Apr 18 '18 at 18:32
  • Please put your solution as an answer. So you will get points on both.. – Mahib Apr 18 '18 at 20:02

0 Answers0