Audiokit Audiobus MVC No Sound

时间:2018-04-17 17:52:28

标签: audiokit audiobus

我有一个在iOS上使用Audiobus的Audiokit原型。我正在视图控制器中加载效果延迟,输入,AudioKit输出,混音器等,一切都按预期工作。

我现在正在尝试重构使用MVC模式。我创建了一个Conductor类和一个延迟类。我把Audiokit开始,Audiobus开始等等转移到指挥。我在构建或运行时没有错误。此时我也没有通过音频。

延迟只是MultiDelay的示例,设置为派生AKNode和AKInput。

我忽略了一些简单的事情吗?

示例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
   }
}

...导体

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()
   }
}

0 个答案:

没有答案