如何调用CMSampleBufferGetAudioBufferListWithRetainedBlockBuf
发布时间:2020-12-14 04:45:17 所属栏目:百科 来源:网络整理
导读:我试图弄清楚如何在 Swift中调用这个AVFoundation函数.我花了很多时间摆弄声明和语法,并且做到了这一点.编译器大部分都很开心,但我最后还是陷入了困境. public func captureOutput( captureOutput: AVCaptureOutput!,didOutputSampleBuffer sampleBuffer: CM
我试图弄清楚如何在
Swift中调用这个AVFoundation函数.我花了很多时间摆弄声明和语法,并且做到了这一点.编译器大部分都很开心,但我最后还是陷入了困境.
public func captureOutput( captureOutput: AVCaptureOutput!,didOutputSampleBuffer sampleBuffer: CMSampleBuffer!,fromConnection connection: AVCaptureConnection! ) { let samplesInBuffer = CMSampleBufferGetNumSamples(sampleBuffer) var audioBufferList: AudioBufferList var buffer: Unmanaged<CMBlockBuffer>? = nil CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer( sampleBuffer,nil,&audioBufferList,UInt(sizeof(audioBufferList.dynamicType)),UInt32(kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment),&buffer ) // do stuff } 编译器抱怨第3和第4个参数:
和
那我该怎么办呢? 我正在使用this StackOverflow answer,但它是Objective-C.我正试图将其翻译成Swift,但遇到了这个问题. 或者是否有更好的方法?我需要从缓冲区读取数据,一次一个样本,所以我基本上试图得到一些我可以迭代的样本数组. 解决方法
免责声明:我刚刚尝试将代码从
Reading audio samples via AVAssetReader转换为Swift,并验证它是否已编译.我还没有
测试它是否真的有效. // Needs to be initialized somehow,even if we take only the address var audioBufferList = AudioBufferList(mNumberBuffers: 1,mBuffers: AudioBuffer(mNumberChannels: 0,mDataByteSize: 0,mData: nil)) var buffer: Unmanaged<CMBlockBuffer>? = nil CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer( sampleBuffer,&buffer ) // Ensure that the buffer is released automatically. let buf = buffer!.takeRetainedValue() // Create UnsafeBufferPointer from the variable length array starting at audioBufferList.mBuffers let audioBuffers = UnsafeBufferPointer<AudioBuffer>(start: &audioBufferList.mBuffers,count: Int(audioBufferList.mNumberBuffers)) for audioBuffer in audioBuffers { // Create UnsafeBufferPointer<Int16> from the buffer data pointer var samples = UnsafeMutableBufferPointer<Int16>(start: UnsafeMutablePointer(audioBuffer.mData),count: Int(audioBuffer.mDataByteSize)/sizeof(Int16)) for sample in samples { // .... } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- PostgreSQL新手入门
- Swift (10) Optional Chaining && Deinitializa
- json2.js在页面中操作json字符串
- ruby-on-rails – Heroku网站崩溃了Rails 3.2.9和路由约束
- .net – SqlBulkCopy与TVP与XML参数与单个插入过程为20-200
- 正则表达式之grep ,egrep
- ruby – 如何检查redis端口和实例sidekiq连接的是什么?
- xml – 如何从Java ME应用程序中使用ASP.NET Web API
- 解析一个XML文件: XML解析器
- ContentProvider-SqliteDatabase实现增删查改(1)