I'm creating this simple audio recorder and editor interface for an iOS app:
The audio is recorded into a float array that is used to create the waveform. After recording I copy the float data into an AVAudioPCMBuffer
for playing with AVAudioPlayerNode
. I'm able to play the buffer from the start, but I can not figure out how I can play just a segment of the buffer. The scheduleSegment
function only works for files.
You can create a new buffer that's a segment of the original. AVAudioPCMBuffer and AudioBufferlist are kind of a pain in Swift. There are a few ways to do this, if you are using floats you can access AVAUdioPCMBuffer.floatChannelData, but here's a method that works for both float and int samples.