mariia
6/25/2019 - 11:11 AM

Data from audio buffer

static func create(from buffer: AVAudioPCMBuffer) -> Data {
        let channelCount = 1  // given PCMBuffer channel count is 1.
        let channels = UnsafeBufferPointer(start: buffer.floatChannelData, count: channelCount)
        let ch0Data = NSData(bytes: channels[0],
                             length:Int(buffer.frameCapacity * buffer.format.streamDescription.pointee.mBytesPerFrame)) as Data
        
        return ch0Data
    }