Hi,
I'm finding difficult to run AudioKit with latest Swift 5.2 through XCode 11.4 (I understand the forum is about Swift only and so my question is just regarding the syntax I used). Is there a way to find a more useful error message? Or is the code syntax correct?
import SwiftUI
import AudioKit
struct ContentView: View {
var oscillator = AKOscillator()
var body: some View {
VStack {
Button("Play") {
self.playSound()
}
}.onAppear {
do {
AudioKit.output = self.oscillator
try AudioKit.start()
} catch {
print("audiokit init error")
}
}
}
private func playSound(){
self.oscillator.amplitude = 1
self.oscillator.frequency = 440
self.oscillator.start()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
My apologies if this is XCode or AudioKit related but been trying to get some support without much success for the past weeks and before moving on to something else, I just want to make sure there's nothing I can do. I've also used GitHub and pulled some projects but the few I found don't compile or are missing libs, the goal was to use to study it.
Moved the Audiokit code to a separate struct
, just to make sure:
// AudioPlayer.swift
import AudioKit
struct AudioPlayer {
var oscillator = AKOscillator()
init() {
do {
AudioKit.output = self.oscillator
try AudioKit.start()
} catch {
print("audiokit init error")
}
}
func playSound(){
self.oscillator.amplitude = 1
self.oscillator.frequency = 440
self.oscillator.start()
}
}
// ContentView.swift
import SwiftUI
struct ContentView: View {
var audioPlayer: AudioPlayer = AudioPlayer()
var body: some View {
VStack {
Button("Play") {
self.audioPlayer.playSound()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Thank you!