我有一个iOS锻炼应用,需要在后台保持运行(和播放音频)。可悲的是,我知道,实现此目标的唯一方法是通过Core Audio播放听不见的声音。
一个用户遇到了重复发生的崩溃,我无法在模拟器中重现。 (他们有iPhone 5,iOS10。)Xcode中的崩溃报告指向了我从未见过的崩溃行。 timestamp
在渲染回调中可以为空吗?
private func render(ctx: UnsafeMutableRawPointer,
ioActionFlags: UnsafeMutablePointer<AudioUnitRenderActionFlags>,
timeStamp: UnsafePointer<AudioTimeStamp>,
bus: UInt32,
nFrames: UInt32,
ioData: UnsafeMutablePointer<AudioBufferList>?) -> OSStatus
{
guard let ioData = ioData else { return noErr }
let abl = UnsafeMutableAudioBufferListPointer(ioData)
guard let bufferData = abl[0].mData else { return noErr }
let impl = Unmanaged<MyClass>.fromOpaque(ctx).takeUnretainedValue()
let buf: UnsafeMutablePointer<Float32> = bufferData.assumingMemoryBound(to: Float32.self)
// **** Crash appears to pointing to this next line.
var t: Int = Int(timeStamp.pointee.mSampleTime) % impl.samples.count
for i in 0..<Int(nFrames) {
buf[i] = impl.samples[t]
t += 1
if t >= impl.samples.count { t = 0 }
}
...