mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 09:14:04 +02:00
Core Audio: Add support for default device detection.
This commit is contained in:
+42
-9
@@ -23588,22 +23588,19 @@ static ma_result ma_set_AudioObject_buffer_size_in_frames(ma_context* pContext,
|
|||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ma_result ma_find_default_AudioObjectID(ma_context* pContext, ma_device_type deviceType, AudioObjectID* pDeviceObjectID)
|
||||||
static ma_result ma_find_AudioObjectID(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, AudioObjectID* pDeviceObjectID)
|
|
||||||
{
|
{
|
||||||
|
AudioObjectPropertyAddress propAddressDefaultDevice;
|
||||||
|
UInt32 defaultDeviceObjectIDSize = sizeof(AudioObjectID);
|
||||||
|
AudioObjectID defaultDeviceObjectID;
|
||||||
|
OSStatus status;
|
||||||
|
|
||||||
MA_ASSERT(pContext != NULL);
|
MA_ASSERT(pContext != NULL);
|
||||||
MA_ASSERT(pDeviceObjectID != NULL);
|
MA_ASSERT(pDeviceObjectID != NULL);
|
||||||
|
|
||||||
/* Safety. */
|
/* Safety. */
|
||||||
*pDeviceObjectID = 0;
|
*pDeviceObjectID = 0;
|
||||||
|
|
||||||
if (pDeviceID == NULL) {
|
|
||||||
/* Default device. */
|
|
||||||
AudioObjectPropertyAddress propAddressDefaultDevice;
|
|
||||||
UInt32 defaultDeviceObjectIDSize = sizeof(AudioObjectID);
|
|
||||||
AudioObjectID defaultDeviceObjectID;
|
|
||||||
OSStatus status;
|
|
||||||
|
|
||||||
propAddressDefaultDevice.mScope = kAudioObjectPropertyScopeGlobal;
|
propAddressDefaultDevice.mScope = kAudioObjectPropertyScopeGlobal;
|
||||||
propAddressDefaultDevice.mElement = kAudioObjectPropertyElementMaster;
|
propAddressDefaultDevice.mElement = kAudioObjectPropertyElementMaster;
|
||||||
if (deviceType == ma_device_type_playback) {
|
if (deviceType == ma_device_type_playback) {
|
||||||
@@ -23618,6 +23615,22 @@ static ma_result ma_find_AudioObjectID(ma_context* pContext, ma_device_type devi
|
|||||||
*pDeviceObjectID = defaultDeviceObjectID;
|
*pDeviceObjectID = defaultDeviceObjectID;
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we get here it means we couldn't find the device. */
|
||||||
|
return MA_NO_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ma_result ma_find_AudioObjectID(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, AudioObjectID* pDeviceObjectID)
|
||||||
|
{
|
||||||
|
MA_ASSERT(pContext != NULL);
|
||||||
|
MA_ASSERT(pDeviceObjectID != NULL);
|
||||||
|
|
||||||
|
/* Safety. */
|
||||||
|
*pDeviceObjectID = 0;
|
||||||
|
|
||||||
|
if (pDeviceID == NULL) {
|
||||||
|
/* Default device. */
|
||||||
|
return ma_find_default_AudioObjectID(pContext, deviceType, pDeviceObjectID);
|
||||||
} else {
|
} else {
|
||||||
/* Explicit device. */
|
/* Explicit device. */
|
||||||
UInt32 deviceCount;
|
UInt32 deviceCount;
|
||||||
@@ -23915,9 +23928,14 @@ static ma_result ma_context_enumerate_devices__coreaudio(ma_context* pContext, m
|
|||||||
#if defined(MA_APPLE_DESKTOP)
|
#if defined(MA_APPLE_DESKTOP)
|
||||||
UInt32 deviceCount;
|
UInt32 deviceCount;
|
||||||
AudioObjectID* pDeviceObjectIDs;
|
AudioObjectID* pDeviceObjectIDs;
|
||||||
|
AudioObjectID defaultDeviceObjectIDPlayback;
|
||||||
|
AudioObjectID defaultDeviceObjectIDCapture;
|
||||||
ma_result result;
|
ma_result result;
|
||||||
UInt32 iDevice;
|
UInt32 iDevice;
|
||||||
|
|
||||||
|
ma_find_default_AudioObjectID(pContext, ma_device_type_playback, &defaultDeviceObjectIDPlayback); /* OK if this fails. */
|
||||||
|
ma_find_default_AudioObjectID(pContext, ma_device_type_capture, &defaultDeviceObjectIDCapture); /* OK if this fails. */
|
||||||
|
|
||||||
result = ma_get_device_object_ids__coreaudio(pContext, &deviceCount, &pDeviceObjectIDs);
|
result = ma_get_device_object_ids__coreaudio(pContext, &deviceCount, &pDeviceObjectIDs);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
@@ -23936,11 +23954,19 @@ static ma_result ma_context_enumerate_devices__coreaudio(ma_context* pContext, m
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ma_does_AudioObject_support_playback(pContext, deviceObjectID)) {
|
if (ma_does_AudioObject_support_playback(pContext, deviceObjectID)) {
|
||||||
|
if (deviceObjectID == defaultDeviceObjectIDPlayback) {
|
||||||
|
info._private.isDefault = MA_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!callback(pContext, ma_device_type_playback, &info, pUserData)) {
|
if (!callback(pContext, ma_device_type_playback, &info, pUserData)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ma_does_AudioObject_support_capture(pContext, deviceObjectID)) {
|
if (ma_does_AudioObject_support_capture(pContext, deviceObjectID)) {
|
||||||
|
if (deviceObjectID == defaultDeviceObjectIDCapture) {
|
||||||
|
info._private.isDefault = MA_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!callback(pContext, ma_device_type_capture, &info, pUserData)) {
|
if (!callback(pContext, ma_device_type_capture, &info, pUserData)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -23986,12 +24012,15 @@ static ma_result ma_context_get_device_info__coreaudio(ma_context* pContext, ma_
|
|||||||
/* Desktop */
|
/* Desktop */
|
||||||
{
|
{
|
||||||
AudioObjectID deviceObjectID;
|
AudioObjectID deviceObjectID;
|
||||||
|
AudioObjectID defaultDeviceObjectID;
|
||||||
UInt32 streamDescriptionCount;
|
UInt32 streamDescriptionCount;
|
||||||
AudioStreamRangedDescription* pStreamDescriptions;
|
AudioStreamRangedDescription* pStreamDescriptions;
|
||||||
UInt32 iStreamDescription;
|
UInt32 iStreamDescription;
|
||||||
UInt32 sampleRateRangeCount;
|
UInt32 sampleRateRangeCount;
|
||||||
AudioValueRange* pSampleRateRanges;
|
AudioValueRange* pSampleRateRanges;
|
||||||
|
|
||||||
|
ma_find_default_AudioObjectID(pContext, deviceType, &defaultDeviceObjectID); /* OK if this fails. */
|
||||||
|
|
||||||
result = ma_find_AudioObjectID(pContext, deviceType, pDeviceID, &deviceObjectID);
|
result = ma_find_AudioObjectID(pContext, deviceType, pDeviceID, &deviceObjectID);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
@@ -24007,6 +24036,10 @@ static ma_result ma_context_get_device_info__coreaudio(ma_context* pContext, ma_
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (deviceObjectID == defaultDeviceObjectID) {
|
||||||
|
pDeviceInfo->_private.isDefault = MA_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Formats. */
|
/* Formats. */
|
||||||
result = ma_get_AudioObject_stream_descriptions(pContext, deviceObjectID, deviceType, &streamDescriptionCount, &pStreamDescriptions);
|
result = ma_get_AudioObject_stream_descriptions(pContext, deviceObjectID, deviceType, &streamDescriptionCount, &pStreamDescriptions);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user