Devin Visslailli
Devin Visslailli

Reputation: 120

Using AudioKit to plot Waveform in UIView

I'm new to the iOS game, and I'm trying to use AudioKit to plot a output waveform graph. My input is the microphone. I was able to get a signal from the mic, but I'm not able to figure out how to set up a graph view, or how to access their plot data even.

This playground: http://audiokit.io/playgrounds/Output%20Waveform%20Plot/

Shows how to plot using liveView in the playground, but not how to convert that to a UIView. The only code I have is from that playground example.

Is there a way to turn a CGRect into a plotted real-time graph?

Any help would be appreciated! Even just pointing me in the right direction.

Upvotes: 3

Views: 3175

Answers (1)

John Memon
John Memon

Reputation: 21

This is from the audio kit example code. If you put this into your view's class, it should work. This is what has worked for me.

var mic: AKMicrophone!
var tracker: AKFrequencyTracker!
var silence: AKBooster!

@IBOutlet weak var audioInputPlot: EZAudioPlot!

override func viewDidLoad() {
    super.viewDidLoad()
    AKSettings.audioInputEnabled = true
    mic = AKMicrophone()
    tracker = AKFrequencyTracker(mic)
    silence = AKBooster(tracker, gain: 0)
    setupPlot()
}

func setupPlot() {
    let plot = AKNodeOutputPlot(mic, frame: audioInputPlot.bounds)
    plot.plotType = .rolling
    plot.shouldFill = true
    plot.shouldMirror = true
    plot.color = UIColor.blue
    audioInputPlot.addSubview(plot)
}

Upvotes: 2

Related Questions