AVCaptureAudioDataOutputを使用してオーディオ入力を分析しようとしています(here)。これは私が自力で把握できるものではないので、例をコピーしていますが、難しいです。Swift 3:AVCaptureAudioDataOutputを使用してオーディオ入力を分析する
Swift 3のXcodeは私にいくつかの変更を促しました。 samples
を割り当てる行でコンパイルエラーが発生します。 Xcodeは「「タイプの引数リストでUnsafeMutablePointer < _> 『タイプのための初期化子を呼び出すことはできません』(UnsafeMutableRawPointer?)」、言う
をここに私はそれを変更したようなコードがあります:
func captureOutput(_ captureOutput: AVCaptureOutput!,
didOutputSampleBuffer sampleBuffer: CMSampleBuffer!,
from connection: AVCaptureConnection!){
var buffer: CMBlockBuffer? = nil
var audioBufferList = AudioBufferList(mNumberBuffers: 1,
mBuffers: AudioBuffer(mNumberChannels: 1, mDataByteSize: 0, mData: nil))
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(
sampleBuffer,
nil,
&audioBufferList,
MemoryLayout<AudioBufferList>.size, // changed for Swift 3
nil,
nil,
UInt32(kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment),
&buffer
)
let abl = UnsafeMutableAudioBufferListPointer(&audioBufferList)
var sum:Int64 = 0
var count:Int = 0
var bufs:Int = 0
for buf in abl {
let samples = UnsafeMutableBufferPointer<Int16>(start: UnsafeMutablePointer(buf.mData), // Error here
count: Int(buf.mDataByteSize)/sizeof(Int16))
for sample in samples {
let s = Int64(sample)
sum = (sum + s*s)
count += 1
}
bufs += 1
}
print("found \(count) samples in \(bufs) buffers, sum is \(sum)")
}
ことができます誰もこのコードを修正する方法を教えてください。