coreaudio: Move from AudioUnits to AudioQueues.

AudioQueues are available in Mac OS X 10.5 and later (and iOS 2.0 and later).
Their API is much more clear (and if you don't mind the threading tapdance
to get its own CFRunLoop) much easier to use in general for our purposes.

As an added benefit: they seemlessly deal with format conversion in ways
AudioUnits don't: for example, my MacBook Pro's built-in microphone won't
capture at 8000Hz and the AudioUnit version wouldn't resample to hide this
fact; the AudioQueue version, however, can handle this.
This commit is contained in:
Ryan C. Gordon
2016-09-04 01:23:55 -04:00
parent 3b53304a94
commit 0265d3af9b
2 changed files with 175 additions and 208 deletions

View File

@@ -32,10 +32,9 @@
#if MACOSX_COREAUDIO
#include <CoreAudio/CoreAudio.h>
#include <CoreServices/CoreServices.h>
#else
#include <AudioToolbox/AudioToolbox.h>
#endif
#include <AudioToolbox/AudioToolbox.h>
#include <AudioUnit/AudioUnit.h>
/* Hidden "this" pointer for the audio functions */
@@ -43,11 +42,16 @@
struct SDL_PrivateAudioData
{
AudioUnit audioUnit;
SDL_bool audioUnitOpened;
SDL_Thread *thread;
AudioQueueRef audioQueue;
AudioQueueBufferRef audioBuffer[2];
void *buffer;
UInt32 bufferOffset;
UInt32 bufferSize;
AudioStreamBasicDescription strdesc;
SDL_sem *ready_semaphore;
char *thread_error;
SDL_atomic_t shutdown;
#if MACOSX_COREAUDIO
AudioDeviceID deviceID;
#endif