Reverse audio files on IOS and Mac using Swift and Accelerate framework.

Borama Apps
Jul 28, 2021

Recently my task at Kinzoo was to add an option to reverse audio files. I’ve found a few examples, but they weren’t fast. I decided to use the reverse function from the Accelerate framework. It works fast!!!

It’s important to note that file format is not the same as processing format, messing it up can lead to weird errors or wrong sample rate.

The main job is done inside a loop processing floatChannelData for each input file channel.

guard let data = buffer.floatChannelData else { return nil }for i in 0..<buffer.format.channelCount {
let stride = vDSP_Stride(1)
vDSP_vrvrs(data.advanced(by: Int(i)).pointee, stride, vDSP_Length(frameLength))
}

That’s it!
Please check my Twitter and my apps!

--

--