Trying to convert M4A to PCM goes well in the start. i am able to convert and read the bytes. however i am not sure if this is the correct way to do this. as i am getting 16384 bytes when i try to get the bytes in NSData.
Here is my function
func getData(sampleRef:CMSampleBufferRef) -> NSMutableData{
let dataBuffer = CMSampleBufferGetDataBuffer(sampleRef)
let length = CMBlockBufferGetDataLength(dataBuffer!)
var data = NSMutableData(length: length)
CMBlockBufferCopyDataBytes(dataBuffer!, 0, length, data!.mutableBytes)
print(data!)// this prints 16384 bytes
return data!
}
this i try to convert this data to Int16
// 3 lines below i was just testing how it converts to Int16
let count = data!.length / sizeof(Int16)
var array = [Int16](count: count, repeatedValue: 0)
data!.getBytes(&array, length: data!.length)
these are my settings to decode the PCM from M4A file.
let outputSettings = [
AVFormatIDKey: Int(kAudioFormatLinearPCM),
AVSampleRateKey: 44100,
AVLinearPCMBitDepthKey:16,
AVLinearPCMIsFloatKey:0,
AVNumberOfChannelsKey: 1 as NSNumber,
]
PS. i record the file with the same settings