Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
61541f7e
Commit
61541f7e
authored
Nov 04, 2020
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Core Audio: Add support for default device detection.
parent
25bd2576
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
19 deletions
+52
-19
miniaudio.h
miniaudio.h
+52
-19
No files found.
miniaudio.h
View file @
61541f7e
...
@@ -23588,6 +23588,37 @@ static ma_result ma_set_AudioObject_buffer_size_in_frames(ma_context* pContext,
...
@@ -23588,6 +23588,37 @@ 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)
{
AudioObjectPropertyAddress propAddressDefaultDevice;
UInt32 defaultDeviceObjectIDSize = sizeof(AudioObjectID);
AudioObjectID defaultDeviceObjectID;
OSStatus status;
MA_ASSERT(pContext != NULL);
MA_ASSERT(pDeviceObjectID != NULL);
/* Safety. */
*pDeviceObjectID = 0;
propAddressDefaultDevice.mScope = kAudioObjectPropertyScopeGlobal;
propAddressDefaultDevice.mElement = kAudioObjectPropertyElementMaster;
if (deviceType == ma_device_type_playback) {
propAddressDefaultDevice.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
} else {
propAddressDefaultDevice.mSelector = kAudioHardwarePropertyDefaultInputDevice;
}
defaultDeviceObjectIDSize = sizeof(AudioObjectID);
status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(kAudioObjectSystemObject, &propAddressDefaultDevice, 0, NULL, &defaultDeviceObjectIDSize, &defaultDeviceObjectID);
if (status == noErr) {
*pDeviceObjectID = defaultDeviceObjectID;
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)
static ma_result ma_find_AudioObjectID(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, AudioObjectID* pDeviceObjectID)
{
{
...
@@ -23599,25 +23630,7 @@ static ma_result ma_find_AudioObjectID(ma_context* pContext, ma_device_type devi
...
@@ -23599,25 +23630,7 @@ static ma_result ma_find_AudioObjectID(ma_context* pContext, ma_device_type devi
if (pDeviceID == NULL) {
if (pDeviceID == NULL) {
/* Default device. */
/* Default device. */
AudioObjectPropertyAddress propAddressDefaultDevice;
return ma_find_default_AudioObjectID(pContext, deviceType, pDeviceObjectID);
UInt32 defaultDeviceObjectIDSize = sizeof(AudioObjectID);
AudioObjectID defaultDeviceObjectID;
OSStatus status;
propAddressDefaultDevice.mScope = kAudioObjectPropertyScopeGlobal;
propAddressDefaultDevice.mElement = kAudioObjectPropertyElementMaster;
if (deviceType == ma_device_type_playback) {
propAddressDefaultDevice.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
} else {
propAddressDefaultDevice.mSelector = kAudioHardwarePropertyDefaultInputDevice;
}
defaultDeviceObjectIDSize = sizeof(AudioObjectID);
status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(kAudioObjectSystemObject, &propAddressDefaultDevice, 0, NULL, &defaultDeviceObjectIDSize, &defaultDeviceObjectID);
if (status == noErr) {
*pDeviceObjectID = defaultDeviceObjectID;
return MA_SUCCESS;
}
} else {
} else {
/* Explicit device. */
/* Explicit device. */
UInt32 deviceCount;
UInt32 deviceCount;
...
@@ -23915,8 +23928,13 @@ static ma_result ma_context_enumerate_devices__coreaudio(ma_context* pContext, m
...
@@ -23915,8 +23928,13 @@ 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) {
...
@@ -23936,11 +23954,19 @@ static ma_result ma_context_enumerate_devices__coreaudio(ma_context* pContext, m
...
@@ -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,11 +24012,14 @@ static ma_result ma_context_get_device_info__coreaudio(ma_context* pContext, ma_
...
@@ -23986,11 +24012,14 @@ 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) {
...
@@ -24006,6 +24035,10 @@ static ma_result ma_context_get_device_info__coreaudio(ma_context* pContext, ma_
...
@@ -24006,6 +24035,10 @@ static ma_result ma_context_get_device_info__coreaudio(ma_context* pContext, ma_
if (result != MA_SUCCESS) {
if (result != MA_SUCCESS) {
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);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment