1
ringBuffers = [AudioQueueBufferRef](repeating: AudioQueueBufferRef(), count:inflightBuffersCount)

says init() is unavailable: use 'nil' literal

but if it is

ringBuffers = [AudioQueueBufferRef](repeating: nil, count: inflightBuffersCount)

it says

main.swift:152:29: Expression type '[AudioQueueBufferRef]' is ambiguous without more context

if it is

var ringBuffers = [AudioQueueBufferRef!](repeating:nil, count:3)
let status = AudioQueueAllocateBuffer(inQueue!, bufferSize, &ringBuffers[0])
print("\(status.description)")

prints

vm_map failed: 0x4 ((os/kern) invalid argument)
4

I think assigning nil is not right

Stream description I have used is

let 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
  • 2,483
  • 7
  • 39
  • 62

1 Answers1

0

You got this wrong ;) You don't need to allocate anything at all; the buffer will be created by the AudioQueueAllocateBuffer function you are calling.

For instance:

var buffer: AudioQueueBufferRef? = nil
let status = AudioQueueAllocateBuffer(inQueue!, bufferSize, &buffer)
Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
  • swift says `nil cannot be assigned to AudioQueueBufferRef` it suggests me to replace with `AudioQueueBufferRef?`. but still `status = AudioQueueAllocateBuffer(outputQueue, UInt32(totalSize), &buffer)` is `4` with runtime error `vm_map failed: 0x4 ((os/kern) invalid argument)` – Necktwi May 21 '17 at 04:21
  • @neckTwi Please check your remaining arguments as well. – Paulo Mattos May 21 '17 at 04:27