0
我正在关注https://github.com/AlesTsurko/LearningCoreAudioWithSwift2.0/tree/master/CH05_Player 以播放频率,但它是用Swift2。 Get microphone input using Audio Queue in Swift 3已解决了许多问题,但它是用于录音的。Swift3 AudioToolbox:PCM播放如何AudioQueueAllocateBuffer?
我被困在一个缓冲区分配给音响队列
var ringBuffers = [AudioQueueBufferRef](repeating:nil, count:3)
AudioQueueAllocateBuffer(inQueue!, bufferSize, &ringBuffers[0])
它给出了一个错误
main.swift:152:29: Expression type '[AudioQueueBufferRef]' is ambiguous without more context
main.swift:153:20: Cannot pass immutable value as inout argument: implicit conversion from 'AudioQueueBufferRef' to 'AudioQueueBufferRef?' requires a temporary
--AFTER SPAD的answer--
var ringBuffers = [AudioQueueBufferRef?](repeating:nil, count:3)
let status = AudioQueueAllocateBuffer(inQueue!, bufferSize, &ringBuffers[0])
print("\(status.description)")
打印
vm_map failed: 0x4 ((os/kern) invalid argument)
4
我用音频描述为
inFormat = AudioStreamBasicDescription(
mSampleRate: Double(sampleRate),
mFormatID: kAudioFormatLinearPCM,
mFormatFlags: kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked,
mBytesPerPacket: UInt32(numChannels * MemoryLayout<UInt16>.size),
mFramesPerPacket: 1,
mBytesPerFrame: UInt32(numChannels * MemoryLayout<UInt16>.size),
mChannelsPerFrame: UInt32(numChannels),
mBitsPerChannel: UInt32(8 * (MemoryLayout<UInt16>.size)),
mReserved: UInt32(0)
)
AudioQueueNewOutput(&inFormat, AQOutputCallback, &player, nil, nil, 0, &inQueue)
似乎多数民众赞成...我会回来完成代码 – neckTwi
但是那给'vm_map失败:为0x4((OS /克恩)无效参数)'运行时错误与'AudioQueueAllocateBuffer' – neckTwi
鉴于更新到你的问题我不能让它与AudioQueueBufferRef编译! 。它必须是一个AudioQueueBufferRef? – Spads