- aout_instance_t *p_aout = (aout_instance_t *)p_this;
- struct aout_sys_t *p_sys = malloc(sizeof(aout_sys_t));
- p_aout->output.p_sys = p_sys;
-
- OSStatus status = 0;
-
- // Setup the audio device.
- AudioStreamBasicDescription deviceFormat;
- deviceFormat.mSampleRate = 44100;
- deviceFormat.mFormatID = kAudioFormatLinearPCM;
- deviceFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger; // Signed integer, little endian
- deviceFormat.mBytesPerPacket = 4;
- deviceFormat.mFramesPerPacket = 1;
- deviceFormat.mBytesPerFrame = 4;
- deviceFormat.mChannelsPerFrame = 2;
- deviceFormat.mBitsPerChannel = 16;
- deviceFormat.mReserved = 0;
-
- // Create a new output AudioQueue for the device.
- status = AudioQueueNewOutput(&deviceFormat, // Format
- AudioQueueCallback, // Callback
- p_aout, // User data, passed to the callback
- CFRunLoopGetMain(), // RunLoop
- kCFRunLoopDefaultMode, // RunLoop mode
- 0, // Flags ; must be zero (per documentation)...
- &(p_sys->audioQueue)); // Output
-
- // This will be used for boosting the audio without the need of a mixer (floating-point conversion is expensive on ARM)
- // AudioQueueSetParameter(p_sys->audioQueue, kAudioQueueParam_Volume, 12.0); // Defaults to 1.0
-
- msg_Dbg(p_aout, "New AudioQueue output created (status = %i)", status);
-
- // Allocate buffers for the AudioQueue, and pre-fill them.
- for (int i = 0; i < NUMBER_OF_BUFFERS; ++i) {
- AudioQueueBufferRef buffer = NULL;
- status = AudioQueueAllocateBuffer(p_sys->audioQueue, FRAME_SIZE * 4, &buffer);
- AudioQueueCallback(NULL, p_sys->audioQueue, buffer);
- }