AudioKit - Drawing full waveform of file
Asked Answered
U

2

6

I've been going through documentation looking for an answer for this. I see that AudioKit can draw waveforms for in realtime as you record or playback, but I was wondering if you could load in a file and it draw the waveform in full so I can see the whole file's waveform without playing it back.

Any help would be greatly appreciated. Even just a pointer to what object I should look into.

Upstretched answered 9/10, 2017 at 0:52 Comment(0)
T
5

You can also use the Objective C EZAudioPlot class which is in AudioKitUI:

let file = EZAudioFile(url: url)
guard let data = file?.getWaveformData() else { return }

let waveform = EZAudioPlot()
addSubview( waveform )
waveform.frame = NSMakeRect(0, 0, 200, 20)
waveform.plotType = EZPlotType.buffer
waveform.shouldFill = true
waveform.shouldMirror = true
waveform.color = NSColor.black
waveform.updateBuffer( data.buffers[0], withBufferSize: data.bufferSize )

I haven't benchmarked the two methods, but the plot version is very fast for longer files. For stereo files, make two stacked plots using buffers[0] and [1]

Transpierce answered 14/11, 2017 at 0:34 Comment(2)
EZAudio is deprecated and EZAudio class are not in AudioKit.Peavey
This answer is outdated nowTranspierce
K
2

there is a waveform that is drawn in the tables playground example here: http://audiokit.io/playgrounds/Basics/Tables/

Basically:

let file = try AKAudioFile(readFileName: "drumloop.wav")
let fileTable = AKTable(file: file)
...UI set up...
addView(AKTableView(fileTable))
Kempf answered 9/10, 2017 at 1:3 Comment(7)
what is the correct behavior here for a dual channel file? I notice the AKTable implementation only grabs data from the first channel.Sloane
@Sloane You'd have to do some preprocessing of the file data to get two data sets for each channel or sums the channels. The goal would be an array of floats that you could load into a table to view. It would be a nice addition to AudioKit to default to the "sum" view and have specific channel view be options.Kempf
Haven't been able to get AKTableView to work. EZAudioPlot works well though.Sturrock
Hi there, what if I want to use a NSData instead a URL as the source, it's possible? Thanks!Murmuration
@Murmuration if I were you I would write the data to a file and then use the url of that file.Mousetrap
Hi there, I can't find EZAudioPlot in the current version of AudioKitUI, do you know if there is a replacement?Liles
AKTable is not a class.Peavey

© 2022 - 2024 — McMap. All rights reserved.