Это поздний ответ, но я изо всех сил пытался получить буфер float *
для записи в файл в Swift.
Размещение этого примера на случай, если он кому-нибудь поможет.
enum AudioFileError: ErrorType {
case FailedToCreate(OSStatus)
case FailedToWrite(OSStatus)
case FailedToClose(OSStatus)
}
func writeAudioData(audioData:NSData, toFile destination:NSURL, description:AudioStreamBasicDescription) throws {
//get a pointer to the float buffer
let floatBuffer = UnsafeMutablePointer<Float>(audioData.bytes)
//get an AudioBufferList from the float buffer
let buffer = AudioBuffer(mNumberChannels: 1, mDataByteSize: UInt32(audioData.length), mData: floatBuffer)
var bufferList = AudioBufferList(mNumberBuffers: 1, mBuffers: buffer)
//create the CAF file using the stream description
var file = ExtAudioFileRef()
var result:OSStatus = noErr
var streamDescription = description
withUnsafePointer(&streamDescription) { streamDescription in
withUnsafeMutablePointer(&file) { file in
result = ExtAudioFileCreateWithURL(destination, kAudioFileCAFType, streamDescription, nil, AudioFileFlags.EraseFile.rawValue, file)
}
}
if result != noErr {
throw AudioFileError.FailedToCreate(result)
}
//write the AudioBufferList to the file
withUnsafeMutablePointer(&bufferList) { bufferList in
result = ExtAudioFileWrite(file, UInt32(audioData.length / sizeof(Float)), bufferList)
}
if result != noErr {
throw AudioFileError.FailedToWrite(result)
}
//close the file
result = ExtAudioFileDispose(file)
if result != noErr {
throw AudioFileError.FailedToClose(result)
}
}