init isRecording false data Data audioEngine inputNode installTap onBu

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
init() {
isRecording = false
data = Data()
audioEngine.inputNode.installTap(onBus: 0, bufferSize: 4096, format: format) { (buffer, time) in
// Retrieve audio buffer and append it to saved data
let channels = UnsafeBufferPointer(start: buffer.int16ChannelData, count: 1)
let bufferData = NSData(bytes: channels.first, length: Int(buffer.frameCapacity * buffer.format.streamDescription.pointee.mBytesPerFrame)) as Data
if let callback = self.passBufferCallback {
callback(bufferData)
}
self.data.append(bufferData)
}
}
private func startRecording() {
data.removeAll()
do {
try audioEngine.start()
DispatchQueue.main.async {
self.delegate?.recordingStarted()
}
}
catch {
print("Some troubles with starting engine..")
}
}